(Exercises #5, Page 464) Consider a class Characteristic
that will be used in an online
dating service to assess how compatible two people are. Its attributes are:
Implement this class with the following methods:
isValid(aRating)
that returns true if the given rating is valid, that
is, it is between 1 and 10setRating(aRating)
that sets the rating to aRating
if it is validsetRating()
that reads a rating from the keyboard, insisting that the rating
supplied by the user is validName this program Characteristic
(Exercises #7, Page 359) Consider the class MotorBoat
that represents motorboarts. A motorboat
has attributes for:
double
)double
)double
)double
)double
)double
)The class has the following methods:
MotorBoat()
- Default constructorMotorBoat(double fuelCapacity, double fuelInTank, double maxSpeed, double efficiency,
double distanceTraveled)
- ConstructorMotorBoat(double fuelCapacity, double maxSpeed, double efficiency)
- ConstructorsetCurrentSpeed(double speed)
- Change the current speed of the boatdriveBoat(double time)
- Operate the boat for an amount of time at the current speedrefuelBoat(double fuel)
- Refuel the boat with some amount of fuelgetFuel()
- Get the amount of fuel in the tankgetDistanceTraveled()
- Get the distance traveled so farequals(MotorBoat otherBoat)
- Compare two MotorBoats for equalityget
, 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 the class in Java and write some Java code to test all the functionality of the class.
Name these programs MotorBoat & MotorBoatDemo
(Exercises #6, Page 358) 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 constructorItemSales(double itemCost, int bulkQuantity, double discountPecentage)
- Default constructorItemSales(double itemCost)
- Default constructorItemSales(int bulkQuantity, double discountPercentage)
- Default constructorregisterSale(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 MotorBoats for equalityget
, and set
methods for all attributes.Implement the class in Java and write some Java code to test the class.
Name these programs ItemSales & ItemSalesDemo