Begin a Java program from scratch. Name it Assign5. Add an import statement to u
ID: 3565843 • Letter: B
Question
Begin a Java program from scratch. Name it Assign5.
Add an import statement to use the Scanner class.
Declare a constant representing a sales tax rate of 7.5%.
Declare three double variables named price, salesTax and total.
Declare a Scanner object named keyScan for keyboard input.
Display a banner message, or greeting, of the following: Welcome to the NIU Pricing System
Skip a line and display a prompt of the following: Enter the item's price:
Get the user's input using the Scanner method nextDouble( ) and assign the value to the variable named price.
Skip a line and display the item's price with two decimal places and full editing with a floating dollar sign and commas between the thousands places if necessary.
Calculate the sales tax using the constant you created for tax rate and the price and assign it to the variable named salesTax.
On the line immediately following the item's price, and with the decimal points lined up in the same column, one over the other, display the sales tax with two decimal places and full editing with a floating dollar sign and commas between the thousands places if necessary.
On the line immediately following the sales tax, display 13 hyphens.
Calculate the total of the sale and assign it to the variable named total.
On the line immediately following the line with 13 hyphens, display the total with the decimal point lined up under the previous two dollar amounts and with two decimal places and full editing with a floating dollar sign and commas between the thousands places if necessary.. After everything, skip a line and display "Thank you for using the NIU Pricing System!"
Sample output with the user entering 1004.58 when prompted:
Welcome to the NIU Pricing System
Please enter the item's price: 1004.58
Price: $1,004.58
Sales Tax: $75.34
-------------
Total: $1,079.92
Thank you for using the NIU Pricing System!
Use the edit pattern of "$#,###,##0.00" in your program.
Take your Assignment 5 Java program and change its name to Assign6.java. Be sure to name the class Assign6 too.
You will be making a few minor changes to the program:
1) Add a second constant for a second tax rate. Name it and the first tax rate appropriately. The first tax rate will be the same as before and the second should be 3.75%.
2) After prompting and getting the price of the item, charge the second tax rate if the price is greater than or equal to 125.00. Otherwise, charge the first, or highest, tax rate. Hint: Use an if with an else decision structure.
3) Your display should look exactly the same as before but, of course, the sales tax will be computed based on the conditional statement described in 2) above.
Submit your Assign6.java program fully and correctly documented by 11:59 PM on Friday, 10/10/2014.
Take your Assignment 6 Java program and change its name to Assign7.java. Be sure to name the class Assign7 too.
You will be making a few minor changes to the program:
1) Add a third constant for a third tax rate and a fourth constant for a fourth tax rate. Name each appropriately. The four tax rates will be 1%, 2.75%, 3.5% and 4.75%.
2) After prompting and getting the price of the item, charge the highest tax rate if the price is 0.00 < price < 75.00, the second highest tax rate if the price is 75.00 <= price < 125.00, the third highest tax rate if the price is 125.00 <= price < 225.00 and the lowest tax rate if the price is >= 225.00. Hint: Use a cascading if structure going from highest dollar amount to lowest. DO NOT USE COMPOUND CONDITIONS AS THERE IS NO NEED TO DO SO!!!
3) Display each dollar amount with a floating dollar sign and commas in between the thousands places. You may refer to the document named Formatting Dollar Amounts in Java in the Slides & Notes Section of Blackboard.
4) Be sure that you display the header and trailer messages with exactly the same wording as displayed below!
If the price entered is 1345.87, your output should look like the following example:
Welcome to the NIU CSCI 210 Pricing System
Please enter the item's price: 1345.87
Price $1,345.87
Sales Tax $13.46
---------------
Total $1,359.33
Thank you for using the NIU CSCI 210 Pricing System!
I need the assign7.
Explanation / Answer
package vijay;
import java.text.DecimalFormat;
import java.util.Scanner;
public class Assign5 {
static final double sales_tax_rate=7.5;
public static void main(String[] args) {
double price, salesTax ,total;
Scanner sc=new Scanner(System.in);
System.out.println("Welcome to the NIU Pricing System");
System.out.println(" Enter the item's price : ");
price=sc.nextDouble();
System.out.println();
System.out.println("price:$"+price);
DecimalFormat df=new DecimalFormat("#.00");
salesTax=(price*sales_tax_rate)/100;
double st=Double.parseDouble(df.format(salesTax));
salesTax=st;
System.out.println("Sales Tax:$"+salesTax);
System.out.println("-------------");
System.out.println("Total:$"+(price+st));
System.out.println();
System.out.println("Thank you for using the NIU Pricing System!");
}
}
package vijay;
import java.text.DecimalFormat;
import java.util.Scanner;
public class Assign6 {
static final double sales_tax_rate=7.5;
static final double second_tax_rate=3.75;
public static void main(String[] args) {
double price, salesTax ,total;
Scanner sc=new Scanner(System.in);
System.out.println("Welcome to the NIU Pricing System");
System.out.println(" Enter the item's price : ");
price=sc.nextDouble();
System.out.println();
System.out.println("price:$"+price);
DecimalFormat df=new DecimalFormat("#.00");
if(price<125)
{
salesTax=(price*sales_tax_rate)/100;
}
else
{
salesTax=(price*second_tax_rate)/100;
}
double st=Double.parseDouble(df.format(salesTax));
salesTax=st;
System.out.println("Sales Tax:$"+salesTax);
System.out.println("-------------");
System.out.println("Total:$"+(price+st));
System.out.println();
System.out.println("Thank you for using the NIU Pricing System!");
}
}
package vijay;
import java.text.DecimalFormat;
import java.util.Scanner;
public class Assign7 {
static final double sales_tax_rate=1;
static final double second_tax_rate=2.75;
static final double third_tax_rate=3.5;
static final double fourth_tax_rate=4.75;
public static void main(String[] args) {
double price, salesTax = 0 ,total;
Scanner sc=new Scanner(System.in);
System.out.println("Welcome to the NIU Pricing System");
System.out.println(" Enter the item's price : ");
price=sc.nextDouble();
DecimalFormat df=new DecimalFormat("#,###,##0.00");
System.out.println();
System.out.println("price:$"+df.format(price));
if(price>0&&price<75)
{
salesTax=(price*fourth_tax_rate)/100;
}
else if(75<=price && price <125)
{
salesTax=(price*second_tax_rate)/100;
}
else if(125<=price && price <225)
{
salesTax=(price*third_tax_rate)/100;
}
else if(price>=225)
{
salesTax=(price*sales_tax_rate)/100;
}
System.out.println("Sales Tax:$"+df.format(salesTax));
System.out.println("-------------");
System.out.println("Total:$"+df.format(price+salesTax));
System.out.println();
System.out.println("Thank you for using the NIU Pricing System!");
}
}
o/p:
Welcome to the NIU Pricing System
Enter the item's price :
1367.46
price:$1,367.46
Sales Tax:$13.67
-------------
Total:$1,381.13
Thank you for using the NIU Pricing System!
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.