|
L8
Oct 30, 2001 6:34:53 GMT -5
Post by pandachan on Oct 30, 2001 6:34:53 GMT -5
I was wondering if there is any way to write this class that can stop right after user types "quit". My class reads 4 information together, so that if user types "quit" in the first line, it still reads 3 more lines and stops.
|
|
|
L8
Oct 30, 2001 16:31:38 GMT -5
Post by Majin_Blues on Oct 30, 2001 16:31:38 GMT -5
i'll fill this one (i had the same dilemma):
make an if statement... if it says quit, break the loop (by changing it so it actually meets the specifications of the "while" loop)
you're gonna have to be shrewed on this one...
|
|
|
L8
Nov 1, 2001 23:23:19 GMT -5
Post by TheRock on Nov 1, 2001 23:23:19 GMT -5
I want to make sure I understand the question
when I run the program Apple [Enter] 5.5 [Enter] true [Enter] 2 [Enter] Purchases:11.0 Tax:1.65 Grand Total: 12.65 Orange [Enter] 6 [Enter] false [Enter] 1 [Enter] Purchases:17.0 Tax:1.65 Grand Total:18.65 Cole [Enter] quit <quit the program>
I use 4 'if' 'else' statement in my loop so I can type quit anytime to quit the program.
am I right?
|
|
|
L8
Nov 1, 2001 23:47:43 GMT -5
Post by Majin_Blues on Nov 1, 2001 23:47:43 GMT -5
you got it! ;D
it's a little tricky at first, but once you get it, it makes sense...
just be a little "if"-fy about it...
(what a horrible pun)
|
|
|
L8
Nov 3, 2001 8:17:40 GMT -5
Post by Sylph on Nov 3, 2001 8:17:40 GMT -5
they can press quit any time?! i thought just on the first one!
also, if they press quit in the beginning, does it still print out a receipt?
|
|
|
L8
Nov 3, 2001 8:20:21 GMT -5
Post by pandachan on Nov 3, 2001 8:20:21 GMT -5
How did u guys use if and else statement to break the loops? can u give me a hint pls?
|
|
|
L8
Nov 3, 2001 11:06:49 GMT -5
Post by Majin_Blues on Nov 3, 2001 11:06:49 GMT -5
it should still print a receipt in the beginning... all you have to do is just print the output or somethin... no biggie... (do you have your output line outside of the loop? that might help)
as for breaking the loop, it depends on your loop: if you used a while, make it so that the condition is met. If you used a for loop, make it so that the condition is NOT met
|
|
|
L8
Nov 3, 2001 18:18:47 GMT -5
Post by Sky on Nov 3, 2001 18:18:47 GMT -5
This is to TheRock...I am just wondering should we print the purchase information only once at the very end of the execution outside the loop...cuz the handout said "repeatedly do the following..." and it doesn't said to repeatedly print the purchase information...it said "at the end, print..." And I don't get how to do it this way... get what i mean???
|
|
|
L8
Nov 3, 2001 19:20:11 GMT -5
Post by Brutal_Chicken on Nov 3, 2001 19:20:11 GMT -5
That's the conundrum. Guys, considering that the other values aren't strings how can you compare it to a string? "quit" can only be typed in the first input.
Also, considering that all of your input is inside a while/for loop you're gonna hafta print it out every time all the info is entered. All the info previously entered remain (EDIT) regardless of whether or not you did anything about it... just re-read the GroceryItem.java.
|
|
|
L8
Nov 3, 2001 19:31:37 GMT -5
Post by Sky on Nov 3, 2001 19:31:37 GMT -5
Well...now i get how to make it to print the purchase information only at the very end and it can exit anytime during the execution when i input "quit"...come to think of that they make the two instance variable as private static...i think they really want the purchase info only at the end after "quit" is entered
|
|
|
L8
Nov 3, 2001 19:35:49 GMT -5
Post by Brutal_Chicken on Nov 3, 2001 19:35:49 GMT -5
Yep, you're right. The info is printed only after "quit" is entered. Damned keen eye you got there.
|
|
|
L8
Nov 3, 2001 20:06:57 GMT -5
Post by TheRock on Nov 3, 2001 20:06:57 GMT -5
Apple [Enter] 5.5 [Enter] true [Enter] 2 [Enter] Orange [Enter] 6 [Enter] false [Enter] 1 [Enter] Cole [Enter] quit [Enter] Purchases:17.0 Tax:1.65 Grand Total:18.65
is it right?
|
|
|
L8
Nov 3, 2001 20:13:26 GMT -5
Post by Majin_Blues on Nov 3, 2001 20:13:26 GMT -5
That's the conundrum. Guys, considering that the other values aren't strings how can you compare it to a string? "quit" can only be typed in the first input. Also, considering that all of your input is inside a while/for loop you're gonna hafta print it out every time all the info is entered. All the info previously entered remain (EDIT) regardless of whether or not you did anything about it... just re-read the GroceryItem.java. when you input the data, input it as string first then you convert it into whatever else you need to convert it to... (heh heh heh... clever) that way, you can check if it equals "quit" for every single input it doesn't have to print it out every time: just place the printout line outside of the loop (make sure the fields u use aren't instance variables or else it'll print out zeros!)
|
|
Brown_Man
New Member
Calculus make Brown Man mad!
Posts: 3
|
L8
Nov 4, 2001 19:59:44 GMT -5
Post by Brown_Man on Nov 4, 2001 19:59:44 GMT -5
One question. The question asks to instantiate a GroceryItem. How would you do that. Do you create a new GroceryItem object? Am I missing something? How can I edit the GroceryItem variables if they are all private? Ohhgaa boogaa? Help.
|
|
|
L8
Nov 4, 2001 20:05:24 GMT -5
Post by Majin_Blues on Nov 4, 2001 20:05:24 GMT -5
create a grocery item object... it's in the groceryitem.java file so you can make one.
and you're not editing them, you're assigning them inside a parameter:
groceryitem garbage = new groceryitem (insert parameters here as seen in groceryitem.java);
|
|