This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Total of something - Need help - PLEASE! :o) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Total of something - Need help - PLEASE! :o)" Watch "Total of something - Need help - PLEASE! :o)" New topic
Author

Total of something - Need help - PLEASE! :o)

Rose Evans
Ranch Hand

Joined: Oct 14, 2004
Posts: 195
You guys, I need some help so much! I canNOT figure out how to add items together to get the total price after they finish buying something.
Please would you have any ideas?
I know if I had variables like total, and amount, it would be ...
total = total + amount;
But those aren't my variable names, and this program has so many methods and stuff in it.
Any suggestions?? Here's part of my code..

public class PurchaseDemo1
{
public static void main(String[] args)
{
Purchase1 oneSale = new Purchase1( );

char answer = 'y';
double finalBill = 0;

while (answer == 'y' || answer == 'Y')

{
oneSale.readInput( );
oneSale.writeOutput( );
System.out.println("*** Cost each $" + oneSale.getUnitCost( ));
System.out.println("*** Total cost $" + oneSale.getTotalCost( ));
System.out.println("*** Your final bill is $" + //HOW DO YOU GET THIS TOTAL??




System.out.println("Do you want to purchase more items? ");
System.out.println("Press y for yes, Press any other key to check out.");
answer = SavitchIn.readLineNonwhiteChar();

}
}
}

I'd appreciate any help you could give me.


) ) ) )
Jeff Bosch
Ranch Hand

Joined: Jul 30, 2003
Posts: 804
You have the info you need in these two lines:



Now, if instead of directly printing the return value of the two methods, you could save them to variables and print the variables. Then, in the third line, you could multiply the total cost by the markup, which should give you the total value. Of course, I'm making a lot of assumptions here because the information was very incomplete...


Give a man a fish, he'll eat for one day. Teach a man to fish, he'll drink all your beer.
Cheers, Jeff (SCJP 1.4, SCJD in progress, if you can call that progress...)
Rose Evans
Ranch Hand

Joined: Oct 14, 2004
Posts: 195
Jeff,

Yeah, I thought the answer was in those two lines, but every time I tried to code something, I would get errors.
I don't quite know how to do that though. It seems so simple, I don't know why it won't click in my brain.


Would you need to see my huge code that goes with that for more information? I'm banging my head against the wall. Ha.
Rose Evans
Ranch Hand

Joined: Oct 14, 2004
Posts: 195
Jeff,

I did it!! Yeahhhhhhhhhhhhhhhhhhhhhhhh, I played with it and played with it, until I got it to do what I wanted!!! Jumping up and down now!!
Jeff Bosch
Ranch Hand

Joined: Jul 30, 2003
Posts: 804
Way cool, Rose!!! Now that's how you become a great programmer, just keeping at it and trying stuff. Great job!!!
Rose Evans
Ranch Hand

Joined: Oct 14, 2004
Posts: 195
I was so proud of myself, I even e-mailed my teacher personally to tell her I figured it out!! Ha ha.
Programming is really fun!! I was SO happy I figured it out!!! Now, I have two more programs to write. Wish me luck.
Thanks for responding.
Jeff Bosch
Ranch Hand

Joined: Jul 30, 2003
Posts: 804
Good luck! With your attitude of fun, you'll do great!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Total of something - Need help - PLEASE! :o)
 
Similar Threads
Party Program
Loop for console input....
Entering many records..Need help!
New to Java and need help
Need advice - How to add items and keep a running total.