Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please divide the program below in three classes. Java package test; import java.util.Scanner; import java.text.NumberFormat; import java.math.BigDecimal; import java.math.RoundingMode; public class Invoice { public static
Please divide the program below in three classes. Java
package test; import java.util.Scanner; import java.text.NumberFormat; import java.math.BigDecimal; import java.math.RoundingMode; public class Invoice { public static void main (String[] args) { System.out.println("Welcome to the invoice calculator"); System.out.println(); Scanner sc = new Scanner(System.in); String choice = "y"; while (!choice.equalsIgnoreCase("n")) { System.out.println("Enter subtotal: "); String subtotalLine = sc.nextLine(); double subtotal = new BigDecimal(subtotalLine).setScale(2,RoundingMode.HALF_UP).doubleValue(); double dicsountPercent; if (subtotal >= 200) { dicsountPercent = .2; }else if (subtotal >= 100) { dicsountPercent = .1; }else { dicsountPercent = 0; } //calculate discount double discountAmount = subtotal * dicsountPercent; discountAmount = new BigDecimal(discountAmount).setScale(2,RoundingMode.HALF_UP).doubleValue(); //calculate sales tax double totalBeforeTax = subtotal - discountAmount; //calculate sales tax final double SALES_TAX_PCT = .05; double salesTax = SALES_TAX_PCT * totalBeforeTax; salesTax = new BigDecimal(salesTax).setScale(2,RoundingMode.HALF_UP).doubleValue(); //calculate total double total = totalBeforeTax + salesTax; //get the currency and percent formatted objects NumberFormat currency = NumberFormat.getCurrencyInstance(); NumberFormat percent = NumberFormat.getPercentInstance(); //display the data String message = " INVOICE " + "subtotal: " + currency.format(subtotal) + " " + "Discount percent: " + percent.format(dicsountPercent) + " " + "Discount amount: " + currency.format(discountAmount) + " " + "Total before tax: " + currency.format(totalBeforeTax) + " " + "Sales tax: " + currency.format(salesTax) + " " + "Invoice total: " + currency.format(total) + " "; System.out.println(message); //see if the user wants to continue System.out.println("Continue? (y): "); choice = sc.nextLine(); System.out.println(); } System.out.println("Application Ended"); } }
This is a program created in only one class. What I have to do is to create the same program but using three different classes. In other words I need to create a program that does exactly the same thing as the program below, but instead of using only one class, I need to use 3 classes.
2-Below is a program written to calculate an invoice total. Analyze and modify the program to design an object-oriented solution by using the three layers architecture, and provide code to include the following: A business rule layer with methods to manipulate data (i.e: Constructor(s), mutators, accessor, customized methods, and others) - A Database layer for data processing An user interface layer to test your application - Exception handling statements that handles exceptions when they occur. Overloaded methods as needed. Note: Provide an object-oriented design solution for the Java application Thank you
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started