Results 1 to 20 of 23
Thread: This ap course is so hard :(((
 01082013, 08:18 PM #1Senior Member
 Join Date
 Jan 2012
 Posts
 147
 Rep Power
 0
This ap course is so hard :(((
Exercise 4.28* Revise the GuessNumber game to have the program lie onethird 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 }
 01082013, 08:39 PM #2AN21XX
 Join Date
 Mar 2012
 Location
 Munich
 Posts
 300
 Rep Power
 9
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.I like likes!
 01082013, 08:42 PM #3Member
 Join Date
 Dec 2012
 Posts
 42
 Rep Power
 0
Re: This ap course is so hard :(((
you could try and use a random number 02 (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"); }
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; 01082013 at 08:44 PM.
 01082013, 08:48 PM #4Senior Member
 Join Date
 Jan 2012
 Posts
 147
 Rep Power
 0
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 }
 01082013, 09:05 PM #5Member
 Join Date
 Dec 2012
 Location
 Des Moines, IA
 Posts
 35
 Rep Power
 0
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.
 01082013, 09:10 PM #6Member
 Join Date
 Dec 2012
 Posts
 42
 Rep Power
 0
 01082013, 09:14 PM #7
Re: This ap course is so hard :(((
Please go through the Forum Rules, particularly the third paragraph.
dbIf you're forever cleaning cobwebs, it's time to get rid of the spiders.
 01082013, 10:00 PM #8Senior Member
 Join Date
 Jan 2012
 Posts
 147
 Rep Power
 0
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; } //======================= }
 01082013, 10:25 PM #9AN21XX
 Join Date
 Mar 2012
 Location
 Munich
 Posts
 300
 Rep Power
 9
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? ;)I like likes!
 01082013, 10:35 PM #10Senior Member
 Join Date
 Jan 2012
 Posts
 147
 Rep Power
 0
Re: This ap course is so hard :(((
You're so helpfullllll :0
 01082013, 10:59 PM #11Member
 Join Date
 Dec 2012
 Location
 Des Moines, IA
 Posts
 35
 Rep Power
 0
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.
 01082013, 11:09 PM #12
Re: This ap course is so hard :(((
Last edited by PhQ; 01092013 at 12:13 AM.
 01082013, 11:11 PM #13AN21XX
 Join Date
 Mar 2012
 Location
 Munich
 Posts
 300
 Rep Power
 9
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!
 01092013, 12:16 AM #14Senior Member
 Join Date
 Jan 2012
 Posts
 147
 Rep Power
 0
Re: This ap course is so hard :(((
Last edited by Army; 01092013 at 12:29 AM.
 01092013, 02:27 AM #15Senior Member
 Join Date
 Jan 2012
 Posts
 147
 Rep Power
 0
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?
 01092013, 03:16 AM #16Member
 Join Date
 Dec 2012
 Posts
 42
 Rep Power
 0
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
 01092013, 03:18 AM #17Member
 Join Date
 Dec 2012
 Posts
 42
 Rep Power
 0
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 answerLast edited by Russd772; 01092013 at 03:26 AM. Reason: added some more
 01092013, 09:57 AM #18AN21XX
 Join Date
 Mar 2012
 Location
 Munich
 Posts
 300
 Rep Power
 9
Re: This ap course is so hard :(((
You missed 110 :)
I like likes!
 01092013, 04:16 PM #19Senior Member
 Join Date
 Jan 2012
 Posts
 147
 Rep Power
 0
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.
 01092013, 04:22 PM #20AN21XX
 Join Date
 Mar 2012
 Location
 Munich
 Posts
 300
 Rep Power
 9
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)I like likes!
Similar Threads

Having a hard time figuring this out! Please help.
By syngine90 in forum New To JavaReplies: 2Last Post: 12192012, 10:31 AM 
Hard Disk Bottleneck
By urbanleg in forum New To JavaReplies: 3Last Post: 09272011, 03:02 PM 
hard to solve it
By seongchog in forum New To JavaReplies: 8Last Post: 09162011, 08:50 PM 
How hard is it.....
By neilp123 in forum New To JavaReplies: 4Last Post: 07222010, 04:21 PM
Bookmarks