Java programming

profileSteven Young
java1_project_salecomparisonapplication_fall_20142-1.docx

This is the individual project that helps you to review what we have learned from the course. Start the project early as you can and enjoy it.

OBJECTIVES

Doing this project, students will have the chances to practice with the following concepts; therefore, you should review them when you are working on the project:

· Repetition structures: using for, while, or do..while loop

· Selection structure: using if, if else, or switch statement

· Read data from keyboard

· Read data from the file

· Write data to the file

· Using DecimalFormat to format the decimal numbers

· Using user-defined functions

· Review how to write the code of data type: data members, constructor, mutator methods, accessor methods and toString method

· How to declare an object of a class in main and how to access member of class by using the object

· how to declare an array and how to initial values of the array elements and how to access each element of an array

REQUIREMENT:

Provide the pseudo-code and the Java code for the application named SaleComparisonApplication_yourLastName.java

Suppose a store sales a product that is in either model X310 or model X410.

At the end of each year, the store has the report named Model_X_Sale_yyyy.txt where yyyy is 4 digits of the year, for example, Model_X_Sale_2014.txtor Model_X_Sale_2013.txt, etc. The format of input file should be:

For example: Year 2013 the store has file Model_X_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_X_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.992

Nov 3088 1.89 4163 1.99

Dec 2906 1.89 4314 1.99

Where each line has 5 information: month, X310 units sold, X310 unit price, X410 units sold, and X410 unit price.

You should create these two input file with the name as above and save in the working folder

The application SaleComparisonApplication_yourLastName allows the store managers to process two tasks:

1. Summary Sale in one year

2. Sale Comparison between two years

The application should allow store managers to continue using until they want to exit

Task 1Summary 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

Define a data type class named as MonthlySale_yourLastName.java that includes:

-data members:month as a string, X310_Units as an int, X310_uPrice as a double, X410_Units as an int, X410_uPrice as a double

-The constructor of the class MonthlySale will accept a String then split it into the information of month, X310_Units, X310_uPrice, X410_Units and X410_uPrice

-The assessor methods

-The method to calculate the money sold X310 in the month: X310_Units * X310_uPrice

-The method to calculate the money sold X410 in the month: X410_Units * X410_uPrice

-The method to calculate total money sold both models, X310 and X410 = money sold X310 + money sold X410

-The method to display on the screen the money sold in month in one line in a column width of 15 as follows:

-The method to write to the output file the money sold in month in one line in a column width of 15 as follows:

moneySoldX310 moneySoldX410

For example:

5526.23 7058.37

Define a controlling class named SaleComparisonApplication_yourLastName.javawith the method main() that do the following:

-Display the menu to allow users to choose the tasks:

1. Summary Sale in one year

2. Sale Comparison 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 to do the following:

-Asks users to enter 4 digits for the year in yyyy format, then open the input file Model_X_Sale_yyyy.txt.

-When reading the input file, for each line, create the object of the class MonthlySale to pass the line in. Inside the constructor, the line will be splitted out into the information of month, X310_Units, X310_uPrice, X410_Units and X410_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

-In the output

- the column X310 includes the monthly sale the product X310

X310 SALE = X310 units sold * X310 unit price

-the column X410 includes the monthly sales the product X410

X410 SALE = X410 units sold * X410 unit price

TOTAL is added in columns

Total sale in year: is added total sale of two models

TASK2

Create a method to do the following:

-Asks user to enter 4 digits of 2 years to compare in the format “xxxxyyyy”

-Open 2 input files, Model_X_Sale_xxxx.txt and Model_X_Sale_yyyy.txt.

Two input files should be read parallel line by line such that for each line in each file, create the object of MonthlySale_yourLastName to pass the line into the constructor. In the constructor of MonthlySale_yourLastName the line will be splitted out into 5 information (see the instruction of class MonthlySale_yourLastName above)

Use the object to access the information to calculate the different between number of X310 units and number of X410 units and also calculate the % increase. (see the output displayed for task 2 above)

-Columns X310_2013 and X310_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 = X310_2014 – X310_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) X310_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 X410 units in the year and the total number

of X310 units in the year

In the fifth column is calculated as below:

% INCREASE = total of INCREASE / total of number of X310 units sold in the year (second column)

*The information of the table of SALE X410 COMPARISON is calculated as the same as for X310

-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 X310 units sold in month of the first year, the number of X310 units sold in the second year, montlyINCREASE 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 accepts the above arrays and all the totals as parameters and prints out the result in the requested format.

HOW TO TURN IN

Submit the source code files:

1. MonthlySale_yourLastName.java

2. SaleComparisonApplication_yourLastName.java

3. Sale_Summary_xxxx.txt

4. Sale_Comparison_xxxx_and_yyyy.txt

5. Project_yourLastName.doc (pseudo-code)

HOW TO GRADE THE PROJECT

Class names: MonthlySale_yourLastName.java, SaleComparisonApplication_yourLastName.java, , SaleSummary_yourLastName_xxxx.txt, SaleComparison_yourLastName_xxxx_and_yyyy.txt

2

Turn in on time

10

Compile success – qualify the requirements

10

Pseudo-code or flowchart in the file named project_yourLastName.doc

5

Write the Comment in each class

3

Class MonthlySale_yourLastName

5 data members

2

Constructor pass a String as parameter, split information and assign to data members

4

All assessor methods

2

Method to calculate the money sold X310 in month, the money sold X410 in month

3

Method to calculate total money sold both models

3

Method to display information sold in month on one line

3

Class SaleComparisonApplication_yourLastName

Menu - handle to allow users to continue selecting tasks until they choose exit

3

Read input for year in both tasks

2

Open input files, open output files, close files in both tasks

4

Loop to read input files in both tasks

3

Read one line, create the object of MonthlySale in both tasks

3

TASK1: calculate result correct

3

Display the result on screen and in output file as requested format

3

TASK2:

Calculate the INCREASE correct

3

Calcualte the % INCREASE correct

3

Calculate TOTAL correct

3

Write result to the screen and to output file as requested format

3

Project Scores

80