Rlab6

profilemike05
JAVA2_Instruction_FA2019_LAB6_Accessibility.pdf

COSC 2436 – LAB6

Contents TITLE .............................................................................................................................................................. 1

TIME TO COMPLETE ...................................................................................................................................... 1

COURSE OBJECTIVES – LEARNING OUTCOME .............................................................................................. 1

LAB OBJECTIVES ............................................................................................................................................ 2

SKILLS REQUIRED........................................................................................................................................... 2

HOW TO DO EACH PART ............................................................................................................................... 2

REQUIREMENT lab5 ...................................................................................................................................... 3

HOW TO TURN IN THE LAB ........................................................................................................................... 4

HOW TO GRADE THE LAB .............................................................................................................................. 6

Note: in the instruction of the lab change “yourLastName” to your last name. In the example, change

Smith to your last name, change James Smith to your full name, change Mary Lane to the name that

users type in from the keyboard (if these words are in this instruction)

TITLE

Hashed Data Structure

TIME TO COMPLETE

Two week

COURSE OBJECTIVES – LEARNING OUTCOME

[LO1] Provide UML class diagram and the code of data type classes Provide the pseudo-code or flowchart based on the requirement of a project before writing the code of the driver class. Also, can access data members of data type classes Describe and implement the inheritance relationship between super class and child classes. Can use abstract classes or interface and apply polymorphism to the real life problem project [LO5] Declare and implement Hashed structures with its operations [LO11] How to evaluate the performance of each operation algorithm of data structure type based on BigO and Density

LAB OBJECTIVES

-Complete the lab on time (Time Management)

-Can write the pseudo-code -Can provide UML of data type class -Can write comments in the program -Can write the code of data type classes including data members, no-argument constructor, parameter constructors, mutator methods, assessor methods, method toString and other methods -Can apply Inheritance concept to write the code of child classes that inherits data members, constructors and other methods from parent class -Can apply Polymorphism: using object of the parent class to point to object of child classes -Can organize the program with selection control structure: if..else, switch, do..while -Can create object and can access members of data type class -Can create the data structure type of LQHashed and java Hashtable -Can implement insert, fetch, delete, update of Hashed data structure

SKILLS REQUIRED

To to this lab, students should review all the concepts required from the previous lab and add the following skills: -Learn how to create the data structure of type LQHashed structure and java Hashtable -Learn the algorithms of the operations, insert, fetch, delete, update of type LQHashed structures and Hashtable -Learn how to show all the nodes in the LQHashed structure -Learn how to declare and use Iterator to insert, fetch or delete, update in the Hashtable structure

HOW TO DO EACH PART

From now and on yourLastName will be changed to your last name Smith: change to your last name James Smith: change to your full name *Step1: -Create UML of data type classes: reuse from lab3 for class Account, CheckingAccount and SavingAccount -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 Lab6_pseudoCode_yourLastName *Step2: -start editor eClipse, create the project → project name: FA2019_LAB6_yourLastName -add data type classes (You can use these classes from lab3) Student_yourLastName Class -Add data structure class: LQHashed_yourLastName Import java Hashtable -Add the driver class FA2019_HashedStructureDemo_yourLastName *Step3: Write the code of classes: Re-use the code of data type classes from previous labs Write the code of LQHashed_yourLastName: using the code on the page 280 – 283 for your reference Use the code on page 293 for your reference on java Hashtable To showAll nodes in java Hashtable do as following: Hashtable table = new Hashtable();

Using put to insert the node to table: table.put(keyfield, node); SHOW ALL: Enumeration keyset = table.keys(); While (keyset.hasMoreElements()) { String studentId = keyset.nextElement(); System.out.println(table.get(studentId)); //get will fetch the student by studentId } Based on the pseudo-code write the java code of main() of the driver class

FA2019_HashedStructureDemo_yourLastName *Step4: compile and run the program *Step5: debug if there is any errors to complete the program

REQUIREMENT LAB5

Download the file students.xlsx from eCampus Open file student.xlxs on the screen then SAVE AS with the extension .CSV (commas delimeter) Save the file with the same name students.csv This file is similar excel file but each row include the information in cells separate by comma For example: 1212121, Bellamy, Kevin, SP2016-COSC1301, A DATA TYPE CLASSES: class Student_yourLastName and class Class Create the class Student_yourLastName -data members: student id (String, generate random number 7 digits), last name (String), first name(String), and aClass (Class) -no argument constructor, parameter consructors -method to generate random number with 7 digits -method toString to create a string output of one student on the screen in the followin format: STUDENT Student ID: 1234567

Student: Mary Lane

Classes:

FA20177-MATH1325 - A

-method toFile to create a string output of one student to the file: 1234567, Smith, Mary, FA20177-MATH1325, A

Create the class Class

-data members: class name (String), letter grade (char) The value of grade can be letter A, B, C, D or F – The grade X means the class has registered; not complete yet -no argument constructor, parameter consructors -Method toString() to create a String output of class information in the following format:

FA20177-MATH1325 - A

Create Data structure class Using the code on the page 280 – 283 from the text book for your reference to produce the class LQHashed_yourLastName. DRIVER CLASS Provide the pseudo-code or flowchart then write the code for the application FA2019_RestrictedStructureDemo_yourLastName that first display the following menu to select types of data structure: FA2019_HashedStructureDemo_Smith.java MAIN MENU LINKED LIST STRUCTURE – JAMES SMITH

1. LQHashed Structure 2. Java Hashtable

0. Exit Read one type of data structure to work For each type do the following: 1.CREATE SELECTED DATA STRUCTURE 2.READ INPUT FILE, CREATE NODES, INSERT TO DATA STRUCTURE

-Display the message and read the file name of the input file. For example: “students.xsv” -Open file to read -create the loop to read file until end of file. For each line *Read one line as a string *Split information of one line with delimeter as comma, then assign thesee information to: student id, last name, first name, class name, letter grade For example:

1234567, Smith, Mary, FA20177-MATH1325, A

*Create one object aClass of Class by passing class name and letter grade in *Then create one object aStudent of class Student_yourLastName by passing student id, last name, first name, aClass *Insertudent to the selected data structure -After the last line, close file

3.DISPLAY THE MENU HASHED DATA STRUCTURE – JAMES SMITH

1. Insert Customer 2. Fetch 3. Verify Encapsulation 4. Update 5. Delete 6. Show all 0. Exit

INSERT -Allow users to enter the information of one student from the keyboard: last name, first name, class name -Create an object aClass of Class by passing class name and letter grade in. For new student with new class, the letter grade is ‘X’ (MEAN: Not Complete)

-Create the object of Student_yourLastname by passing last name, first name, aClass. The student id will be generated as a random number inside the constructor then insert to the data structure FETCH -Allow users to type student id then search in the data structure for looking for the student. If it is found, print out the information of student on the screen otherwise display the message: “The stduent cannot be found” ENCAPSULATION -Allow users to type a student id from the keyboard, id. -Search in the data structure. If the student is found named it as temp. -Display message to ask for new last name. Modify the last name of the student temp -Fetch from the selected data structure a student with above id; store to fetchedStudent -Compare the last name of temp and fetchedStudent. If the last names are different, display messge: “LQHashed is encapsulated” OR “Hashtable is encapsulated” If they are the same: display message “LQHashed is not encapsulated” OR “Hashtable is not encapsulated” UPDATE Display the message to ask users to enter the student id. Using the student id to fetch the student from the selected data structure to temp3. Asking users to enter one new last name from the keyboard then change the this new information of temp3 Update the data structure with the temp3 with student id as the same student id of temp3. Display the message to see if update successfully or not DELETE Display the message to ask users to enter the student id. Remove the node with the entered id Display the message to see if delete successfully or not SHOW ALL Display all the students who are currently stored in the data structure Exit program When users choose to exit the program, before terminating the program do the following: -open the file students.csv (the same file name provided at the beginning) to write (NOT APPEND). Then write all the nodes stored in the data structure to the file student.csv in the same format on one line as when you read. By show all with the method toFile() of class Student Close file

HOW TO TURN IN THE LAB

Psuedo-code of main() Student_yourLastName.java Class.java LQHashed.java HashedStructureDemo.yourLastName.java Student_yourLastName.class Class.class LQHashed.class HashedStructureDemo.yourLastName.class

HOW TO GRADE THE LAB

Turn in on time 3

Turn in all files required with correct names 1

UML, pseudo code 2

Data type classes about Student and Class 4

Class LQHashed 1

DRIVER CLASS

LQHashed

Create LQHashed structure 0.5

Open input file – create nodes – insert to data structure – close file 2

Menu of type – loop to allow to continue until exit 0.5

Insert – fetch – Encapsulation – update – delete – show all 3

EXIT: Open file – write to file - close 1

Java Hashtable

Create the Hashtable data structure 0.5

Open file to read, create nodes, and insert node to Hashtable, close file 3

Menu of operation – handle the loop 0.5

Insert, fetch, encapsulation, update delete, show all 2

EXIT: Open file – write to file - close 1

Compile success, requirements qualified – OUTPUT IN REQUIRED FORMAT 3

comment 2

LAB5 scores 30