Java Assignment

Order Description

TITLE Selection Structure (if, if..else, if..else ..if, nested if, swithc) – Representative Salary TIME TO COMPLETE Two weeks COURSE OBJECTIVES – LEARNING OUTCOME After finish the lab4 students should know: [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, toString, constructors, mutator, accessor methods. Etc [LO3] Declare objects of data type class Initialize object Use object to access data members of classInstructor: Liem Le – COSC1437 2 [LO5] Analyze problems and design algorithms using pseudo-code, flowcharts, and structured charts, UML [LO8] Apply selection structure to the programs: if, if..else, if..else..if, switch statements [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 LAB OBJECTIVES • Complete the lab on time (Time Management) • Write the pseudo-code • Create a new project, add source file to the project, compile and run the program without errors and qualified to the requirement • Display strings and numbers on the screen • Declare variables, assign values to int or string variables • Write the comment • Display output in columns • Generate the current date • Calculate the correct average of two numbers • Can write the code of a Data Type class including data member, constructors, mutator methods, accessor methods, method toString() • Can write in the selection structures with statements: if, if..else, if..elseif, nested if, switch SKILLS REQUIRED To do this lab, students have to know the following: (You can read topics from HINTS FOR LABS on eCampus to learn how to do) -Review concepts applied in the previous labs -Display output on the screen with the information layed out in columns and aligned to left or right. Using String.format() to format an output string For example: System.out.println(String.format(“-30s10.1f”, “This test is on the left”, 125.42)); System.out.println(String.format(“-30s10.1f”, “This test is on the left”, 4.23456)); The output will be: This test is on the left: 125.4 This test is on the left: 4.2 -There are two types of classes: data type class (for example: class Rectangle, class Student) and driver class that contains main() -How to create UML of a data type class: read the topic about UML from HINTS FOR LAB on eCampus -The template of a data type class: public class DataTypeClass { //list of variables that describe the object that is called as data members, fields, etc. //list of constructors //list of mutator methods //list of accessor methods //method toString //other methods depend on the needs of each projectInstructor: Liem Le – COSC1437 3 } How to write the constructors, mutator methods, accessor methods, method toStrings, see the topics from HINTS FOR LABS on eCampus ADDITIONAL CONCEPTS: -The syntax of selection structure: if, if..else, if..else if, nexted if and switch statement Using the selection statements: SYNTAX OF IF STATEMENT: if (condition) do this when condition is true SYNTAX OF if..else STATEMENT: if (condition) do this when condition is true else do this when condition is false SYNTAX OF if..else..if STATEMENT if (condition1) do this when condtion1 is true else if (condition2) do this when condition2 is true SYNTAX OF NESTED IF if (condtion1) { if (condition2) do this when condition1 is true and condition2 is true else do this when condition1 is true and condition2 is false } SWITCH STATEMENT int option = keyboard.nextInt();//READ VALUE OF option FROM THE KEYBOARD switch (option) case 1: //when option == 1 do all these statements for case 1, until break break; case 2: //when option == 2 do all these statements for case 2, until break break; . . . . } HOW TO DO EACH PART – PART 2 From now and on yourLastName will be changed to your last name *Step1: Read the requirement of each part; write the pseudo-code in a word document by listing the step by step what you suppose to do in main() and then save it with the name as Lab1_pseudoCode_yourLastName *Step2: -start editor (for example eClipse) create the project → project name: FA2019_LAB4PART2_yourLastName (part 2) -add a data type class Class: RepresentativeSalary_yourLastNameInstructor: Liem Le – COSC1437 4 -add a driver class (file with extension .java) that contain main() Class: PrintRepresentativeSalarySlip_yourLastName *Step3: read instruction in part 2, create the UML of data type class and based on the requirements write the pseudo-code of main() Then follow UML to write the code of data type class Follow step by step in the pseudo-code to write the code of main() in the driver class *Step:4 compile and run the program *Step5: debug if there is any errors to complete the program REQUIREMENT LAB4 PART1 Open a Word document then type the answers of the following questions: QUESTION 1: Suppose we have the following lines of the code: int main() { float float1, float2; cout << “Enter a decimal number: “; cin >> float1; . . . . system(“pause”); return 0; } Add to above main() an if statement that assigns 1.91 to float2 when float1 is less than 19.1 QUESTION 2: Suppose we have the following lines of the code: int main() { ffloat float1, float2; cout << “Enter a decimal number: “; cin >> float1; . . . . . system(“pause”); return 0; } Add to above main() an if..else statement that assigns 11.9 to float2 when float1 is less than or equal to 19.9; otherwise assign 23.8 QUESTION 3: Using the following chart, write an if-else-if statement to calculate the commission amount depending on the value in sale amount as below: Sale amount Commission Rate Less than or equal $8,000 2.59% Greater $8,000 to $12,000 3.99% Over $12,000 4.99%Instructor: Liem Le – COSC1437 5 QUESTION 4: Suppose we have the following lines of code: int main() { int integer1, integer2; cout << “Enter the first integer: “; cin >> integer1; cout << “Enter the second integer: “; cin >> integer2; . . . . . system(“pause”); return 0; } Add to above main() the nested if statement that performs the following: If integer1 is less than 1000 and integer2 is less than or equal to 2000 and if integer1 is greater than integer2 then display the “integer1 and integer2 is less than 1000 and integer2 is less than value1” QUESTION 5: Convert following if-else-if statement into a switch statement if (task == 1 ) { System.out.println(“You selected task 1 ”); } else if (task == 2) { System.out.println(“You selected task 2.”); } else if (task == 3 || task == 4 ) { System.out.println(“You selected task 3 or task 4.”); } else { System.out.println(“Invalid number – Select task in the range 1 to 4.”); } LAB4 PART2 IF YOU DO NOT HAVE UML OF DATA TYPE CLASS AND THE PSEUDO-CODE OF main(), YOU HAVE TO READ THE BELOW REQUIREMENT THEN CREATE THE UML AND WRITE THE PSEUDO-CODE BEFORE WRITING THE CODE Using Java, provide the application for the company Kitchen Products to calculate the salary of the Sale Representative who is working at the company. The salary of Sale Representative based on the number of appointments with customers and the sale amount he makes DATA TYPYE CLASS Class RepresentativeSalary_yourLastName maintains the following informaiton of a Representative: name of the representative, employee id, number of appointments made and sale amount The salary is calculated by the following formula: salary = $20 (per appointment) * number of appointments made + commission amount + bonus The commission amount and bonus are calculated based on the rule of the following table:Instructor: Liem Le – COSC1437 6 Commission Bonus If the representative only has appointments with customers without sale amount 0 0 If the representive has appointments and also makes total sale amount that is less than or equal $10,000 in the month 2.25% On the sale 0 With sale is greater than $10,000 but less than $15,000 in month 3.25% On the sale 2.75% On any sale beyond $10,000 With sale is equal or greater than $15,000 in month 5.25% On the sale 2.75% On any sale beyond $10,000 Print out the salary split as below: RepresentativeSalary_Smith.java .................................................. COMPANY KITCHEN PRODUCTS 123 Buckingham Dallas, TX 75243 Sale Prepresentative: Mary Lane Employee id: 12345 Pay Date: 09/30/2019 Work count: 56 Sale aamount: 15800.00 .................................................. Base Salary: 1120.00 Commission: 829.50 Bonus: 159.50 Salary: 2109.00 .................................................. OR RepresentativeSalary_Smith.java .................................................. COMPANY KITCHEN PRODUCTS 123 Buckingham Dallas, TX 75243 Sale Prepresentative: Mary Lane Employee id: 12345 Pay Date: 09/30/2019 Work count: 72 Sale aamount: 12600.00 .................................................. Base Salary: 1440.00 Commission: 409.50 Bonus: 71.50 Salary: 1921.00 .................................................. OR RepresentativeSalary_Smith.java .................................................. COMPANY KITCHEN PRODUCTS 123 Buckingham Dallas, TX 75243 Sale Prepresentative: Mary Lane Employee id: 12345Instructor: Liem Le – COSC1437 7 Pay Date: 09/30/2019 Work count: 86 Sale aamount: 8200.00 .................................................. Base Salary: 1720.00 Commission: 184.50 Bonus: 0.00 Salary: 1904.50 .................................................. REQUIREMENT -Change Smith to your last name -Change Mary Lane to the name of Representative entered from the keyboard -The file name should be placed as the first comment line at the top of the file HOW TO TURN IN THE LAB The list of answers on Part 1 UML pseudocode and pictures of the output windows of part2 RepresentativeSalary_yourLastName.java PrintRepresentativeSalarySlip_yourLastane.java RepresentativeSalary_yourLastName.class PrintRepresentativeSalarySlip_yourLastane.class HOW TO GRADE THE LAB Turn in on time 3 Question 1 1 Question 2 1 Question 3 2 Question 4 2 Question 5 2 PART2 Submit all files requested 1 Psuedo-code(main) – UML (data type class) – output pictures 2 Data type class Define data members 1 No argument constructor – parameter constructor 2 Method to calculate base paid 1 Method to calculate the commission amount 1 Method to calculate the bonus 1 Method to calculate the salary 1 Method to toString to return the output string of the salary slip as requested format 2 Driver class Read input 1 Create the object of data type class 1 Display the salary slip by calling the method toString() of data type class 1 Write the comment 1 Compile success – qualified all the requirements 3 Total 30