• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 808
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
Rose Evans
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 195
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 808
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 195
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 808
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good luck! With your attitude of fun, you'll do great!
 
We find this kind of rampant individuality very disturbing. But not this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic