Question

In: Computer Science

Part C (25 pts) Coding question Create a Java class name Store_XXXXX with last 5 digits...

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

Solutions

Expert Solution

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


Related Solutions

Java Coding Part A Create a class Employee. Employees have a name.   Also give Employee a...
Java Coding Part A Create a class Employee. Employees have a name.   Also give Employee a method paycheck() which returns a double. For basic employees, paycheck is always 0 (they just get health insurance). Give the class a parameterized constructor that takes the name; Add a method reportDeposit. This method prints a report for the employee with the original amount of the paycheck, the amount taken out for taxes (we will do a flat 17%), and the final amount (for...
Create a Class with Data Fields and Methods in Java. Provide a Java coding solution for...
Create a Class with Data Fields and Methods in Java. Provide a Java coding solution for the following: 1. Name the class SalonServices 2. Add private data fields: a. salonServiceDescription – This field is a String type b. price - This field is a double type 3. Create two methods that will set the field values. a. The first method setSalonServiceDescription() accepts a String parameter defined as service and assigns it to the salonServiceDescription. The method is not static b....
Java Coding Background You will create a Java class that simulates a water holding tank. The...
Java Coding Background You will create a Java class that simulates a water holding tank. The holding tank can hold volumes of water (measured in gallons) that range from 0 (empty) up to a maximum. If more than the maximum capacity is added to the holding tank, an overflow valve causes the excess to be dumped into the sewer system. Assignment The class will be named HoldingTank. The class attributes will consist of two int fields – current and maxCapacity....
C# (Thank you in advance) Create an Employee class with five fields: first name, last name,...
C# (Thank you in advance) Create an Employee class with five fields: first name, last name, workID, yearStartedWked, and initSalary. It includes constructor(s) and properties to initialize values for all fields. Create an interface, SalaryCalculate, class that includes two functions: first,CalcYearWorked() function, it takes one parameter (currentyear) and calculates the number of year the worker has been working. The second function, CalcCurSalary() function that calculates the current year salary. Create a Worker classes that is derived from Employee and SalaryCalculate...
JAVA CODING PLEASE Create a class SportsCar that inherits from the Car class (CAR CLASS LISTED...
JAVA CODING PLEASE Create a class SportsCar that inherits from the Car class (CAR CLASS LISTED BELOW THIS QUESTION). Include the following: A variable Roof that holds the type of roof (Ex: Convertible, Hard-Top, Soft-Top) A variable Doors that holds the car’s number of doors (Ex: 2, 4) Implement the ChangeSpeed method to add 20 to the speed each time it is called. Add exception handling to the ChangeSpeed method to keep the speed under 65. Implement the sound method...
c# language Create a class “Person” which included first name, last name, age, gender, salary, and...
c# language Create a class “Person” which included first name, last name, age, gender, salary, and havekids (Boolean) variables. You have to create constructors and prosperities for the class. Create a “MatchingDemo” class. In the main function, the program reads the number of people in the database from the “PersonInfo.txt” file and creates a dynamic array of the object. It also reads the people's information from “PersonInfo.txt” file and save them into the array. Give the user the ability to...
Create a Java project called 5 and a class named 5 Create a second new class...
Create a Java project called 5 and a class named 5 Create a second new class named CoinFlipper Add 2 int instance variables named headsCount and tailsCount Add a constructor with no parameters that sets both instance variables to 0; Add a public int method named flipCoin (no parameters). It should generate a random number between 0 & 1 and return that number. (Important note: put the Random randomNumbers = new Random(); statement before all the methods, just under the...
Create a java class with name Cat. Instructions for Cat class: This class is modeled after...
Create a java class with name Cat. Instructions for Cat class: This class is modeled after a Cat. You should have instance variables as follows: The Cat’s name The number of mice caught by the Cat. Whether or not the Cat is secretly plotting to kill you Note that you will need to choose both good types and meaningful identifiers for each of these instance variables. You may also assume that the Cat is not automatically always secretly plotting to...
java script coding to create a math test program with 5 questions.
java script coding to create a math test program with 5 questions.
Create java class with name BaseballPlayer Instructions for BaseballPlayer class: The BaseballPlayer class is modeled after...
Create java class with name BaseballPlayer Instructions for BaseballPlayer class: The BaseballPlayer class is modeled after a BaseballPlayer and will contain methods to calculate various statistics based on the stats of a player. For this class, you will want to use a static variable for storing a DecimalFormat object. See the API document for the BaseballPlayer class for a list of methods you will write. API Document Constructors: Identifier: BaseballPlayer(String name, int number, int singles, int doubles, int triples, int...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT