Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

An online retailer has hired you to write a program to calculate the total cost

ID: 441912 • Letter: A

Question

An online retailer has hired you to write a program to calculate the total cost of a customer's purchases. The customer may order books, movies, and peanuts. Books are $9 each. Movies are $16 each. Peanuts are sold at$1.80 per pound and can be purchased by the tenth of a pound. The shipping cost for each book is $1. The shipping cost for movies is 10% of the movie subtotal portion of the order. The shipping charge for peanuts is 20cents per pound of peanuts ordered. The program must prompt the user to input the number of books, movies, and peanuts (in lbs.) that he would like to purchase and obtain those amounts in that specified order. The program calculates and displays the subtotal of these amounts and the cost of shipping. The program must then output the total cost of the order. You are guaranteed that the user will type a whole numbers between 0 and 50, inclusive, for each input, except for the pounds of peanuts. The pounds of peanuts input will be an integer or floating-point value to the tenths place between or including 0 and 50 (e.g. 21.4). If the user provides other input (letters, numbers with more than one place to the right of the decimal, etc.) your program's behavior is arbitrary. It can crash, work normally, freeze up, etc. Sample run: How many books? 11 How many movies? 3 How many pounds of peanuts? 13.5 Books: 99 Movies: 48 Peanuts: 24.3 Subtotal: 171.3 Shipping: 18.5 Total: 189.8

Explanation / Answer

import java.util.*;
import java.lang.*;

class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner in = new Scanner(System.in);
System.out.println(" How many books?");
int books = in.nextInt();
System.out.println(" How many movies?");
int movies = in.nextInt();
System.out.println(" How many pounds of peanuts? ");
double peanuts = in.nextDouble();
System.out.println(" Books: " + (books*9));
System.out.println(" Movies: " + (movies*16));
System.out.println(" Peanuts: " + (peanuts*1.80));
double subtotal = books*9 + movies*16 + peanuts*1.80;
double shipping = books*1 + movies*16*0.1 + peanuts*0.2;
System.out.println(" subtotal: " + subtotal);
System.out.println(" shipping: " + shipping);
System.out.println(" Total: : " + (subtotal+shipping));

}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote