REQUIREMENT: A store that sales a product that is in either model T224 or model
ID: 665549 • Letter: R
Question
REQUIREMENT:
A store that sales a product that is in either model T224 or model T334.
At the end of each year, the store has the report named Model_T_Sale_yyyy.txt where yyyy is 4 digits of the year, for example, Model_T_Sale_2014.txt or Model_T_Sale_2013.txt, etc. The format of input file should be:
For example: Year 2013 the store has file Model_T_Sale_2013.txt as follows:
Jan 2777 1.99 3223 2.19
Feb 2431 1.99 2612 2.19
Mar 2540 1.99 2729 2.19
Apr 2557 2.19 2892 2.29
May 2515 2.19 2249 2.29
Jun 2639 2.19 3190 2.29
Jul 2610 1.89 2839 2.09
Aug 2595 1.89 2875 2.09
Sep 2456 1.89 2828 2.09
Oct 2454 1.99 2803 2.19
Nov 2707 1.99 3295 2.19
Dec 2893 1.99 3522 2.19
For example: Year 2014 the store has file Model_T_Sale_2014.txt as follows:
Jan 3128 1.59 3421 1.79
Feb 3130 1.59 2822 1.79
Mar 3126 1.59 3210 1.79
Apr 3075 1.69 3143 1.79
May 3250 1.69 2538 1.79
Jun 3133 1.69 3458 1.79
Jul 3211 1.79 3135 1.89
Aug 2958 1.79 3620 1.89
Sep 2823 1.79 3714 1.89
Oct 2989 1.89 3689 1.99
Nov 3088 1.89 4163 1.99
Dec 2906 1.89 4314 1.99
Where each line has 5 information of month, T224 units sold, T224 unit price, T334 units sold, and T334 unit price.
These files are saved in the storage
This project asks you to provide the pseudo-code and the Java code for the application that processes two tasks:
Summary Sale in one year
Sale Comparison between two years
The application continue allows users to use the program until they want to exit
Task 1 Summary Sale in one year
For each year, calculate the money sold of each product type in each month and the total money sold of each product type in whole year then display in the following format on screen and also write to the output file named SaleSummary_yourLastName_yyyy.txt where yyyy is 4 digits of the year
For example: the output of the summary of sale in year 2013 and the output of the summary of sale in year 2014
Task 2
This task is to compare the sale on each product type between two years by calculate the different between number of product units sold between two years then calculate the % increase.
The result should be displayed on the screen and write to the output file named SaleComparison_yourLastName_ xxxx_and_yyyy.txt as follows:
HOW TO DO THE PROJECT
Create the project named SU15PROJECT_LastName then add the following classes
*Define a data type class named as SU15PROJECT_LastName_SaleInMonth.java that contains:
-data members: month as a string, T224_Units as an int, T224_uPrice as a double, T334_Units as an int, T334_uPrice as a double
-The constructor of the class MonthlySale will accept a String then split it into the information of month, T224_Units, T224_uPrice, T334_Units and T334_uPrice
-The assessor methods
-The method to calculate the money sold T224 in the month: T224_Units * T224_uPrice
-The method to calculate the money sold T334 in the month: T334_Units * T334_uPrice
-The method to calculate total money sold both models = money sold T224 + money sold T334
-The method to display on the screen the money sold in month on one line and in a column width of 15
-The method to write to the output file the money sold in month on one line and in a column width of 15. The format of the output in output file and on the screen is:
Month moneySoldT224 moneySoldT334
For example:
Jan 5526.23 7058.37
……
*Define a controlling class (a driver class) named SU15PROJECT_LastName_SaleReport.java with the method main() that do the following:
-Display the menu to allow users to choose the tasks:
1. Summary Of Sale In One Year
2. Compare Sales Between Two Years
-Read the selected task to determine which task is processed; only terminate the program when users select EXIT
TASK 1:
Create a method for the task 1 to do the following:
-Asks users to enter 4 digits for the year in yyyy format, then open the input file Model_T_Sale_yyyy.txt.
-When reading the input file, for each line, create the object of the class SU15PROJECT_LastName_SaleInMonth to pass the line in. Inside the constructor, the line will be splitted out into the information of month, T224_Units, T224_uPrice, T334_Units and T334_uPrice.
-Use the object to access information or call methods from the class MonthlySale_yourLastName to calculate or display output.
-Handle to display on the screen the output as requested
-Also, write the same output to the output file
-Using System.out.printf(“%15s”, aString) to display aString on the right of the column (width = 15)
-Using System.out.printf(“%15.2f”, aDecimalNumber) to display a decimal number with 2 decimal digits in column (width = 15)
-Using System.out.printf(%n) to go to next line
-Review to open file to read by using Scanner object
-Review to open file to write by using PrintWriter object
-Formula:
TOTAL: all the values in columns are added
Total sale in year: TOTAL of T224_SALE + TOTAL of T334_SALE
TASK2
Create a method for the task 2 to do the following:
-Asks user to enter 4 digits of 2 years to compare in the format “xxxx yyyy”
-Open 2 input files, Model_T_Sale_xxxx.txt and Model_T_Sale_yyyy.txt. (You should create these input files by typing the information to notepad and save with the above names)
Two input files should be read parallel line by line such that for each line in each file, create the object of SU15PROJECT_LastName_SaleInMonth to pass the line into the constructor. In the constructor of SU15PROJECT_LastName_SaleInMonth the line will be splitted out into 5 information (see the instruction of class SU15PROJECT_LastName_SaleInMonth above)
Use the object to access the information and calculate the different between number of T224 units and number of T334 units and also calculate the % increase. (see the output displayed for task 2 above)
-Columns T224_2013 and T224_2014 include the number of unit sold in year 2013 and 2014
-Column INCREASE: is calculated by: number of units sold in 2014 – number of units sold in 2013
INCREASE = T224_2014 – T224_2013 (number of units sold in 2014 – number of units sold in 2013)
-Column % INCREASE is calculated by: INCREASE / number of units sold in 2013
%INCREASE = (double) INCREASE / (double) T224_2013 (INCREASE / number of units sold in 2013)
-TOTAL:
In the second and third columns are the sum of number of units sold in 12 months the year
In the fourth column is the different of the total number of T334 units in the year and the total number
of T224 units in the year
In the fifth column is calculated as below:
% INCREASE = total of INCREASE / total of number of T224 units sold in the year (second column)
*The information of the table of SALE T334 COMPARISON is calculated as the same as for T224
-It is easy to print out the output as requested, when you read each line in each input file, calculate the INCREASE and %INCREASE then save month, the number of T224 units sold in month of the first year, the number of T224 units sold in the second year, montly INCREASE and monthly % INCREASE, you should save them into 5 arrays with the same size and pass these arrays with all the totals to a different method to print them out
Create a method that prints out the result in the requested format.
Explanation / Answer
SU15PROJECT_LastName_SaleInMonth.java
class MonthlySale {
private String month;
private int T224_units,T334_units;
private double T224_uPrice,T334_uPrice;
public MonthlySale(String sale){
Scanner s=new Scanner(sale).useDelimeter("\t");
month=s.next();
T224_units=s.nextInt();
T224_uPrice=s.nextDouble();
T334_units=s.nextInt();
T334_uPrice=s.nextDouble();
}
public String getMonth(){
return month;
}
public int getT224_unit(){
return T224_units;
}
public double getT224_uPrice(){
return T224_uPrice;
}
public int getT344_unit(){
return T334_units;
}
public double getT334_uPrice(){
return T334_uPrice;
}
public double moneySoldT224(){
return T224_units*T224_uPrice;
}
public double moneySoldT334(){
return T334_units*T334_uPrice;
}
public double totalMoneySold(){
return moneySoldT224()+moneySoldT334();
}
public void displayMoneySoldOnScreen(){
System.out.printf(“%15s”, month);
System.out.printf(“%15.2f”, moneySoldT224());
System.out.printf(“%15.2f”, moneySoldT334());
System.out.printf("%n");
}
public void outputMoneySoldToFile(int year){
PrintWriter out = new PrintWriter(new FileWriter("SaleSummary_yourLastName_"+year+".txt", true));
out.printf(“%15s”, month);
out.printf(“%15.2f”, moneySoldT224());
out.printf(“%15.2f”, moneySoldT334());
out.printf("%n");
}
}
SU15PROJECT_LastName_SaleReport.java
public class SU15PROJECT_LastName_SaleReport{
public static void main(String[] args){
int ch=0;
Scanner s=new Scaneer(System.in);
do{
System.out.println("1. Summary Of Sale In One Year");
System.out.println("2. Compare Sales Between Two Years");
System.out.println("3. EXIT");
System.out.println("Enter choice:");
ch=s.nextInt();
switch(ch){
case 1:
System.out.println("Enter year in yyyy format: ");
int year=s.nextInt();
File file=new File("Model_T_Sale_"+year+".txt");
Scanner fs=new Scanner(file);
while(fs.hasNext()){
MonthlySale ms=new MonthlySale(fs.nextLine());
ms.displayMoneySoldOnScreen();
ms.outputMoneySoldToFile(year);
}
break;
case 2:
System.out.println("Enter year 1 in yyyy format: ");
int year1=s.nextInt();
System.out.println("Enter year 2 in yyyy format: ");
int year2=s.nextInt();
File file1=new File("Model_T_Sale_"+year1+".txt");
Scanner fs1=new Scanner(file1);
File file2=new File("Model_T_Sale_"+year2+".txt");
Scanner fs2=new Scanner(file2);
while(fs1.hasNext()&&fs2.hasNext()){
MonthlySale ms1=new MonthlySale(fs1.nextLine());
MonthlySale ms2=new MonthlySale(fs2.nextLine());
System.out.printf(“%15.2f”,ms1.moneySoldT224());
System.out.printf(“%15.2f”,ms2.moneySoldT224());
double increase=ms2.moneySoldT224()-ms1.moneySoldT224();
System.out.printf(“%15.2f”,increase);
System.out.printf(“%15.2f”,(increase*100)/ms1.moneySoldT224());
}
break;
}
}while(ch!=3&&ch!=3);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.