project programming 2
COSC 1437 – PROJECT
Note: in the instruction of the lab change “yourLastName” to your last name
Contents TITLE 1 TIME TO COMPLETE 1 COURSE OBJECTIVES – LEARNING OUTCOME 1 LAB OBJECTIVES 2 SKILLS REQUIRED 3 HOW TO DO the project 4 PROJECT INSTRUCTION 5 DATA TYPE CLASS 5 DRIVER CLASS 6 HOW TO TURN IN THE LAB 8 HOW TO GRADE THE LAB 8
TITLE
File access –Year Sale Report
TIME TO COMPLETE
Five weeks
COURSE OBJECTIVES – LEARNING OUTCOME
[LO1]
-Declare variables, initialize values of primitive data types
-Apply math operators on numeric variables
-Write a java program with basic with comments and documentation
[LO2]
-Define a data type class including attributes and methods
-Set access modifiers as private, protected, default or public to data members of the data type class such that the data type class encapsulated
-method toString, constructors, mutator, accessor methods. etc.
[LO3]
-Declare objects of data type classes
-Initialize object
-Use object to access data members of class
[LO4]
-Set access modifier for data members of data type classes Inherit from super class: constructor, methods
[LO5]
Analyze problems and design algorithms using pseudocode, flowcharts, and structured charts, UML
[LO6]
-Create and access void methods and returned-value methods in classes
-Create returned reference method
[LO7]
-Declare arrays, pass array as arguments to methods, returned array from methods create array of objects. Apply searching methods in arrays: sequential search, Sort an array: selection sort and binary search sort
[LO8]
-Apply selection structure to the programs: if, if..else, if..else..if, switch statements
-Apply repetition structure to the programs: for, while, do..while loop
[LO9]
-Declare objects of Wrapper classes and use their function to convert data types
-Declare objects of StringBuilder classes and Declare objects of StringTokenizer class to split strings
[LO10]
-String to access their functions to split, concatenate, manipulate the output
[LO11]
-Can read input from the keyboard and from input files
-Can write output to the screen and to the output files
-display messages by using dialog box
[LO12]
-Using some basic Exception class to handle exception: IOException,, FileNotFoundException Using try.catch.. finally block
LAB OBJECTIVES
After finishing the project, students should know:
-Complete the lab on time (Time Management)
1.
-Write the pseudo-code, create UML of data type classes
-Create a new project, add source file to the project, compile and run the program without errors and qualified to the requirement
-Write the comment
2.
-can write the code of a data type class including data members, constructors, mutator methods, accessor methods, toString
3.
-can create an object of a data type class
-can access methods of a data type class by using an object
4.
-can create correctly if, if..else or switch statements
-can user the loops, can handle the loop to redisplay the menu
5.
-Create and access user-defined functions, such as, void methods and returned-value methods
-Create function with reference parameters, default parameters
6.
-open files to read, to write or to append
SKILLS REQUIRED
-Review all concepts and syntax that are studied and practiced in labs from the course. The project focuses on the following:
1.
-Manage to redisplay the menu until users select exit
do
{
Display the menu
1. Task1
2. Task2
….
0. Exit
Read the task users enter from the keyboard
switch (task)
{
case 1:
statement1;
break;
case 2:
statement2;
break;
default:
statement3;
}
} while (task != 0);
2.
How to declare a constant
For example
static final float CONSTANT_VARIABLE = 3.99f;
3.
-How to open a file to read, write, append
TO READ
File file = new File(filename);
Scanner sc = new Scanner(file); //open file
while (sc.hasNextLine()) //the loop to read line by line
System.out.println(sc.nextLine()); //read one line and display
}
sc.close; //close file
TO WRITE and TO APPEND - need throws IOException
FileWriter fileWriter = new FileWriter(filename, true);//ONLY true when append
PrintWriter printWriter = new PrintWriter(fileWriter); //open file
printWriter.println("Some String");//write one line to the file
printWriter.printf("Product name: %s and its price: %d $", "iPhone", 1000); //write one line to file with the format
printWriter.close();//close file
The result in file:
Some String
Product name is iPhone and its price are 1000$
4.
-How to convert a number to a string
String str1 = Integer.toString(123);
String str2 = Float.toString(123.45f);
5.
How to create the array of objects.
How to access each element of the array to read one object
6.
How to use object of data type to access methods in the data type class
HOW TO DO the project
*Step1: Read the requirement of each part, recognize the objects the requirement talk about to make decision which data type classes we need for the project. Create the UML of each data type class
Also, read the requirement to write the pseudo-code or draw the flowchart to determine what step by step you suppose to do in main() of driver class such that the program is qualified to the requirement
The UML of data type classes, pseudo-code or flowchart and output pictures should be saved in a word document named SU2020_PROJECT_yourLastName.docx
*Step2:
-start editor (for example eclipse) create the project with the following project name:
SU2020_PROJECT_yourLastName
-add data type class (file with extension .java)
Class SU2020Product_yourLastName
Driver class: SaleSU20Product_yourLastName
*Step3: Based on the UML of data type class, write the code of data type class
Based on the pseudo-code or flowchart, write the code of main() in driver class
*Step:4 compile and run the program
*Step5: debug if there are any errors to complete the program
PROJECT INSTRUCTION
The company SU2020 sales two product models, SU20PD1 and SU20PD2.
The company asks for the application that helps the company to do some tasks that list in the following menu:
File YearSaleReport_White.java
SU20Product Company – McKINLEY WHITE
1. Month Sale Report.
2. Year Sale Report.
3. Compare Two Years Report.
0. Exit
After finishing one task, the program should redisplay the menu to allow users to continue using the program to select other task until users select exit to terminate the program
You have to use Object Oriented Programming by providing the data type class and the driver class.
You have to use an array of the objects of data type and at least 3 user-defined functions in the driver class
DATA TYPE CLASS
Class SU2020Product_yourLastName holds information month(String in 3 characters, for example Jan), SU20PD1_Units, SU20PD2_Units, SU20PD1_price(float), SU20PD2_price (float), no-argument constructor, parameterized constructor, method getCost_SU20PD1(), method getCost_SU20PD2(), method toString(), method toStringInFile()
Method getCost_SU20PD1(): will return the SU20PD1_cost (float) of product SU20PD1 by using the formula:
SU20PD1_cost = SU20PD1_units * SU20PD1_price
Method getCost_SU20PD2(): will return the SU20PD2_cost (float) of product SU20PD2 by using the formula:
SU20PD2_cost = SU20PD2_units * SU20PD2_price
Method toString() will return the output String to display on the screen in the following format, for example:
File SaleSU20Product_White
SU2020Product – McKINLEY WHITE
Month Report: June 2020
----------------------------------------------------
SU20PD1 ($5.19) 4639 24076.41
SU20PD2 ($5.29) 5190 27455.10
----------------------------------------------------
Subtotal: 51531.51
Tax (8.25%) 4251.35
----------------------------------------------------
Total: 55782.86
Method toStringinFile() will return the output String to write one line in the output file:
month year SU20PD1_units SU20PD1_price SU20PD2_units SU20PD2_price
for example:
Jun 2020 2639 5.19 3190 5.29
DRIVER CLASS: SU20PD_YearSaleReport_yourLastName.java
Display the requested menu then allow users to select one task from the menu.
Task1: Month Sale Report
The information of month sale should be read from the keyboard about: the month (String), the year (in 4 digits-String), number of units of the first model SU20PD1 sold in month (int) and the price of each unit (float), number of units model SU20PD2 (int) and the price of each unit (float). Create the object of the data type class U2020Product_yourLastName to pass the information of month, number of units with price of the model SU20PD1 and number of units with the price of the model SU20PD2 in to the object. Then display the Month report on the screen and write one line to store the sale of month to the output file named xxxx_YearSale.txt by accessing the method toString() and method toStringInFile() from data type class
Task2: Year Sale Report
Ask users to type the input file of year sale and read the file name. For example 2019_YearSale.txt
Open the input file with the entered file name. If file exists, the read each line of the file as a String,
For each line:
-the split information into month, number of units of model SU20PD1, unit price of model SU20PD1, number of units of model SU20PD2 and unit price of model SU20DP2 to create the object of data type class SU2020Product_yourLastName.
-place the object to one element of one array size 12
After reading whole file, all the information from the file will be kept in 12 elements of the array.
The Process Year Sale Report will be based on reading this array, you can calculate by accessing the methods:
- getCost_SU20PD1() each month on each line, calculate the total of sale amount of model SU20PD1 in whole year and calculate Total number of SU20PD1 units in whole year
- getCost_SU20PD2() each month on each line, calculate the total of sale amount of model SU20PD2 in whole year and calculate Total number of SU20PD2 units in whole year
-print year sale report in the following format:
File SaleSU20Product_White
SU2020Product – McKINLEY WHITE
Year Report: 2019
------------------------------------------------
SU20PD1 52817 250669.13
SU20PD1 58227 283387.44
------------------------------------------------
Subtotal: 534056.56
Tax (8.25%) 44059.67
----------------------------------------------------
Total: 578116.23
3. Compare Two Years Report
Read from the keyboard two file names of two year sale reports of two years that users want to compare.
If one of these two files do not exist then ending for this task
If both files exist, open these files to read parallelly. Each file has 12 lines of the sale information of 12 months in the year.
For each line of the first file, split information into month, year, SU20PD1_number, SU20PD1_price, SU20PD2_number, SU20PD2_price to create the object of SU2020Product, place the object in the element of the array1.
For each line of the second file, split information into month, year, SU20PD1_number, SU20PD1_price, SU20PD2_number, SU20PD2_price to create the object of SU2020Product, place the object in the element of the array2:
The process to compare two years sale includes calculating the following from two above arrays, array1 and array2
For each element of array1 and each element of array2 at the same index:
-The different between numbers of the product SU20PD1 in the later year to the number of the product SU20PD1 in the previous year. For example:
DifferentOfProductSU20PD1 = numberOfSU20PD1_soldIn2019 - numberOfSU20PD1_soldIn2018
DifferentOfProductSU20PD2 = numberOfSU20PD2_soldIn2019 - numberOfSU20PD2_soldIn2018
%IncreasingOfSU20PD1 = (DifferentOfProductSU20PD1 / numberOfSU20PD1_soldIn2018)*100
%IncreasingOfSU20PD2 = (DifferentOfProductSU20PD2 / numberOfSU20PD2_soldIn2018)*100
Create one output line with 6 information and place to one element of the array line1 of size 12 in the following format:
Month Year numberOfSU20PD1_soldIn2019 numberOfSU20PD1_soldIn2018 DifferentOfProductSU20PD1 %IncreasingOfSU20PD1
Create one output line with 6 information and place to one element of the array line2 of size 12 in the following format:
Month Year numberOfSU20PD2_soldIn2019 numberOfSU20PD2_soldIn2018 DifferentOfProductSU20PD2 %IncreasingOfSU20PD2
Display the output each element of the array line1 as one line in the following report after displaying the top of the report as below:
File SaleSU20Product_White.java
SU2020Product – McKINLEY WHITE
COMPARE SALE REPORT OF PRODUCT SU20PD1: 2019 and 2018
-------------------------------------------------------
MONTH YEAR 2019 YEAR 2018 DIFFERENT PERCENTAGE
-------------------------------------------------------
Jan 4128 3725 403 10.82%
Feb 4130 3723 407 10.93%
Mar 4126 3682 444 12.06%
Apr 4075 3642 433 11.89%
May 4250 3812 438 11.49%
Jun 4133 3742 391 10.45%
Jul 4211 3457 754 21.81%
Aug 4958 4237 721 17.02%
Sep 4823 4123 700 16.98%
Oct 4989 4218 771 18.28%
Nov 4088 3654 434 11.88%
Dec 4906 4226 680 16.09%
Display the output each element of the array line1 as one line in the following report after displaying the top of the report as below:
File SaleSU20Product_White.java
SU2020Product – McKINLEY WHITE
COMPARE SALE REPORT OF PRODUCT SU20PD2: 2019 and 2019
-------------------------------------------------------
MONTH YEAR 2019 YEAR 2018 DIFFERENT PERCENTAGE
-------------------------------------------------------
Jan 4421 4005 416 10.39%
Feb 4822 4415 407 9.22%
Mar 5210 4612 598 12.97%
Apr 5143 4725 418 8.85%
May 4538 4145 393 9.48%
Jun 4458 4007 451 11.26%
Jul 5135 4612 523 11.34%
Aug 4620 4228 392 9.27%
Sep 4714 4310 404 9.37%
Oct 4689 4125 564 13.67%
Nov 5163 4526 637 14.07%
Dec 5314 4735 579 12.23%
REQUIREMENT:
*Change White to your last name
*Change McKINLEY WHITE to your full name
*Write the file name as the first comment line at the top of program
*Write the comments to explain each part of the program
*After running your program, get the picture of the output window from your program with your name on to paste at the bottom of the pseudo-code to turn in
HOW TO TURN IN THE LAB
You should turn in the following files: (yourLastName should be your last name)
SU2020PROJECT _YourLastName.docx (for UML, Pseudo-code and the output pictures)
SU2020Product_yourLastName.java
SaleSU20Product_yourLastName.java
SU2020Product_yourLastName.class
SaleSU20Product_yourLastName.class
IF YOU GET ANY PROBLEM TO SUBMIT FILEs .class YOU CAN COMPRESS ALL PROJECT INTO ONE FILE .zip or .rar TO UPLOAD TO eCampus
HOW TO GRADE THE LAB
|
Topic |
Scores |
|
turn in on time |
8 |
|
Submit all files requested with correct names |
3 |
|
compile success with all the requirements |
10 |
|
UML Pseudo-code or flowchart and output pictures |
6 |
|
Write the comment in the program, name file is at top |
5 |
|
Using at least 3 user-defined functions and call them in main() |
6 |
|
Manage main menu to re-display after finishing each task and terminate when users select exit |
2 |
|
TASK1 Month Sale Report: read input from the keyboard, calculate, print the report on screen, write one line to file, close files |
10 |
|
TASK2 Year Sale Report: read input file, store in array, read each element of the array, calculate, print the year report, close files |
12 |
|
TASK3 Compare Year Sale report: read 2 files, create object, place objects to 2 arrays, Read 2 arrays, calculate, print 2 reports for 2 models, , close files |
10 |
|
Output as requested |
8 |
|
PROJECT SCORES |
80 POINTS |