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 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....

  • 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...

  • 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...

  • Question 1 CSEB113 Write a program to create customer's bll for an electrical appliance company. Assume...

    Question 1 CSEB113 Write a program to create customer's bll for an electrical appliance company. Assume the company sells only three different products: TV, VCR and CD player. The unit prices are RM3000, RM500 and RM300 respectively. The program must read the quantity of each piece of the items purchased from the user. It then calculates the cost of each item, the subtotal and the total cost after an 6% of GST. Your program must use the following functions, given...

  • Create a program that performs the following operations: 1. Prompt for and accept a string of...

    Create a program that performs the following operations: 1. Prompt for and accept a string of up to 80 characters from the user. • The memory buffer for this string is created by: buffer: .space 80 #create space for string input The syscall to place input into the buffer looks like: li $v0,8 # code for syscall read_string la $a0, buffer #tell syscall where the buffer is li $a1, 80 # tell syscall how big the buffer is syscall 2....

  • Programing requirement for: Safety Alert System Version 01 I. Project and class name Create a new...

    Programing requirement for: Safety Alert System Version 01 I. Project and class name Create a new project name: yourfirst lastname program01 (you must include your name in the project name) Create a new class name: Safety Alert vo 1 II. Requirement 1. Input Prompt appropriate messages that asking use toenter: city name, season, temperature, and raining. Input validation: your program has to valid the user input and prompt specific message when user enter invalid input. Base on following validation: City...

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