Lab Evaluation2 BSec
Lab Evaluation2 BSec
Lab Evaluation -2
Copy all your .java files in a single word and the output screen. Submit in the following link as a word
file only named CBENU4CSE231XX.docx. Any name other than this will not be evaluated.
https://drive.google.com/drive/folders/1v1IX2oeiD53p3lz1Z_bCZmdDdCBb90AU?usp=sharing
Rubrics
1. Payment System
a. Define a class named Payment that has two instance variables:
amount, which specifies the amount of payment. It is a double value.;
currency, which specifies the currency of the payment as a String value. The
currency can take one of the three values “SAR”, “EUR” and “USD”.
The class Payment also has a static array of constants named currencies_array
that contains the three currency values “SAR”, “EUR” and “USD”.
The method setCurrency(String CURR) must make data validation checking if
the parameter CURR is a value in the array currencies_array, otherwise, it sets to
currency to the default value “SAR”.
The class Payment has a constructor with two arguments that sets the values of
both instance variables to those passed as parameters.
Finally, it defines the paymentDetails() method that returns the string in the
format “the amount is amount currency” Implement the class Payment.
You must use all concepts related to inheritance and good software engineering
practices (encapsulation, data hiding, etc.).
b. Write a class CashPayment that is derived from Payment. This class should redefine the
paymentDetails() method to indicate that the payment is in cash. It must return the
following string in the format “the amount is amount currency (paid in Cash)”. Include an
appropriate constructor. You must use all inheritance concepts. Implement the class
CashPayment.
c. Write a class CreditCardPayment that is derived from Payment. This class contains three
instance variables: (1) nameOnCard is a String and specifies the name of the card owner,
(2) ExpirationDate is defined as a Date object (Date class is in package java.util.Date),
and (3) creditCardNumber which is a String that specifies the credit card number.
The class also has a constructor that initializes all instance variables.
This class should redefine the paymentDetails() method to indicate that the
payment is in credit card and shows all credit card information. It must return the
following string in the format:
“The amount is amount currency (paid in Credit Card)
Card Owner: nameOnCard
Expiration Date: expirationDate
Credit Card Number: creditCardNumber”.
d. Define the class TestPayment with a main method that creates one CashPayment object
and one CreditCardPayment object with different values and calls and prints
paymentDetails for each object. To create a new date, you can use Date date = new
Date().
2. Consider the classes Person, Street, Address, Phone, Time and Date. We will build a hospital
management system.
a. Write a class Patient that inherits from Person. It has these specific private attributes:
String SSN, social security number. It must start with ‘701’ and has 10
characters.
String hospitalID: hospital ID of the patient. It must start with ‘23’ and has 6
characters.
A method toString(), which returns a string representation of the Patient class in
the following format. It must call the superclass toString () method.
• A constructor with seven arguments that sets the values of instance variables to
those passed as parameters.
b. Write a class Doctor that inherits from Person. It has three more specific private
attributes:
String doctorID, the ID of the doctor in the hospital. It must start with ‘99’ and
has 8 characters.
Date hireDate: the hire date of the doctor.
Time [] workingTime = new Time [2]: the working time is an array of Time
objects composed of two cells. The first cell represents the starting work time and
the second cell represents the end work time.
A method toString(), which returns a string representation of the Patient class in
the following format. It must call the superclass toString () method.
A constructor with eight arguments that sets the values of instance variables to
those passed as parameters. Doctor(String CID, String firstName, String
lastName, Phone mobilePhone, Address address, String doctorID, Date hireDate,
Time [] workingTime)
Implement the class Doctor and get and set methods for the specific attributes.
c. Write a class Appointment that represents an appointment for a patient with a doctor on a
certain date and at a certain time. It has the following four attributes:
Doctor doctor;
Patient patient;
Date appDate;
Time appTime;
It has a toString() method that provides the following output:
d. Complete the missing code in HospitalTest class. The final output must be equal to
Appointment {Patient: (219874, Ali Karim)}, Doctor:(Ahmed Nasr), on (11/12/2014) at
(17:30:00)}
Doctor working time from 5:30 pm until 9:30 pm
Patient phone number: +966 05 14578542
Doctor phone number: +96605114578548
3. In this assignment, you will create four classes, a base class, two child classes and a driver class.
The base class will be a BasketballPlayer class. The two child classes will be
CollegeBasketballPlayer and ProBasketballPlayer.
The BasketballPlayer class will have
o instance data of name, position, team (Strings), height, weight, agility,
speed, ballHandling (ints) and all should be accessible by only the
subclasses.
o We will have 3 constructors namely,
a 0 parameter constructor (all instance data are initialized to
“unknown” or 0),
a 3-parameter constructor which receives the 3 Strings and
assigns the 3 String instance data to them and 0 to all int instance
data, and
one which receives a parameter for each instance data and
assigns them all appropriately.
o Also create accessors for all instance data and a toString which will
return at least the name, position, team and the value for a method you
will write called getValue. The getValue method will test various
instance data and return an int using nested if-else logic based on the
table below. All methods should be accessible by any package.
NOTE: empty “other conditions” mean “any values”, these would be used in else
clauses.
Implement a CollegeBasketballPlayer to extend BasketballPlayer.
o It will have two instance data, eligibilityRemaining (int) and role
(String). Note: We do not plan to extend this class.
o Have 3 different constructors,
a 0 param constructor,
a 3 param constructor (name, position, team) and
a constructor that receives all params.
Use super(); for the 0 param constructor, super(…);
for the other two constructors, passing the appropriate
parameters.
Assign eligibilityRemaining and role to either 4 and “bench” for
the 0 and 3 parameter constructors or the proper params for the
third constructor.
o Add accessors for these two instance data a new toString method which
return super.toString() + “\t” + “…” where … is at least the role of this
player (and the eligibilityRemaining if desired).
o Finally, add a method called draftable which returns a boolean based on
the following logic: A player is draftable if he/she is a “starter” (role)
whose value (as obtained by super.getValue()) > 4 or is a “bench” player
(role) whose value >= 8.
Implement ProBasketballPlayer by extending BasketballPlayer.
o Add 2 new instance data: yearsInLeague (int) and role (String).
o Add 3 constructors similar to what you had for CollegeBasketballPlayer.
For the first two constructors, yearsInLeague should be initialized to 0
and role to “bench”.
o Add accessors for the two new instance data and a toString which will
add to BasketballPlayer’s toString both yearsInLeague and role.
o Finally, implement a method called newContractValue which returns an
int value based on the logic in the following table.
Again, empty entries in the table mean “any value”.
NOTE: because of the logic here, you may need to add else return 0; at the end of
your nested if-else statement to satisfy the Java compiler.
import java.time.*;
// Get the current date and time
LocalDateTime currentTime = LocalDateTime.now();
System.out.println("Current DateTime: " + currentTime);
LocalDateTime date2 =
currentTime.withDayOfMonth(10).withYear(2012);
System.out.println("date2: " + date2);
//parse a string
LocalTime date5 = LocalTime.parse("20:15:30");
System.out.println("date5: " + date5);
4.