Consider a class Characteristic
that will be used in an online
dating service to assess how compatible two people are. Its attributes are:
And the following methods:
isValid(aRating)
that returns true if the given
rating is valid, that is, it is between 1 and 10
setRating(aRating)
that sets the rating to
aRating
if it is valid
setRating()
that reads a rating from the keyboard,
insisting that the rating supplied by the user is valid
get
, and set
methods for all attributes.
Implement this class in Java and write a main() method within it to test it.
Name this program Characteristic
Consider a class that keeps track of the sales of an item. An object of this class will have the attributes:
And the following methods:
ItemSales()
- Default constructor
ItemSales(double itemCost)
- Constructor that initializes
the itemCost.
ItemSales(double itemCost, int bulkQuantity, double discountPecentage)
-
Constructor that initializes itemCost, bulkQuatity and discoutPercentage.
ItemSales(int bulkQuantity, double discountPercentage)
- Constructor the
initializes bulkQuatity and discoutPercentage.
registerSale(n)
Records the sale of n
items.
If n
is equal to or larger than the bulk quatity, the cost per item
will be reduced by the bulk discount.
displaySales()
Displays the number sold, the total sales, and total
discount.
equals(ItemSales otherItem)
- Compare two ItemSales objects
for equality. They will be considered equal if all the attributes are equal.
get
, and set
methods for all attributes.
Implement this class in Java and write another class to test it. Make sure you test all the possibilities.
Name these programs ItemSales & ItemSalesDemo
Consider the class MotorBoat
that represents motorboarts. A motorboat
has attributes for:
The class has the following methods:
MotorBoat()
- Default constructor
MotorBoat(double fuelCapacity, double fuelInTank, double maxSpeed, double efficiency,
double distanceTraveled)
- Constructor that initializes fuelCapacity, fuelInTank, maxSpeed, efficiency,
and distanceTraveled
MotorBoat(double fuelCapacity, double maxSpeed, double efficiency)
- Constructor that initializes fuelCapacity, maxSpeed, and efficiency
setCurrentSpeed(double speed)
- Change the current speed of the boat
driveBoat(double time)
- Operate the boat for an amount of time at the
current speed.
refuelBoat(double fuel)
- Refuel the boat with some amount of fuel
getFuel()
- Get the amount of fuel in the tank
getDistanceTraveled()
- Get the distance traveled so far
equals(MotorBoat otherBoat)
- Compare two MotorBoats for equality
get
, and set
methods for all attributes.
If the boat has efficiency e
, the amount of fuel used when traveling
at a speed s
for time t
is
(e * (s^2) * t)
. The distance traveled in that time is
(s * t)
.
Implement this class in Java and write another class to test it. Make sure you test all the possibilities.
Name these programs MotorBoat & MotorBoatDemo
Please submit the completed assignment on Blackboard by attaching all your .java files. Make sure to attach all your programs to each submission.