Page 1 of 2 12 LastLast
Results 1 to 20 of 23
Like Tree4Likes

Thread: This ap course is so hard :(((

  1. #1
    Army is offline Senior Member
    Join Date
    Jan 2012
    Posts
    147
    Rep Power
    0

    Default This ap course is so hard :(((

    Exercise 4.28* Revise the GuessNumber game to 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.

    How do I even think of doing that? Wtf?

    Java Code:
    import javax.swing.JOptionPane;
    public class GuessNumber extends BasicGame {
        private java.util.Random randy;
        private int itsSecretNumber;
        private int itsUsersNumber;
        public GuessNumber(){
            super();
            randy = new java.util.Random();
        } //=======================
        public void askUsersFirstChoice(){ 
            itsSecretNumber = 1 + randy.nextInt (10);
            askUsersNextChoice();
        } //=======================
        public void askUsersNextChoice(){
            String s = JOptionPane.showInputDialog
            ("Guess my number from 1 to 100:");
                if (s != null && ! s.equals ("")) {
                itsUsersNumber = Integer.parseInt (s);
                }else{
                itsUsersNumber = -1; // just to have a value there
            }
           
            } //======================
            public boolean shouldContinue(){ 
                return itsUsersNumber != itsSecretNumber;
            } //======================
            //Exercise 4.28
            public void showUpdatedStatus(){ 
                int result = itsUsersNumber - itsSecretNumber;
                if(Math.abs(result) == 2){
                    JOptionPane.showMessageDialog (null, "You're hot");
                }
                if(Math.abs(result) == 1){
                    JOptionPane.showMessageDialog (null, "You're hot");
                }
                if(Math.abs(result) == 3){
                    JOptionPane.showMessageDialog (null, "You're warm");
                }
                if(Math.abs(result) == 4){
                    JOptionPane.showMessageDialog (null, "You're warm");
                }
                if(Math.abs(result) == 5){
                    JOptionPane.showMessageDialog (null, "You're warm");
                }
                if (itsUsersNumber > itsSecretNumber)
                JOptionPane.showMessageDialog (null, "Too high");
                else
                JOptionPane.showMessageDialog (null, "Too low");
            } //=======================
            // inherited from BasicGame:
            // playManyGames
            // playOneGame
            // showFinalStatus
    }

  2. #2
    Sierra is offline AN21XX
    Join Date
    Mar 2012
    Location
    Munich
    Posts
    297
    Rep Power
    3

    Default Re: This ap course is so hard :(((

    Implement one thing at a time, step by step. One third is a probability, so you need to generate a random number and use a conditional to determine if it lies or not...
    I suggest you implement methods for "too high" and "too low", so you do not have to duplicate code.
    foulkelore likes this.
    I like likes!

  3. #3
    Russd772 is offline Member
    Join Date
    Dec 2012
    Posts
    42
    Rep Power
    0

    Default Re: This ap course is so hard :(((

    you could try and use a random number 0-2 (total 3) and
    Java Code:
    if(randNum == 1 && guessedNumber < secretNumber){
    System.out.println("Number is too High");
    }
    if(randNum == 1 && guessedNumber > secretNumber){
    System.out.println("Number is too Low");
    }
    or something along those lines
    this would give a lie 33% of the time but would lie depending on the users guess, if you just want to say high no matter what then technically its not a lie 33% of the time if the user guesses too low, but you can just omit the greater than and less than expressions.
    Last edited by Russd772; 01-08-2013 at 08:44 PM.

  4. #4
    Army is offline Senior Member
    Join Date
    Jan 2012
    Posts
    147
    Rep Power
    0

    Default Re: This ap course is so hard :(((

    Java Code:
    import javax.swing.JOptionPane;
    public class GuessNumber extends BasicGame {
        private java.util.Random randy;
        private int itsSecretNumber;
        private int itsUsersNumber;
        private int itsMark;
        public GuessNumber(){
            super();
            randy = new java.util.Random();
        } //=======================
        public void askUsersFirstChoice(){ 
            itsSecretNumber = 1 + randy.nextInt (10);
            askUsersNextChoice();
           
        } //=======================
        public void askUsersNextChoice(){
            String s = JOptionPane.showInputDialog
            ("Guess my number from 1 to 100:");
                if (s != null && ! s.equals ("")) {
                itsUsersNumber = Integer.parseInt (s);
                }else{
                itsUsersNumber = -1; // just to have a value there
            }
           itsMark++;
            } //======================
            public boolean shouldContinue(){ 
                return itsUsersNumber != itsSecretNumber;
                
            } //======================
            //Exercise 4.28
            public void showUpdatedStatus(){ 
                while(itsMark == itsMark + 2){
                    if (itsUsersNumber > itsSecretNumber){
                        JOptionPane.showMessageDialog (null, "Too high");
                    }
                }
                int result = itsUsersNumber - itsSecretNumber;
                if(Math.abs(result) == 2){
                    JOptionPane.showMessageDialog (null, "You're hot");
                }
                if(Math.abs(result) == 1){
                    JOptionPane.showMessageDialog (null, "You're hot");
                }
                if(Math.abs(result) == 3){
                    JOptionPane.showMessageDialog (null, "You're warm");
                }
                if(Math.abs(result) == 4){
                    JOptionPane.showMessageDialog (null, "You're warm");
                }
                if(Math.abs(result) == 5){
                    JOptionPane.showMessageDialog (null, "You're warm");
                }
                if (itsUsersNumber > itsSecretNumber)
                JOptionPane.showMessageDialog (null, "Too high");
                else
                JOptionPane.showMessageDialog (null, "Too low");
            } //=======================
            // inherited from BasicGame:
            // playManyGames
            // playOneGame
            // showFinalStatus
    }
    I did this but my tiny mind doesn't perceive some of the stuff I did.

  5. #5
    foulkelore is offline Member
    Join Date
    Dec 2012
    Location
    Des Moines, IA
    Posts
    35
    Rep Power
    0

    Default Re: This ap course is so hard :(((

    I agree with Sierra. Don't think of this as one large problem, but a series of small problems. Get one thing to work and then move on to another.

  6. #6
    Russd772 is offline Member
    Join Date
    Dec 2012
    Posts
    42
    Rep Power
    0

    Default Re: This ap course is so hard :(((

    Quote Originally Posted by foulkelore View Post
    I agree with Sierra. Don't think of this as one large problem, but a series of small problems. Get one thing to work and then move on to another.
    Yeah def want to break it down and look at chunks of code, then once you learn what they all do the program as a whole will fal into perspective.

  7. #7
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,184
    Rep Power
    19

    Default Re: This ap course is so hard :(((

    Please go through the Forum Rules, particularly the third paragraph.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  8. #8
    Army is offline Senior Member
    Join Date
    Jan 2012
    Posts
    147
    Rep Power
    0

    Default Re: This ap course is so hard :(((

    Sorry if I'm getting annoying but, what does this mean? Exercise 4.33* Write out the full Time constructor with the heading public Time(int totalMinutes). Be sure to allow for negative inputs.

    The one thing that is confusing me is the totalMinutes part. Are they telling me to forgot the hours of the time and not use it...?

    Here's the Time class
    Java Code:
    public class Time extends Object
    {
         private int itsHour;    // always in the range 0 to 23
         private int itsMin;     // always in the range 0 to 59
    
    
         /** Create an object for the given hour and minute.  If min
          *  is negative, adjust the values to make 0 <= min < 60. */
    
         public Time (int hour, int min)            // constructor
         {    super();
              itsHour = hour;
              for (itsMin = min;  itsMin < 0;  itsMin = itsMin + 60)
                   itsHour--;
         }    //=======================
    
    
         /** Return the time expressed in military time. */
    
         public String toString()
         {    if (itsHour < 10)
                   return ("0" + itsHour) + itsMin;
              else
                   return ("" + itsHour) + itsMin;
         }    //=======================
    
    
         /** Return the result of adding this Time to that Time. */
    
         public Time add (Time that)
         {    Time valueToReturn = new Time (this.itsHour + that.itsHour, 
                                             this.itsMin + that.itsMin);
              if (valueToReturn.itsMin >= 60)
              {    valueToReturn.itsMin = valueToReturn.itsMin - 60;
                   valueToReturn.itsHour++;
              }
              valueToReturn.itsHour = valueToReturn.itsHour % 24;
              return valueToReturn;
         }    //=======================
    }

  9. #9
    Sierra is offline AN21XX
    Join Date
    Mar 2012
    Location
    Munich
    Posts
    297
    Rep Power
    3

    Default Re: This ap course is so hard :(((

    I think you would need to calculate those minutes into hours and minutes:
    if totalMinutes is 72 it would be one hour and 12 minutes, right? ;)
    Army likes this.
    I like likes!

  10. #10
    Army is offline Senior Member
    Join Date
    Jan 2012
    Posts
    147
    Rep Power
    0

    Default Re: This ap course is so hard :(((

    You're so helpfullllll :0

  11. #11
    foulkelore is offline Member
    Join Date
    Dec 2012
    Location
    Des Moines, IA
    Posts
    35
    Rep Power
    0

    Default Re: This ap course is so hard :(((

    I'm not sure programming is a good career choice for you. have you tried going through the tutorals? They are really helpful.

  12. #12
    PhQ's Avatar
    PhQ
    PhQ is offline Senior Member
    Join Date
    Mar 2010
    Location
    Lithuania
    Posts
    358
    Rep Power
    5

    Default Re: This ap course is so hard :(((

    Quote Originally Posted by foulkelore View Post
    I'm not sure programming is a good career choice for you.
    I'm sure it's impossible for one to learn programming in a couple lectures.
    I ask hundreds of questions on this forum and this doesn't mean that programming is not a good career choice for me. Programming might be hard for someone who is new to it.
    Last edited by PhQ; 01-09-2013 at 12:13 AM.

  13. #13
    Sierra is offline AN21XX
    Join Date
    Mar 2012
    Location
    Munich
    Posts
    297
    Rep Power
    3

    Default Re: This ap course is so hard :(((

    True, I never saw someone who came from any course as a professional... it needs time and effort. For some more, for others less...
    I like likes!

  14. #14
    Army is offline Senior Member
    Join Date
    Jan 2012
    Posts
    147
    Rep Power
    0

    Default Re: This ap course is so hard :(((

    Quote Originally Posted by foulkelore View Post
    I'm not sure programming is a good career choice for you. have you tried going through the tutorals? They are really helpful.
    Hmm, that was kinda mean. Sorry if I don't meet your programming standards. Arnold Schwarzenegger or Ronnie Coleman didn't start off squatting 500 lbs on the first day.

    And also it's pretty hard to ask an online book questions.
    Last edited by Army; 01-09-2013 at 12:29 AM.
    PhQ likes this.

  15. #15
    Army is offline Senior Member
    Join Date
    Jan 2012
    Posts
    147
    Rep Power
    0

    Default Re: This ap course is so hard :(((

    Exercise 4.37* There are eight possible assignments of true and false to the boolean variables b, c, and d. Which assignments give !b && (c || !d) a different value from !(b || !c && d).

    Does anyone under stand this? How can you have an answer if there is nothing to compare it to be true or false with?

  16. #16
    Russd772 is offline Member
    Join Date
    Dec 2012
    Posts
    42
    Rep Power
    0

    Default Re: This ap course is so hard :(((

    have you ever studied boolean algebra? or logic? look up "logical OR" and "Logical AND" and that should help alot for you. just consider the true and false 1's and zeroes for that purpose its all the same, "1" being TRUE and "0" being FALSE

  17. #17
    Russd772 is offline Member
    Join Date
    Dec 2012
    Posts
    42
    Rep Power
    0

    Default Re: This ap course is so hard :(((

    actually include your search to include "inverters", "NAND" and "NOR" also, its not really complicated but it takes a bit of explaining

    basically && is the AND and || is the OR, so AND means that ALL values must be true in order for the statement to be true, and OR means that only one value must be true in order for the statement to be true.

    when you see a ! for examplye !b means that b has to evaluate to False to be considered TRUE.. im probably confusing the crap out of you, google is probably much better at explaining this.

    probably the easiest way to look at all possible outcomes would be to look at it like this


    a | b | c
    0 0 0 = ?
    0 0 1 = ?
    0 1 0 = ?
    0 1 1 = ?
    1 0 0 = ?
    1 0 1 = ?
    1 1 1 = ?


    these are all of the possible variations with 3 variables, 1 is true, 0 is false, you would do the same with the second statement then compare your answers to get your final answer
    Last edited by Russd772; 01-09-2013 at 03:26 AM. Reason: added some more

  18. #18
    Sierra is offline AN21XX
    Join Date
    Mar 2012
    Location
    Munich
    Posts
    297
    Rep Power
    3

    Default Re: This ap course is so hard :(((

    You missed 110 :)
    I like likes!

  19. #19
    Army is offline Senior Member
    Join Date
    Jan 2012
    Posts
    147
    Rep Power
    0

    Default Re: This ap course is so hard :(((

    Before I submitted the question I did write that out but I still was confused. All I'm confused about is what the && and the || effects.

  20. #20
    Sierra is offline AN21XX
    Join Date
    Mar 2012
    Location
    Munich
    Posts
    297
    Rep Power
    3

    Default Re: This ap course is so hard :(((

    It is not of much use to tell us that you are confused. You need to tell us what you want from us... explanation? Does something not work as expected?

    Take a look here: Summary of Operators (The Java™ Tutorials > Learning the Java Language > Language Basics)
    Fubarable likes this.
    I like likes!

Page 1 of 2 12 LastLast

Similar Threads

  1. Having a hard time figuring this out! Please help.
    By syngine90 in forum New To Java
    Replies: 2
    Last Post: 12-19-2012, 10:31 AM
  2. Hard Disk Bottleneck
    By urbanleg in forum New To Java
    Replies: 3
    Last Post: 09-27-2011, 03:02 PM
  3. hard to solve it
    By seongchog in forum New To Java
    Replies: 8
    Last Post: 09-16-2011, 08:50 PM
  4. How hard is it.....
    By neilp123 in forum New To Java
    Replies: 4
    Last Post: 07-22-2010, 04:21 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •