Skip to main content
added 1064 characters in body
Source Link

EDIT: I managed to get everything working fine with this code:

public void showUpdatedStatus()
{
    
    if(((itsUsersNumber - itsSecretNumber) <= 2) && ((itsUsersNumber -itsSecretNumber) >= -2))
        JOptionPane.showMessageDialog(null, "You're hot!");
    else if (((itsUsersNumber - itsSecretNumber) <= 6) && ((itsUsersNumber -itsSecretNumber) >= -6))
        JOptionPane.showMessageDialog(null, "You're warm.");
    if ((itsUsersNumber - itsSecretNumber) < -6)
        JOptionPane.showMessageDialog(null, "Too low.");
    else 
        TooHigh();
}

public void TooHigh()
{
    if ((itsUsersNumber - itsSecretNumber) > 6)
    {
        itsLieNum = randy.nextInt(3);
        if(canLie && itsLieNum == 1){
            canLie = false;
            JOptionPane.showMessageDialog(null, "Too low.");}
        else{
            canLie = true;
            JOptionPane.showMessageDialog(null, "Too high.");}
    }
}

Thanks to rolfl

EDIT: I managed to get everything working fine with this code:

public void showUpdatedStatus()
{
    
    if(((itsUsersNumber - itsSecretNumber) <= 2) && ((itsUsersNumber -itsSecretNumber) >= -2))
        JOptionPane.showMessageDialog(null, "You're hot!");
    else if (((itsUsersNumber - itsSecretNumber) <= 6) && ((itsUsersNumber -itsSecretNumber) >= -6))
        JOptionPane.showMessageDialog(null, "You're warm.");
    if ((itsUsersNumber - itsSecretNumber) < -6)
        JOptionPane.showMessageDialog(null, "Too low.");
    else 
        TooHigh();
}

public void TooHigh()
{
    if ((itsUsersNumber - itsSecretNumber) > 6)
    {
        itsLieNum = randy.nextInt(3);
        if(canLie && itsLieNum == 1){
            canLie = false;
            JOptionPane.showMessageDialog(null, "Too low.");}
        else{
            canLie = true;
            JOptionPane.showMessageDialog(null, "Too high.");}
    }
}

Thanks to rolfl

deleted 10 characters in body; edited tags; edited title
Source Link
Jamal
  • 34.9k
  • 13
  • 133
  • 237

how How to make a program that lies one-third of the time?

I am supposed to take this code (that I made):

public void showUpdatedStatus()
{
    if(((itsUsersNumber - itsSecretNumber) <= 2) && ((itsUsersNumber - itsSecretNumber) >= -2))
        JOptionPane.showMessageDialog(null, "You're hot!");
    if (((itsUsersNumber - itsSecretNumber) <= 6) && ((itsUsersNumber - itsSecretNumber) >= -6))
        JOptionPane.showMessageDialog(null, "You're warm.");
    if ((itsUsersNumber - itsSecretNumber) < -6)
        JOptionPane.showMessageDialog(null, "Too low.");
    if ((itsUsersNumber - itsSecretNumber) > 6)
        JOptionPane.showMessageDialog(null, "Too high.");
}

And change it so it does this:

Have the program lie one-third of the time that the guess is too high; it says it is too low. But it never lies about the guess being too low, nor does it lie twice in a row.

I believe I have managed to do this with this method for checking whether the guess is "Too"too high."

public void TooHigh()
{
    int numLies = 1;
    if ((itsUsersNumber - itsSecretNumber) > 6)
    {
        itsLieNum = randy.nextInt(2);
        if(itsLieNum == 1 && numLies == 1){
            numLies = 2;
            JOptionPane.showMessageDialog(null, "Too low.");}
        else
            numLies = 1;
            JOptionPane.showMessageDialog(null, "Too high.");
    }
}

I just want to know whether or not it seems like it would work fine. I would just test it, but it would probably take me quite a while to make sure that it not only works 1/3 of the time, but also that it doesn't do it twice in a row. Thanks :)

how to make a program that lies one-third of the time?

I am supposed to take this code (that I made):

public void showUpdatedStatus()
{
    if(((itsUsersNumber - itsSecretNumber) <= 2) && ((itsUsersNumber - itsSecretNumber) >= -2))
        JOptionPane.showMessageDialog(null, "You're hot!");
    if (((itsUsersNumber - itsSecretNumber) <= 6) && ((itsUsersNumber - itsSecretNumber) >= -6))
        JOptionPane.showMessageDialog(null, "You're warm.");
    if ((itsUsersNumber - itsSecretNumber) < -6)
        JOptionPane.showMessageDialog(null, "Too low.");
    if ((itsUsersNumber - itsSecretNumber) > 6)
        JOptionPane.showMessageDialog(null, "Too high.");
}

And change it so it does this:

Have the program lie one-third of the time that the guess is too high; it says it is too low. But it never lies about the guess being too low, nor does it lie twice in a row.

I believe I have managed to do this with this method for checking whether the guess is "Too high."

public void TooHigh()
{
    int numLies = 1;
    if ((itsUsersNumber - itsSecretNumber) > 6)
    {
        itsLieNum = randy.nextInt(2);
        if(itsLieNum == 1 && numLies == 1){
            numLies = 2;
            JOptionPane.showMessageDialog(null, "Too low.");}
        else
            numLies = 1;
            JOptionPane.showMessageDialog(null, "Too high.");
    }
}

I just want to know whether or not it seems like it would work fine. I would just test it, but it would probably take me quite a while to make sure that it not only works 1/3 of the time, but also that it doesn't do it twice in a row. Thanks :)

How to make a program that lies one-third of the time?

I am supposed to take this code (that I made):

public void showUpdatedStatus()
{
    if(((itsUsersNumber - itsSecretNumber) <= 2) && ((itsUsersNumber - itsSecretNumber) >= -2))
        JOptionPane.showMessageDialog(null, "You're hot!");
    if (((itsUsersNumber - itsSecretNumber) <= 6) && ((itsUsersNumber - itsSecretNumber) >= -6))
        JOptionPane.showMessageDialog(null, "You're warm.");
    if ((itsUsersNumber - itsSecretNumber) < -6)
        JOptionPane.showMessageDialog(null, "Too low.");
    if ((itsUsersNumber - itsSecretNumber) > 6)
        JOptionPane.showMessageDialog(null, "Too high.");
}

And change it so it does this:

Have the program lie one-third of the time that the guess is too high; it says it is too low. But it never lies about the guess being too low, nor does it lie twice in a row.

I believe I have managed to do this with this method for checking whether the guess is "too high."

public void TooHigh()
{
    int numLies = 1;
    if ((itsUsersNumber - itsSecretNumber) > 6)
    {
        itsLieNum = randy.nextInt(2);
        if(itsLieNum == 1 && numLies == 1){
            numLies = 2;
            JOptionPane.showMessageDialog(null, "Too low.");}
        else
            numLies = 1;
            JOptionPane.showMessageDialog(null, "Too high.");
    }
}

I just want to know whether or not it seems like it would work fine. I would just test it, but it would probably take me quite a while to make sure that it not only works 1/3 of the time, but also that it doesn't do it twice in a row.

edited tags
Link
rolfl
  • 97.5k
  • 17
  • 218
  • 418
Source Link
Loading