aspose file tools*
The moose likes Java in General and the fly likes The Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "The Problem" Watch "The Problem" New topic
Author

The Problem

Thomas Wren
Greenhorn

Joined: Nov 06, 2006
Posts: 11
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
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> The problem is:

No, that is the task (your task).

What specific problem do you have?
Thomas Wren
Greenhorn

Joined: Nov 06, 2006
Posts: 11
it should be Product 3 $9.98
Thomas Wren
Greenhorn

Joined: Nov 06, 2006
Posts: 11
How do I start this program?
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24184
    
  34

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.


[Jess in Action][AskingGoodQuestions]
Garrett Rowe
Ranch Hand

Joined: Jan 17, 2006
Posts: 1296
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


Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
Thomas Wren
Greenhorn

Joined: Nov 06, 2006
Posts: 11
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
Marshal

Joined: Jul 08, 2003
Posts: 24184
    
  34

You shouldn't need to do anything nearly so complex; just use arrays.
Thomas Wren
Greenhorn

Joined: Nov 06, 2006
Posts: 11
The only problem with using Arrays, Is I havent learned them yet in class.
Thomas Wren
Greenhorn

Joined: Nov 06, 2006
Posts: 11
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

Joined: Nov 06, 2006
Posts: 11
Close this one too.. Cause its just bogging down your space.
 
 
subject: The Problem