wood burning stoves 2.0*
The moose likes Java in General and the fly likes cant get output right Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "cant get output right" Watch "cant get output right" New topic
Author

cant get output right

sherri statham
Greenhorn

Joined: Sep 14, 2006
Posts: 6
Ok i've gotten most of the code written, and a big headache too, lol
this what program should look like, but mine don't, any idea's?


Program input:
Enter product number, or <ctrl>z to stop:1
quantity sold for product 1:1
Enter product number, or <ctrl>z to stop:2
quantity sold for product 2:10
Enter product number, or <ctrl>z to stop:3
quantity sold for product 3:100
Enter product number, or <ctrl>z to stop:4
quantity sold for product 4:1000
Enter product number, or <ctrl>z to stop:5
quantity sold for product 5:10000
Enter product number, or <ctrl>z to stop: ^Z

Program output:
product Quantity unit price total sales

1 1 $ 2.98 $ 2.98
2 10 $ 4.50 $ 45.00
3 100 $ 9.98 $ 998.00
4 1000 $ 4.49 $ 4,490.00
5 10000 $ 6.87 $ 68,700.00

total sales $ 74,235.98

end of program


here the Pseudo code,
MailOrder

+main(args [ ] : String)

-PrintSalesReport( quantitySoldOfProduct1: int,

quantitySoldOfProduct2: int,

quantitySoldOfProduct3: int,

quantitySoldOfProduct4: int,

quantitySoldOfProduct5: int)




DEFINE a local variable input, a Scanner

DEFINE a local variable quantitySoldOfProduct1, an integer and initialize it to zero

DEFINE a local variable quantitySoldOfProduct2, an integer and initialize it to zero

DEFINE a local variable quantitySoldOfProduct3, an integer and initialize it to zero

DEFINE a local variable quantitySoldOfProduct4, an integer and initialize it to zero

DEFINE a local variable quantitySoldOfProduct5, an integer and initialize it to zero

DEFINE a local variable productId, an integer

DEFINE a local variable quantitySoldOfProduct, an integer

DISPLAY a blank line followed by the task id and programmer (your name) identification line.

DISPLAY a blank line followed by the �Program input:� line

DISPLAY the initial �Enter product number�� prompt

DO

Using nextInt() method of input variable, ASSIGN the entered value to productId

Using printf() method and appropriate horizontal tab(s), DISPLAY �Quantity sold� prompt

Using nextInt() method of input variable, ASSIGN the enter value to quantitySoldOfProduct

the switch statement, summarize quantitySoldOfProduct into appropriate

quantitySoldOfProduct1 through quantitySoldOfProduct5, depending on value of productId.

Within the switch statement, using default case, if an invalid productId has been entered,

DISPLAY an appropriate error message and ignore the input

DISPLAY the �Enter product�� prompt

WHILE (input.hasNext())

Using PrintSalesReport() method, print the sales report

DISPLAY a blank line followed by the �End of Program� line

DEFINE a local variable totalSalesAllProducts, an double and initialize it to zero

DEFINE a local variable unitPriceOfProduct1, an double and initialize it to 2.98

DEFINE a local variable unitPriceOfProduct2, an double and initialize it to 4.50

DEFINE a local variable unitPriceOfProduct3, an double and initialize it to 9.98

DEFINE a local variable unitPriceOfProduct4, an double and initialize it to 4.49

DEFINE a local variable unitPriceOfProduct5, an double and initialize it to 6.87

DEFINE a local variable product1Sales, a double and initialize it to

quantitySoldOfProduct1 * unitPriceOfProduct1

DEFINE a local variable product2Sales, a double and initialize it to

quantitySoldOfProduct2 * unitPriceOfProduct2

DEFINE a local variable product3Sales, a double and initialize it to

quantitySoldOfProduct3 * unitPriceOfProduct3

DEFINE a local variable product4Sales, a double and initialize it to

quantitySoldOfProduct4 * unitPriceOfProduct4

DEFINE a local variable product5Sales, a double and initialize it to

quantitySoldOfProduct5 * unitPriceOfProduct5

DISPLAY a blank line followed by the �Program output:� line

Using appropriate format specifiers and horizontal tabs, DISPLAY the column heading line

followed by a blank line

Using appropriate format specifiers and horizontal tabs, DISPLAY one line for each

product, its quantity sold, its unit price and its total sales

ASSIGN the sum of product1Sales through product5Sales TO totalSalesAllProducts

Using appropriate format specifiers and horizontal tabs, DISPLAY the �Total Sales� line


here is what I've written, but can't seem to get the readout to look like this example



sherri l statham
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

//need more print statements here


So... put more print statements there?


[Jess in Action][AskingGoodQuestions]
sherri statham
Greenhorn

Joined: Sep 14, 2006
Posts: 6
geez, why didn't i think about that!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: cant get output right
 
Similar Threads
Beginner Java Question
specifier format?
sentinal controlled looop
Program Output not working
Help wit h code