Question: c) 10/25: Review the example from class: RollingDice which uses Die. RollingDice is a driver class whose main method instantiates (i.e. creates) 2 Die objects,

c) 10/25: Review the example from class: RollingDice which uses Die. RollingDice is a driver class whose main method instantiates (i.e. creates) 2 Die objects, then calls the computeSum method which is defined in the Die class. As you review this example, let me know if something is not clear. Define 2 classes (in 2 separate files): 1) a driver class named TestPoint and 2) a blueprint class named Point:
TestPoint is a driver class, whose main method instantiates 4 Point objects (e.g.
Point p1 = new Point (0, 0);
Point p2 = new Point (4, 3);
Point p3 = new Point (3, 4);
Point p4 = new Point (0, 0);
), then computes and prints the distance between the first 2 points and the distance between the last 2 points (by calling a method calcDistance as follows:
distance1 = p1.calcDistance (p2);
distance2 = p3.calcDistance (p4);
where p1, p2, p3 and p4 are Point objects, and calcDistance is a method to be defined in the Point class).
A Point contains instance data for the x and y coordinates. Define the Point constructor to accept and initialize this data. Include a method to calculate and return the distance from this point to another point.
Try writing your driver code first, and writing comments before code.
Include a toString() method to return a nicely-formatted String representation of a point, e.g. if a point's x value is 3 and y value is 4, then the toString() method should return the following String: "(3, 4)"; the toString method is defined in your Point class and called (invoked) in your TestPoint class in order to print the output in a readable way, e.g.: The distance between (0, 0) and (3, 4) is 5.
d)
Try writing your driver code first, and writing comments before code. Create two classes, Kennel and Dog, as follows. Kennel is a driver class, whose main method instantiates several Dog objects, then computes and prints their ages in "person years". A Dog contains instance data that represents the dog's name and age. Define the Dog constructor to accept and initialize instance data. Include a method to compute and return the age of the dog in "person years" (seven times the dog's age). Include a toString method that returns a one-line description of the dog. Include getter (accessor) and setter (mutator) methods for the name and age, i.e.
public String getName()
public double getAge()
public void setName(String)
public void setAge(double)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!