• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Help wit h code

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
I am a student learning java
This is what i am required to do
A company sells five products Product 1, $2.98; product 2, $4.50;
product 3, $9.98; product 4, $4.49 and product 5, $6.87. Write an application that reads a series of pairs of numbers as follows:
a) product number
b) quantity sold
use a switch statement to determine the retail price for each product. It should calculate and display the total retail value of all products sold. Use a sentinel-controlled loop to determine when the program should stop looping and display the final results

Here is my code
am i on the right track





[edit: PMc added code tags and fiddled with spacing]
[ March 27, 2006: Message edited by: Pauline McNamara ]
 
Sheriff
Posts: 4012
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Sydney, welcome to Javaranch!

This forum is for Cattle Drive questions, so I'm moving your question over to Java In General - Beginner. I also took the liberty of adding code tags to your post so the code part looks more formatted.

Good luck with your course!

Pauline
 
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
On the right track. If this is all of your code, then I have to point
out that "price" is not declared, only defined. Change the "price" line
to "double price = ..." and then you can also lose the "(double)" on the
following lines.

I assume you will make quantity a double when you actually receive that
answer from the user (that code seems not to have been written yet).
[ March 27, 2006: Message edited by: Martin Simons ]
 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
in the line :


I guess you mean "OR" ("||") and not "AND" ("&&"). What about -2 ?
Maybe you could put a "default case" at the end of your switch statement that would do the same job.

regards
 
Sydney Naidoo
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for directing to the correct forumn.
Can someone help with correcting or enhancing the code for me.
 
author
Posts: 288
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need a main method to run it also would be nice to have some basic input validation to check if the user is keying in the right value.
[ March 28, 2006: Message edited by: ak pillai ]
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic