COSC 5
COSC 1437 – LAB6
Note: in the instruction of the lab change “yourLastName” to your last name
TITLE
Array – Array Access
TIME TO COMPLETE
Two weeks for class 16 weeks – One week for class 8 weeks
HOW TO DO EACH PART
*Change Smith to your last name
*Change JAMES SMITH to your full name
*Change Mary Lane to the name of user
*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
PART 1: Create a word document FA2021_LAB6PART1_YourLastName.docx to answer questions
PART 2:
*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
*Step2:
-start editor (for example eclipse) create the project with the following project name:
FA2021_LAB6PART2_yourLastName (part 2)
-add data type class (file with extension .java)
Class: FA2021_CandidateDriverLicense_yourLastName (par2)
Class: FA2021_ComputerTestForDriverLicense_yourLastName (part2)
*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
LAB6 PART1 REQUIREMENT
Create a word document FA2020LAB6_PART1_yourLastName.docx then answer the following questions:
QUESTION 1
Look at the following array definition:
int [ ] numbers = { 44, 86, 30, 72, 142, 104};
What is the output of the following lines?
A.
System.out.println(numbers[2]);
B.
x = numbers[4] + 2*numbers[1];
System.out.println(x);
C.
x = ++numbers[3];
System.out.println(x);
QUESTION 2
public class InventoryItem {
String ItemID;
float unitPrice;
int unitCount;
//constructor
public InventoryItem()
{
itemID = “”;
unitPrice = 0.0f;
unitCount = 0;
}
//accessor method
//method mutator setUnitPrice
public void setItemID(String id)
{
itemID = id;
}
public void setUnitPrice(float newPrice)
{
unitPrice = newPrice;
]
//method mutator setUnitPrice
public void setUnitCount(int count)
{
unitCount = count;
}
public String toString()
{
return “ITEM: “ + itemID + “ – “ + unitPrice + “ – “ + itemCount;
}
}
The following statements in the main():
a. Which one is correct? If it is correct, what does the statement do on array items?
b. Which one is NOT correct? If it is not correct, provide the correct one.
public static void main(String[] args)
{
InventoryItem[] items = new InventoryItem[3];
for (int i= 0; i< items.length; i++)
Items[i] = new InventoryItem();
A.
items = new InventoryItem();
B.
items[0].setItemID(“A54321”);
items[0].setUnitPrice(12.5f);
items[0].setUnitCount(125);
C.
for (int i=0; i<items.length; i++)
{
items.setUnitCount[i] (85.5);
}
D.
for (int i=0; i<items.length; i++)
{
System.out.println(items[i]);
}
}
QUESTION 3
Suppose the file number.txt is already open to write
Use the following int array
int [ ] numbers = { 39, 58, 6, 112, 49, 88, 75, 33, 34, 50}
Write the code accesses on each element of the array numbers to store value of each element of the array numbers and write to above the output file number.txt in the following format and remember to close file.
Numbers 0 = 39
Numbers 1 = 58
Numbers 2 = 6
Numbers 3 = 112
Numbers 4 = 49
Numbers 5 = 88
Numbers 6 = 75
Numbers 7 = 33
Numbers 8 = 34
Numbers 9 = 50
QUESTION 4
A data type class ExerciseMonitor_yourLastName that hold the name (String) of person and the array (of float number size 7) that keeps 7 distances the person did exercise in one week
Provide the code of class ExerciseMonitor_yourLastName to have the list of data members (name, distances array), no-argument constructor, parameter constructor, the method toString() to display the following output string:
PERSON
Name = Mary Lane
Week Exercise Distance = 2.1, 2.5, 2.2, 2.4, 2.6, 2.2, 2.4
LAB6 PART2 REQUIREMENT
IF YOU DO NOT HAVE THE UML and PSEUDO-CODE, YOU HAVE TO READ THE BELOW REQUIREMENT THEN CREATE UML OF DATA TYPE CLASS AND WRITE THE PSEUDO-CODE BEFORE WRITING THE CODE
DATA TYPE CLASS
Class FA2021_CandidateDriverLicense_yourLastName
-This class hold data members: last name (String), first name (String), SSNumber(String), Driver’s license number (String), address(String), answerArray(char array size 25)
-constructors: the constructor initializes values for lastname, firstname, SSNumber, driverLicenseNumber, address, and initializes the char answerArray with size 25
* The driver license is generated by random number with 8 digits and test date is generated as current date
-method evaluateResult() accept answerArray and keyArray to determine the result and mark the failed questions list. If the candidate having 20 or more correct answers over 25 questions will be passed; otherwise he will be failed
-You can add more methods if you need
-method toString() prints the result in the following format.
FA2021_ComputerTestForDriverLicense_Smith.java
DRIVER TEST RESULT – JAMES SMITH
---------------------------------------------------------------------
Driver’s name: Lane, Mary
SS Number: 112233440
Address: 123 Plano Rd Dallas TX 75243
Driver’s License: 12345678
Test date: 10/15/2021
Result: ASSED
Missed Questions: 5, 12, 15
DRIVER CLASS
Class FA2021_ComputerTestForDriverLicense_yourLastName:
The local driver’s license office has asked you to write a program that grades the written portion of the driver’s license Rules and Signals Test.
The driver license test has 25 multiple choice questions. The key set is:
char key[] = { 'A', 'C', 'A', 'A', 'A', 'A', 'A', 'C', 'B', 'A', 'B', 'A', 'D', 'A', 'B', 'A', 'A', 'A', 'A', 'C', 'C', 'B', 'A', 'D', 'A' };
The program should declare the keySet as a char array constant.
First, the application displays messages to ask for the information of current candidate about last name, first name, SS number, address to create a Test account as an object of class DriverCandidate_yourLastName to pass all these information in.
When the candidate is ready, display the test instruction, questions and read answers
DRIVER LICENSE TEST
THERE ARE 25 MULTIPLE CHOICE QUESTIONS
YOU HAVE TO GET AT LEAST 20 CORRECT ANSWERS TO GET PASSED
------------------------------------------------------------
Question 1: _
The users answer the question by typing a letter A, B, C or D for each question. The program will read these answers and store to an answerArray.
If users type other keys than A, B, C or D; display message “Invalid key – Retype” and allow users to retype the answer of current question before moving on
The answerArray and the keySet should be sent to the object of class FA2021_CandidateDriverLicense_yourLastName
The result will be displayed on the screen in the requested format by call a method of class FA2021_CandidateDriverLicense_yourLastName
HOW TO TURN IN THE LAB
You should turn in the following files: (yourLastName should be your last name)
FA2021_LAB6PART1_YourLastName.docx (part 1)
UML Pseudo-code and the output pictures of part2
FA2021_CandidateDriverLicense_yourLastName.java
FA2021_ComputerTestForDriverLicense_yourLastName.java
FA2021_CandidateDriverLicense_yourLastName.class
FA2021_ComputerTestForDriverLicense_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 |
Readings & Assignments |
|
TURN IN ON TIME |
3 |
|
PART 1 |
|
|
Question1 |
1.5 |
|
Question2 |
2 |
|
Question3 |
1.5 |
|
Question4 |
2 |
|
PART2 |
|
|
UML diagram of data type class – pseudo-code of main and output pictures |
1 |
|
Submit correct files requested |
0.5 |
|
Data type class: data members |
0.5 |
|
No argument Constructor, parameter constructor – generate the random Driver license number |
1.5 |
|
Method to determine the result |
0.5 |
|
Method to evaluate the result passed or failed |
1 |
|
Method to printout the result |
2 |
|
The output of result in the required format |
2 |
|
Driver class |
|
|
Provide the key array |
1 |
|
Declare an array to hold the answer |
1 |
|
Read information of the candidate, read the answer |
2 |
|
Create the object |
1 |
|
Display the result by access method from data type class |
1 |
|
Write comments |
2 |
|
Compile correct - Output correct - comment |
3 |
|
Total |
30 |