Assignment

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

PRO192: OOP in Java

Assignment

Learning outcome:
Upon successful completion of this assignment, you will have demonstrated the abilities to:

• Uses streams to read and write data from/to different types of sources/targets
• Identify classes, objects, members of a class, and relationships among them needed for a
specific problem
• Explain the concept and demonstrates the use of Polymorphism, Encapsulation,
Abstraction, and Inheritance in java

• Understand and implement a complete program using a collection framework


• Describe to your instructor what you have learned in completing this workshop.

Project 1: STUDENT INFORMATION MANAGEMENT PROGRAM


Program Requirements:
Using array to develop application that manages student information
1) Define “Student” class that includes:
❖ Attributes:
▪ Student code
▪ Student full name
▪ Student birthyear
▪ Class name
▪ Average grade
❖ Methods:
▪ Initiate the attributes of “Student” class
▪ Needed accessor methods (getters) and mutator methods (setters)
2) Define class “StudentArray”. Each element in the list has the data type of “Student” class
❖ Methods:
▪ Add a student to the array
▪ Find out the student corresponding with specified student code
▪ Delete the student corresponding with specified student code
▪ Delete all the students of specified class
▪ Check if the entered student belongs to specified class
▪ Find out the first-found student having largest average grade
3) Define graphics user interface class that supplies a input and output interface for student
information.
When the user selects “Add”, “Find”, “Delete”, “Delete Class”, “Check”, “Best Student”
buttons, the corresponding method defined in the array class is called:
❖ Read in student information, select “Add” button, the student information is
added to the array

1
❖ Read in student code, select “Find” button, the corresponding student information
is displayed
❖ Read in student code, select “Delete” button, the corresponding student is
removed from the list
❖ Read in student class, select “Delete Class” button, all the students of the class is
removed from the list
❖ Read in student code and class, select “Check” button, student class is checked
and displayed
Select “Best Student” button, first-found student having largest average grade is displayed
Project 2: BOOK MANAGEMENT IN THE LIBRARY PROGRAM
Program Requirements:
Using array, develop application that manages book information in a library
1) Define “Book class” that includes:
o Attributes:
▪ Book title
▪ Author
▪ Published year
▪ Book unit price
▪ Book quantity
o Methods:
▪ Initiate the attributes of “Book” class
▪ Needed accessor methods (getters) and mutator methods (setters)
▪ Calculate total book price = quantity x book unit price
▪ Calculate transport price. It is known:
Quantity Transport price
<=50 0
50 < quantity <= 500 2% of book price
otherwise 5% of book price
2) Define class “BookArray” to manage book information in a library. Each element in
the list has the data type of “Book” class
Methods of the class:
o Add a book to the array
o Calculate the total book price (including transport price)
o Delete the book corresponding with specified book code
o Find out the book corresponding with specified book code
o Find out the book having largest quantity in the library
3) Define graphics user interface class that supplies a input and output interface for book
information. When the user selects “Add”, “Price”, “Delete”, “Find”, “Largest Quantity”
buttons, the corresponding method defined in the array class is called:

2
o Read in book information, select “Add” button, the book information is added to
the array
o Select “Price” button, the total book price (including transport price) of the books
in the library is calculated
o Read in book code, select “Delete” button, the corresponding book is removed
from the list
o Select “Find” button, the information of book having specified book code is
displayed
o Select “Largest Quantity” button, the information of book having largest quantity
is displayed

Project 3: MANAGING BILLS FOR USING ELECTRICITY PROGRAM


Program Requirements:
Use array to develop application that manages bill information for using electricity.

• Define “Bill” class that includes:


o Attributes:
▪ Customer code
▪ Customer type
▪ Old index of electricity meter
▪ New index of electricity meter
o Methods:
▪ Initiate the attributes of “Bill” class
▪ Needed accessor methods (getters) and mutator methods (setters)
▪ Calculate used electrical energy (KW) = New index of electricity meter –
Old index of electricity meter
▪ Calculate norm using electricity. It is known:
Customer Type Norm using electricity (KW)
“NN” 500
“SX” or “KD” 400
Otherwise 300
▪ Calculate payment for using electricity = Used electrical energy * Unit
price. It is known:
Used electrical energy Unit price
If Used electrical energy <= Norm 550 VND /KW
Otherwise 1100 VND / KW
o Define array class to manage bill information. Each item in the list has the data
type of “Bill” class
▪ Methods of the class:

3
• Add a bill to the list
• Find out the bill corresponding with specified bill code
• Calculate the total bill payment of customers belonging among
specified customer type
• Delete the bill corresponding with specified customer code
• Find out the bill having largest payment
o Define graphics user interface class that supplies a input and output interface for
bill information
▪ When the user selects “Add”, “Find”, “Payment”, “Delete”, “Largest
Payment” buttons, the corresponding method defined in the array class is
called
▪ Read in bill information, select “Add” button, the bill information is added
to the list
▪ Read in bill code, select “Find” button, the information of bill having the
bill code is displayed
▪ Read in customer type, select “Payment” button, the total payment of the
bills belonging among the customer type is calculated
▪ Read in customer code, select “Delete” button, the corresponding bill is
removed from the list
▪ Select “Largest Payment” button, the information of bill having the total
largest payment is displayed

Project 4: DOCTOR MANAGEMENT PROGRAM.


Write a program to manage the doctor information below:
Display the menu:
1. Add Doctor
2. Update Doctor.
3. Delete Doctor
4. Search Doctor.
5. Exit.

- If the user chooses 1 then add one record to data including Code(String), Name(String),
Specialization(String), Availability(int).
- If user chooses 2: then request enter the code. If it does not exist Code, the notification
"Doctor code does not exist". Otherwiseuser can edit of the remaining information. If
Information is blank then not change old information.
- If user chooses 3: the Code requires the user to enter Code and delete information if Code
exists, if Code does not exist,, the notification "code does not exist Doctor".
- If user chooses 4: require user to enter search strings, search and returns the list for users.
- If user chooses 5: exit the program.
Function details:
4
Function 1: Display GUIand Input Data.
• User runs the program. The program prompts users input Data.
• Auto next Function2.
Function 2: Perform function based on the selected option.

• Option 1: Add Doctor


o Require to enter task information including“code, name, specialization,
availability”.
o Check the valid data following conditions:
▪ Code is not null or duplicate in the DB.
o Add Doctor to the program.
o Return to the main screen.
• Option 2:Update Doctor
o Require to enter Code (id) and the data to be modified.
o Check the valid data with the conditions below:
▪ Code (id) must exist in the DB.
o Update Doctor in the program.
o Return to the main screen.
• Option 3:Delete Doctor
o The requirement to enter Code (id).
o Check valid data with the conditions below:
▪ Code(id) must exist in the DB.
o Delete the doctor information.
o Return to the main screen.
• Option 4: Search Doctor.
o Require to enter strings to search.
o Search data and displayon the screen
o Return to the main screen.
• Option 5:Exit the program.

Project 5: Write a calculator program.


Write a calculator program have functions: addition, subtraction, multiplication functions for
matrix.
Function details:
Function 1: Display a menu and ask users to select an option.
• Users run the program. The program prompts users to select an option.
• Users select an option, perform Function 2.
Function 2: Perform function based on the selected option.
o Prompt users input number of row, number of column of 2 matrixes.

5
o Prompt users input values of matrixes must be the number. If users input values
that are not a number, display notification on the screen: “Values of matrix must
be the number”.

• Option 1: Addition matrixes


o Display result.

• Option 2: Subtraction matrixes


o Display result.

• Option 3: Multiplication matrixes


o Display result.

• Option 4: Exit program.


Project 6: Shapes.

Implement the Shape hierarchy shown in above figure. Each two-dimensional shape should
contains method getArea() to calculate the area of it (e.g area of a circle is pi* r2).
Each three-dimensional shape should contain getArea() and getVolume() methods to calculate
the surface area and volume respectively.
Create a program that uses an array of Shape references to objects of each concrete class in the
hierarchy. The program should print the object to which each array element refers.
Also in the loop that processes all the shapes in the array, determine whether each shape is a two-
dimensional shape or three-dimensional shape. If a shape is two-dimensional one, display its
area. If a shape is three -dimensional one, display its area and volume.
Project 7: Bees.
Write classes to represent 3 different types of Bee - Worker, Queen and Drone.

6
Each Bee has a floating-point health property, which is not writable externally and upon creation
is set to a value of 100 (percent).
Each Bee has a Damage() method that takes a single integer parameter that should be a value
between 0 and 100. When this method is called, the health of the bee is to be reduced by that
percentage of their current health.
When a Worker has a health below 70% it cannot fly and therefore is pronounced Dead. When a
Queen has a health below 20%, or a Drone below 50%, it is pronounced dead. This 'Dead'
property should be readable from each Bee. When a Bee is dead, no further health deductions
should be recorded by the bee, although the Damage() method should still be invokable without
error.
Your application should create a single list containing 10 instances of each type of Bee and store
in a list or array. It must support methods to allow Damage() to be called for each Bee, and to
return the health status of each bee, including whether it is alive or not.
Your application interface must contains 2 functions (user press “1” or “2” to activate this
function :
1 – Create bee list – Clear current bee list and create new random bees, then display in the
console windows
2 – Attack bees - Attack current bee list, a different random value between 0 and 80 should be
selected for each bee and applied with a call to Damage(). After attacked, the user interface
should refresh to show the health status of the bees in console windows

You might also like