Using Java For this assignment you will develop two classes
Using Java:
For this assignment, you will develop two classes. The first class will contain:
-The main method
-A method for greeting the user when the program begins
-A method for user input for the bag weight and number of bags
-A method that handles output for the results
-The results will include the current date calculated using the built-in Date class.
-Align the output as shown in the output referenced later in these instructions.
-A method for output of a message that is displayed when the user is done calculating coffee sales
The second class will contain:
-Two constant data fields:
-One for the price per pound, which is $5.99
-One for the tax rate, which is 7.25% (expressed as 0.0725)
-A no-argument constructor that creates a sale of one bag weighing one pound
-A constructor that accepts arguments from the first class for number of bags and the weight of each bag
-A constructor that accepts arguments from the first class for number of bags and the weight of each bag
-A method named getSale() that returns the sale amount before tax
-A method named getSaleTax() that returns the tax on the transaction
-A method named getTotalPrice() that returns the total sale price
-A method named getPrice() that returns the price per pound
-A method named getTaxRate() that returns the tax rate
-Calculations will be based on the following formulas:
-totalPrice = bagWeight * numberOfBags * pricePerLB
-totalPriceWithTax = totalPrice + (totalPrice * taxRate)
Here is a sample run for the program (user entries are underlined) Welcome to the Coffee Sales Tracker This program will calculate the amount due for your coffee sales transactions Are you ready to begin Y/N? Y Number of bags: 3 Weight per bag: 5 Today\'s date: Number of bags: Weight per bag: Price per pound: Sales tax: Sales sub-total: Total tax: August 8, 2014 3 5 pounds $5.99 125% $89.85 $6.51 Total Sale: Do you have another sale to ring up Y/N? N Thank you and have a great day. Goodbye $96.36Solution
import java.text.DateFormatSymbols;
import java.text.DecimalFormat;
import java.util.Scanner;
public class CoffeeSales {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
greet();
Sales S;
System.out.println(\"Are you ready to begin Y/N?\ \");
String s = in.nextLine();
while (s.equalsIgnoreCase(\"Y\")) {
int[] bagDetails = bagDetails();
S = new Sales(bagDetails[0], bagDetails[1]);
System.out.println(\"\ Do you have another sale to ring up Y/N?\ \");
s=in.nextLine();
}
System.out.println(\"Thank you and have a great day. Goodbye\");
}
public static void greet() {
System.out.println(\"Welcome to the coffee Sales Tracker\ \ \");
System.out.println(\"This program will calculate the amount due for your coffee sales transactions\ \");
}
public static int[] bagDetails() {
Scanner in = new Scanner(System.in);
int b[] = new int[2];
System.out.print(\"Number of bags :\\t\");
b[0] = in.nextInt();
System.out.print(\"Weight per bag :\\t\");
b[1] = in.nextInt();
return b;
}
}
class Sales {
static double pricePerPound = 5.99;
static double taxRate = 7.25;
public Sales(int bags, int weight) {
DecimalFormat dtime = new DecimalFormat(\".##\");
System.out.print(\"Today\'s date: \\t\\t\");
System.out.print(new DateFormatSymbols().getMonths()[new java.util.Date().getMonth()]);
System.out.print(\" \" + new java.util.Date().getDay() + \", \");
System.out.println(new java.util.Date().getYear() + 1900);
System.out.println(\"Number of bags: \\t\" + bags);
System.out.println(\"Weight per bag: \\t\" + weight);
System.out.println(\"Price per pound: \\t\" + getPrice());
System.out.println(\"Sales tax: \\t\\t\" + getTaxRate() + \"%\");
System.out.println(\"Sales sub-total: \\t\" + dtime.format(getSale(bags, weight)));
System.out.println(\"Total tax: \\t\\t\" + dtime.format(getSaleTax(bags, weight)));
System.out.println();
System.out.println(\"Total Sale: \\t\\t\" + dtime.format(getTotalPrice(bags, weight)));
}
public double getTaxRate() {
return taxRate;
}
public double getPrice() {
return pricePerPound;
}
public double getSale(int bags, int weight) {
return bags * weight * getPrice();
}
public double getSaleTax(int bags, int weight) {
return bags * weight * getPrice() * getTaxRate() / 100;
}
public double getTotalPrice(int bags, int weight) {
return getSale(bags, weight) + getSaleTax(bags, weight);
}
}


