Question

Java I: Create a Java program that will accept the price of an item and the...

Java I: Create a Java program that will accept the price of an item and the quantity being purchased of that item. After accepting the input, calculate the amount of the purchase (based on the price and quantity), calculate the sales tax on the purchase, then output the product price, quantity, subtotal, sales tax, and the total sale based on the output format shown below.

Structure your file name and class name on the following pattern:

The first three letters of your last name (begin with upper case.).

Then the first two letters of your first name (begin with upper case.).

Follow this with the name of the program: ProductSales.

For a student called ’John Doe,’ the class name and file name would be: DoeJoProductSales

--------------------------------------

Name the program ProductSales and format the title as described above by incorporating your name.

Use good comments:

Write a good description of what the program does.

Use comments within the code as well, especially on calculations and other areas that might need some explanation.

Think about the problem and decide what type each of the input numbers should be. Also, think about the calculations and decide what type the variables should be that will hold the results of the calculations.

Use camel casing for variable names, and use descriptive variable names. This time I will take points off for variable names like "tax" or "total."

Prompt the user with a statement asking for each of the input values. Clearly express what the user is to enter. Each prompt will be a simple text statement that will appear just prior to the input of the number.

Label all output to match the Output Format section below.

Use the printf() method to format the output of the dollar amounts.

Tip     

Tip #1

The sales tax amount should be a constant in the program and does not need to be input. Set that constant equal to 0.06 and use that constant variable in the calculation.

Tip     

Tip #2

Other than the quantity, the variables in this program will hold dollar amounts. Therefore, be sure that your variable types will hold dollar amounts (dollars and cents), and that the variables to hold the results of calculations will hold those types as well.

--------------------

3.2. Output Format

Format the output to look similar to the following:

The 9s simply indicate where numbers will be. There will not always be a number for each 9, except for the cents in the dollar amounts.

***** Product Sale Calculations *****

Product price: $9.99

Number of units purchased: 9

Subtotal: $99.99

Sale tax on purchase: $99.99

Final Sale amount: $99.99

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code


import java.text.DecimalFormat;//for formatted output
import java.util.*;//for Scanner

public class DoeJoProductSales {

/**
* @param args the command line arguments
*/
public static final float constant = 0.06f;//declaring the constant variable that holds the sales tax
public static void main(String[] args)
{
Scanner input=new Scanner(System.in);
DecimalFormat ft = new DecimalFormat("$###,###.##");
int quanity;//variable quntity type int that will hold the quntity of the product entered by the user
//variable productPrice holds the price of the product
//variable subTotal holds the subtotal productprice * quantity
//variable saleTax holds the total saleTax on purchase
//varianle totalAmount holds the total amount of purchase i.e suTotal + saleTax
float productPrice,subTotal,saleTax,totalAmount;
//taking the product price from the user
  
System.out.print("Enter the price of the Product: $");
productPrice=input.nextFloat();
  
//taking the product quantity from the user
System.out.print("Enter the qunity of Product you want to purchase: ");
quanity=input.nextInt();
  
subTotal=productPrice*quanity;//calculating the subtotal
saleTax=subTotal*constant;//calculting the saleTax
totalAmount=subTotal+saleTax;//calculating the total amount
System.out.printf("\n\n***** Product Sale Calculations *****\n");
System.out.printf("Number of units purchased: : %d\n",quanity);
System.out.printf("Subtotal: $%.2f\n",subTotal);
System.out.printf("Sale tax on purchase: $%.2f\n",saleTax);
System.out.printf("Final Sale amount: $%.2f\n",totalAmount);
}
  
}
output

Product Sale Calculation-NetBeans IDE 8.0.2 File Edit View Navigate Source Refactor Run Debug Profie Teem Iools Window Help SIf you have any query regarding the code please ask me in the comment i am here for help you. Please do not direct thumbs down just ask if you have any query. And if you like my work then please appreciates with up vote. Thank You.

Add a comment
Know the answer?
Add Answer to:
Java I: Create a Java program that will accept the price of an item and the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In this project you will write a C++ program that simulates the purchase of a single...

    In this project you will write a C++ program that simulates the purchase of a single item in an online store. What to do Write a C++ program that: 1. Prints out a welcome message. 2. Prompts the user for the following information: (a) Their first name (example: Roger) (b) Their last name (example: Waters) (c) The name of the product (example: Brick) (d) The unit price of the product (example: 1.99) (e) The quantity to buy (example: 200) (f)...

  • CIT 149 Java 1 programming question Use DrJava to compile the following try-catch program ? The...

    CIT 149 Java 1 programming question Use DrJava to compile the following try-catch program ? The Assignment ? Specifications General Structure your file name and class name on the following pattern: The first three letters of your last name (begin with upper case.). Then the first two letters of your first name (begin with upper case.). Follow this with the name of the program: TryCatch. For a student called ’John Doe,’ the class name and file name would be: DoeJoTryCatch...

  • Create a program named TipCalculation that includes two overloaded methods named DisplayTipInfo. One should accept a...

    Create a program named TipCalculation that includes two overloaded methods named DisplayTipInfo. One should accept a meal price and a tip as doubles (for example, 30.00 and 0.20, where 0.20 represents a 20 percent tip). The other should accept a meal price as a double and a tip amount as an integer (for example, 30.00 and 5, where 5 represents a $5 tip). Each method displays the meal price, the tip as a percentage of the meal price, the tip...

  • java; programing language Write a program to calculate the price of a purchase. It should ask...

    java; programing language Write a program to calculate the price of a purchase. It should ask the user to enter the name of the item bought (like sweater, apple, …), number of items bought (4, 5 lbs,…), price per item ($40.50, $1.99 per pound,…), and the sales tax rate (8.35% for example). It should calculate the subtotal (price*number of items), sales tax (subtotal*sales tax), and total price (subtotal+ sales tax). It should print all the information in a receipt form

  • Java programming Create a simple tip calculator called TipCalcMethod. Your program should read in the bill...

    Java programming Create a simple tip calculator called TipCalcMethod. Your program should read in the bill amount from the command-line, then show 3 tip amounts: 15%, 20% and 25% of the bill. Don't worry about rounding the result to two decimal places, but make sure that the result includes cents (not just dollars). This program will be different than your first Tipcalc program because you will writea method to calculate the tip amount. program will have 2 methods: main) and...

  • Create a new program in Mu and save it as ps2.4.1.py Take the code below and...

    Create a new program in Mu and save it as ps2.4.1.py Take the code below and fix it as indicated in the comments: dividend = 7 divisor = 3 # You may modify the lines of code above, but don't move them! # Your code should work with different values for the variables. # The variables above create a dividend and a divisor. Add # some code below that will print the quotient and remainder # of performing this operation....

  • Your app is computing and displaying tax for the user, in the format “Hello John Doe,...

    Your app is computing and displaying tax for the user, in the format “Hello John Doe, Your Tax is: ......” , where John Doe is the name entered, and .... indicates the tax amount as a dollar figure. Your form has two textboxes, where the user will enter his/her name, and income, and click a Submit button. Your app will store the name entered by the user into a variable of type String, and store the income into a variable...

  • Write a Java program to meet the following requirements: 1. Prompt the user to enter three...

    Write a Java program to meet the following requirements: 1. Prompt the user to enter three strings by using nextLine(). Space can be part of the string). ( Note: your program requires using loop: for-loop, while-loop or do-while-loop to get the input String ) 2. Write a method with an input variable (string type).The method should return the number of lowercase letters of the input variable. 3. Get the number of the lowercase letters for each user input string by...

  • In Java. Write a GUI contact list application. The program should allow you to input names...

    In Java. Write a GUI contact list application. The program should allow you to input names and phone numbers. You should also be able to input a name and have it display the previously entered phone number. The GUI should look something like the following, although you are welcome to format it in any way that works. This should be a GUI application with a JFrame. The program should contain two arrays of Strings. One array will contain a list...

  • Write a C++ program that calculates the discount of the original price of an item and...

    Write a C++ program that calculates the discount of the original price of an item and displays the new price, and the total amount of savings. This program should have a separate header (discount.h), implementation (discount.cpp) and application files (main.cpp). The program must also have user input: the user must be prompted to enter data (the original price, and the percent off as a percentage). There must also be a validation, for example: Output: “Enter the original price of the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT