In: Computer Science
Part C (25 pts) Coding question Create a Java class name Store_XXXXX with last 5 digits of your student ID and write your code in there. A PC store sells many types of computers. The PC can have either 16 or 8 gigabytes of memory. The quality of the PCs can be either New, Refurbished, or Dented. The price list is given as follows: Memory size/Status New Refurbished Dented 16 gigabytes 849.99 729.99 609.99 8 gigabytes 699.99 579.99 439.99 Determine the price of a given PC dependent on the user inputs. The sale tax is 9.25% for each PC. User input can only be 8 or 16 for memory size and 'N', 'R', or 'D' for quality (upper-case). The input quantity should be 0 or positive. If any user input is not correct, display an error message and skip all calculation. All currency amounts should be displayed with 2 digits in decimal fraction. Here are several separate program sample runs. Enter the memory size of the PC (8 or 16 gigabytes): 16 Enter the quality of the PC (N for New, R for Refurbished, or D for Dented): N Enter PC quantity to buy: 2
The item price is $XXXX.XX The sale tax is $XXXX.XX The total bill is $XXXX.XX ---------------------- Enter the memory size of the PC (8 or 16 gigabytes): 8 Enter the quality of the
PC (N for New, R for Refurbished, or D for Dented): R Enter PC quantity to buy: 3 The item price is $XXXX.XX The sale tax is $XXXX.XX The total bill is $XXXX.XX ---------------------- Enter the memory size of the PC (8 or 16 gigabytes): 15 Invalid memory size! ---------------------- Enter the memory size of the PC (8 or 16 gigabytes): 8 Enter the quality of the PC (N for New, R for Refurbished, or D for Dented): A Invalid PC quality! ---------------------- Enter the memory size of the PC (8 or 16 gigabytes): 8 Enter the quality of the PC (N for New, R for Refurbished, or D for Dented): (user hit Tab key) Invalid PC quality! ---------------------- Enter the memory size of the PC (8 or 16 gigabytes): 16 Enter the quality of the PC (N for New, R for Refurbished, or D for Dented): R Enter PC quantity to buy: -2 Invalid PC quantity!
programme should be in java student id - 203866
Here iam provding the answer.Hope this helps you.If you have any doubts comment me i will clarify you.Please give me a feedback that helps me a lot.Thank you :-)
import java.util.*;
import java.lang.Math;
import java.text.DecimalFormat;
public class Store_03866{
public static void main(String[] args){
int memory;
Scanner sc = new Scanner(System.in);
System.out.print("Enter the memory size of the PC(8 OR 16 gugabytes): ");
memory=sc.nextInt();
String pattern = "######.##";
DecimalFormat decimalFormat = new DecimalFormat(pattern);
if(memory!=8 && memory!=16){
System.out.println("Invalid memory size!");
}
else{
Character type;
System.out.print("Enter the quality of the PC (N for New, R for Refurbished, or D for Dented): ");
type=sc.next().charAt(0);;
if(type.equals('N')){
System.out.print("Enter PC quantity to buy: ");
int quantity=sc.nextInt();
if(quantity<0){
System.out.println("Invalid PC quantity!");
}
else{
if(memory==8){
double total_amo=quantity*699.99;
System.out.println("The item price is $"+decimalFormat.format(total_amo));
System.out.println("The sale tax is $"+decimalFormat.format(total_amo*0.0925));
System.out.println("The total bill is $"+decimalFormat.format((total_amo-(total_amo*0.0925))));
}
if(memory==16){
double total_amo=quantity*849.99;
System.out.println("The item price is $"+decimalFormat.format(total_amo));
System.out.println("The sale tax is $"+decimalFormat.format(total_amo*0.0925));
System.out.println("The total bill is $"+decimalFormat.format((total_amo-(total_amo*0.0925))));
}
}
}
else if(type.equals('R')){
System.out.print("Enter PC quantity to buy: ");
int quantity=sc.nextInt();
if(quantity<0){
System.out.println("Invalid PC quantity!");
}
else{
if(memory==8){
double total_amo=quantity*579.99;
System.out.println("The item price is $"+decimalFormat.format(total_amo));
System.out.println("The sale tax is $"+decimalFormat.format(total_amo*0.0925));
System.out.println("The total bill is $"+decimalFormat.format((total_amo-(total_amo*0.0925))));
}
if(memory==16){
double total_amo=quantity*729.99;
System.out.println("The item price is $"+decimalFormat.format(total_amo));
System.out.println("The sale tax is $"+decimalFormat.format(total_amo*0.0925));
System.out.println("The total bill is $"+decimalFormat.format((total_amo-(total_amo*0.0925))));
}
}
}
else if(type.equals('D')){
System.out.print("Enter PC quantity to buy: ");
int quantity=sc.nextInt();
if(quantity<0){
System.out.println("Invalid PC quantity!");
}
else{
if(memory==8){
double total_amo=quantity*439.99;
System.out.println("The item price is $"+decimalFormat.format(total_amo));
System.out.println("The sale tax is $"+decimalFormat.format(total_amo*0.0925));
System.out.println("The total bill is $"+decimalFormat.format((total_amo-(total_amo*0.0925))));
}
if(memory==16){
double total_amo=quantity*609.99;
System.out.println("The item price is $"+decimalFormat.format(total_amo));
System.out.println("The sale tax is $"+decimalFormat.format(total_amo*0.0925));
System.out.println("The total bill is $"+decimalFormat.format((total_amo-(total_amo*0.0925))));
}
}
}
else{
System.out.println("Invalid PC quality!");
}
}
}
}
Output:-