This Problem Set Is Due By 11:59 PM on October 20, 2013

  1. Characterstic (5 points)

    Consider a class Characteristic that will be used in an online dating service to assess how compatible two people are. Its attributes are:

    • description - A String that identifies the characteristic
    • rating - An integer between 1 and 10 (inclusive) that indicates a person's desire for this characteristic in another person

    And the following methods:

    • Write a constructor that sets the description of the characteristic to given String and sets the rating to zero to indicate that it has not yet been determined.
    • Write a private method isValid(aRating) that returns true if the given rating is valid, that is, it is between 1 and 10
    • Write a method setRating(aRating) that sets the rating to aRating if it is valid
    • Write a method setRating() that reads a rating from the keyboard, insisting that the rating supplied by the user is valid
    • Implement 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

  2. Item Sales (10 points)

    Consider a class that keeps track of the sales of an item. An object of this class will have the attributes:

    • Number Sold
    • Total Sales (In Dollars)
    • Total Discounts
    • Cost per item
    • Bulk Quantity
    • Bulk discount percentage

    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.
    • Implement 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

  3. Motor Boat (10 points)

    Consider the class MotorBoat that represents motorboarts. A motorboat has attributes for:

    • The capacity of the fuel tank
    • The amount of fuel in the tank
    • The maximum speed of the boat
    • The current speed of the boat
    • The efficiency of the boat's motor
    • The distance traveled

    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
    • Implement 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.