Help translating pseudocode into a Java program?

Home » Programming & Design » Help translating pseudocode into a Java program?
Programming & Design No Comments

This is homework, so I'm not asking for you to do my work for me, I'm just not comprehending what this wants from me, and I can't get in touch with my teacher. So, if somebody could help explain it to me

The following pseudocode describes how a bookstore computes the price of an order from the total

This is homework, so I'm not asking for you to do my work for me, I'm just not comprehending what this wants from me, and I can't get in touch with my teacher. So, if somebody could help explain it to me

The following pseudocode describes how a bookstore computes the price of an order from the total price and the number of the books that were ordered.

Read the book subtotal (the price of all the books added together) and the number of books.
Compute the tax (6.5 percent of the total book price).
Compute the shipping charge ($2.95 per book).
The price of the order is the sum of the total book price, the tax, and the shipping charge.
Print the price of the order.
No I'm *NOT* asking for you to do my work. I'm asking for help.

Best Answer:

stephdansletuyau: Let's decompose what you need:
"The following pseudocode describes how a bookstore computes the price of an order from the total price and the number of the books that were ordered. "

"Read the book subtotal (the price of all the books added together) and the number of books. ".
You need to use System.console().readLine();
Call it twice, once for the total price, and once for the number of books. Be careful, readline() returns a string, so you need to convert it to proper numeric type.

"Compute the tax (6.5 percent of the total book price). ". Just a multiplication of the subtotal by 0.065
"Compute the shipping charge ($2.95 per book). " you already know the number of books, so add 2.95 x bookcount

"The price of the order is the sum of the total book price, the tax, and the shipping charge. ", you just need to sum the subtotal, the tax and the delivery fee. Declare a variable, something like totalprice.
Then just print out the result.

You can also add some checks to make sure that the price and the number of books are positive, and use try/catch blocks for error handling.

Other answer:

stephdansletuyau:
You *ARE* asking us to do your work for you.

If you just want help, then you need to show us your attempt at translating it.

——————
Edit: When it says you need to read the data, it means you need to use a Scanner object to get the numbers from the keyboard. You shouldn't be hard-coding them into 4 variables like that.

http://www.java-tips.org/java-se-tips-10…
http://www.java2s.com/Tutorial/Java/0040…

The program does NOT have to add the price of the books. The user has to do that and then enter just the subtotal. It's unusual, but that's the assignment — probably because you haven't covered loops yet.

Margaret:
ask a Javanese from Java
Charles:
that nice question

LEAVE A COMMENT