• 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
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

The Problem

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Guys and Gals,

I am facing a problem with a problem. My problem is I do not know how to start this problem. The problem is:


A mail-order house sells five products whose retail prices are as follows: 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 seris of pairs of numbers as follows:
a) product number b)quantity sold

The program should 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.

The program should have two methods. Not counting the main.


Thanks,
Thomas
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
> The problem is:

No, that is the task (your task).

What specific problem do you have?
 
Thomas Wren
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
it should be Product 3 $9.98
 
Thomas Wren
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How do I start this program?
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Start with



Compile that, run it. It should do nothing.

Now, add code to open a file, read a line, and display it.



Compile that; create a file "mydatafile.txt" with some text in it; run the program. It should print out one line from the file.

Now add some code to read two numbers from the file and print them. Edit the data file to contain lines of numbers. Compile the program, run it.

Repeat until the program is working!

If, at any point, the program doesn't do what it should, fix it before moving on.
 
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Thomas Wren:
How do I start this program?


I always start by trying to get a little piece working.

Try to get that to read:

Product number = 1
Product price = 298 cents
 
Thomas Wren
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks guys.. Have another question?

What if I did something like this;

public static void prodCounters(int N, int prodQ)
{
switch( prod N);
case 1; += prodQ; // increment aCount
break; // necessary to exit switch
case 2; +


how could I finish the rest?
 
Ernest Friedman-Hill
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You shouldn't need to do anything nearly so complex; just use arrays.
 
Thomas Wren
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The only problem with using Arrays, Is I havent learned them yet in class.
 
Thomas Wren
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
import java.util.Scanner; // program uses class Scanner

public class tw54663def
{
private int total; // sum of products
private int Counter; // quantity entered by user
private int aCount; // count of product 1
private int bCount; // count of product 2
private int cCount; // count of product 3
private int dCount; // count of product 4





This is How I think I am suppose to start it... How do i set values to the Products. So it still follows the format of the program.
 
Thomas Wren
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Close this one too.. Cause its just bogging down your space.
 
Police line, do not cross. Well, this tiny ad can go through:
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