Computer Science

Almighty
JAVA2_Instruction_SP2019_LAB5.pdf

Liem Le | COSC2436 #1

School of Engineering and Technology

COSC2436 – LAB 5

Title Singly Linked List – Iterator and java LinkedList

Time to

complete Two weeks

COURSE OBJECTIVES

LEARNING OUTCOME LAB OBJECTIVES

-Apply Object Oriented programming

-Complete the lab on time (Time

Management)

-Do the lab by following the project process:

analysis, design, write the code, test, debug,

implement

-UML of data type class

-Write comments

-Write the code of data type classes

including data members, no-argument

constructor, parameter constructors,

mutator methods, assessor methods,

toString and other methods

-INHERITANCE: write the code of child

classes including, data members,

constructors and other methods inherited

from parent class

-apply Polymorphism: using object of the

parent class to point to object of child

classes

-control structure: if..else, switch, do..while

-create object, access members of data type

class

-format the output in columns and double

numbers with 2 decimal digits

-display message box

-create and work with SinglyLInkedList,

Iterator

-Create a new project, add source file to the project, compile

and run the program without errors and qualified to the

requirement

-Declare variables of int, double, String;

-provide UML of data types

-Create data types with data members, constructors, mutator

methods

-Apply Inheritance relationship

-Apply polymorphism in the project

-provide the pseudo-code of program

-create and manage the menu to loop back to re-display after

each task: using do.. while

-Use switch statement to determine and define the action for

each task

-Format the output in columns and double numbers wiwth 2

decimal digits

-Display message box

- create the data structure type of Singly Linked List and

access the operations

- create Iterator with Singly Linked List and access the

operations

- create and access java LinkedList and access the operations

Liem Le | COSC2436 #2

Skills

required to

do the Lab

To do this lab, students have to know:

-Review to create the pseudo-code or a flowchart of a lab

-Review the syntax to create a data type class with data members, constructors, mutator

accessor methods, method toString

-Review how to define a child class including data member, constructor, toString and other

methods inheriting from parent class:

-Review how to declare an object in main(), how to access the methods of data type classes

from main()

-Review how to apply polymorphism

-Review control structure: if..else, switch, do..while loop

-How to set the decimal digits (2) of a double number

-How to display the message box

-How to create a Singly Linked List and how 4 operations work

-How to create a Singly Linked List with Iterator and how the iterator work with operations

-How to create java LinkedList with Iterator and how to access iterator with operations

HOW TO DO

EACH PART

*Step1: Create the pseudo-code

*Step2: Write the code

-start editor create the project SP2019LAB5_yourLastName, add all .java files, 3 classes for

Account, Checking Account and Saving Account, class SinglyLinkedList, class

SinglyLinkedListIterator and

-follow the pseudo-code and use java to write the code of the program

*Step3: compile and run the program

*Step4: debug if there is any errors to complete the program

HINTS:

0. Create the project SP2019LAB5_yourLastName 1. Add 3 data type classes: Account_yourLastName, CheckingAccount_yourLastName,

SavingAccount_yourLastName 2. Add data structure classes: SinglyLinkedList, SinglyLinedListIterator 3. Add driver class named: Demo_LinkedList_yourLastName

LAB 5

Requirement

Create the an application that can use different types of Linked List to manage either Checking

Account or Saving Account.

The application should allow users can select the type of Linked List to work on. After finishing

one, users can select to work with other type of Linked List until they want to exit

1. Singly Linked List 2. Singly Linked List with Iterator 3. Java Linked List with Iterator 0. Exit

You can re-use the class Account_yourLastName, CheckingAccount_yourLastName and

SavingAccount_yourLastName

Liem Le | COSC2436 #3

FOR SINGLY LINKED LIST DO THE FOLLOWING TASKS:

Create a Singly Linked List then allow users to do the following tasks:

Insert Account

-display message to ask users to enter all the information that needs to create either a

Checking account or Saving account

-Insert that account to the Singly Linked List.

-Check if Insert returns true, display message “The account is open”

-If insert returns false, display message: “Cannot open this account”

Read Account

Allow users to enter the account number to look for the Checking Account or Saving Account.

- If the Singly Linked List is empty, display the message: “There is no node in the Singly Linked

List”

- If the account cannot be found, display the message: “Account cannot be found”

- If the it is found, display the information of the chekcing account or saving account found

VERIFY UNCAPSULATION

-ask for information of either a Checking account or Saving account named temp1

-insert account temp1 to the Singly Linked List

-Change the address or one filed of account temp1

-fetch one account from Singly Linked List with the same account number of temp1

to the variable temp2

-compare the address of temp1 and temp2 (or the field you have change on temp1)

* if both address are the same: display the message: “Singly Lnked List is not encapsulated”

* If their addresses are different, display the message: “Singly Linked Lst is encapsulateded”

UPDATE

-ask for information of either a Checking account or Saving account named temp

-insert account temp to the Singly Linked List

-Change the address or one filed of account temp

-Update temp to the Singly Linked List

-Check if update returns true, display message “Update successfully”

-if update returns false, display message “Update Not successfully”

DELETE

- allow users to enter the account number of the account that they want to delete

Delete the account with the id.

-Check if delete returns true, display message “Account is closed”

-If delete returns false, display message “Delete account failed”

SHOW ALL

-show all accounts in the Singly Linked list

Liem Le | COSC2436 #4

FOR SINGLY LINKED LIST WITH ITERATOR

Create a Singly Linked List with Iterator then do the following steps:

INSERT

-Allow users to insert 5 accounts (either Checking Account or Saving Account) to the Singly

Linked List with Iterator

SHOW ALL

-show all 5 accounts in the Singly Linked List with Iterator

DELETE

-move iterator to delete the third account in the Singly Linked List with Iterator

-show all accounts to verify the account is deleted

FOR THE JAVA LinkedList

Create a java LinkedList then do the following steps:

INSERT

-Allow users to insert 5 accounts (either Checking Account or Saving Account) to the Singly

Linked List with Iterator

FETCH

-Fetch two first accounts in the Java LinkedList

UPDATE

-fetch the node at the current location of iterator to variable temp

-change the address or a field of account temp

-update the account at the current location with new temp

-check if update returns true, display message “Account is updated”

-if update returns false, display message: “Update failed”

SHOW ALL

-show all the LinkedList to see all accounts

HOW TO

EVALUATE

THE LAB

ITEMS SCORES

Turn in on time 3

All data type classes 2

class SinglyLinkedList 1

class SinglyLinkedListIterator 1

Display menu to choose the type of list and manage the loop to terminate the program when users select Exit

2

Declare the Singly Linked list object, perform insert, fetch, verify encapsulation, delete , update and display information on each step

5

Declare the SinglyLinkedListIterator object, perform insert, show all, delete 5

Liem Le | COSC2436 #5

Declare the Java LinkedList object, Declare ListIterator object and attach it to LinkedList object, perform insert, fetch, update and show all

4

Inheritance and polymorphism 2

compile success – qualified the requirements 3

comment 2

Total scores of Lab5 30

HOW TO

TURN IN

You should turn in the following files:

Account_LastName.java

CheckingAccount_yourLastName.java

SavingAccount_yourLastName.java

SinglyLInkedList.java

SinglyLInkedListIterator.java

Demo_LinkedList_yourLastName.java

Account_LastName.class

CheckingAccount_yourLastName.class

SavingAccount_yourLastName.class

SinglyLinkedList.class

SinglyLInkedListIterator.class

Demo_LinkedList_yourLastName.class

-pseudo code

IF YOU GET ANY PROBLEM TO SUBMIT FILE .class, YOU CAN SUBMIT ALL PROJECT INTO ONE

FILE .zip or .rar TO SEND