1. Write a Calculatable interface that includes methods to calculate the following. (Do not overanalyze these methods!)
Posted: Sat May 14, 2022 2:50 pm
1. Write a Calculatable interface that includes
methods to calculate the following. (Do not
overanalyze these methods!)
The volume of a cube. The volume of a cube is determined by the
length, height, and width.
The volume of a cylinder. The volume of a cylinder is determined by
the height and radius of a
cylinder.
2. Consider the following partially completed
class.
public class SomeClass extends SomeOtherClass
{
public void convertHours(double hours)
{
//some code here
}
public void convertMonths(double months)
{
//some code here}
}
}
Write the corresponding abstract class.
3. Consider the following partially complete class:
public class TestClass implements Comparable
{
private String lastName;
private String firstName
public TestClass( String lastName, String firstName)
{
this.lastName=lastName;
this.firstName=firstName;
}
public String getlastName()
{
return this.lastName;
}
public String getFirstName()
}
return this.firstName;
}
public int compareTo( Object obj)
{
// complete the code here
}
}
Using the Comparable interface, write a compareTo()
method that returns -1 if the private
instance variable lastName occurs lexicographically before obj,
0 if the private instance
variable lastName and obj are lexicographically the same, or 1 if
the private instance variable
lastName occurs lexicographically after obj. Use a getter method
any time you need to use a
private instance variable.
Thank You!
methods to calculate the following. (Do not
overanalyze these methods!)
The volume of a cube. The volume of a cube is determined by the
length, height, and width.
The volume of a cylinder. The volume of a cylinder is determined by
the height and radius of a
cylinder.
2. Consider the following partially completed
class.
public class SomeClass extends SomeOtherClass
{
public void convertHours(double hours)
{
//some code here
}
public void convertMonths(double months)
{
//some code here}
}
}
Write the corresponding abstract class.
3. Consider the following partially complete class:
public class TestClass implements Comparable
{
private String lastName;
private String firstName
public TestClass( String lastName, String firstName)
{
this.lastName=lastName;
this.firstName=firstName;
}
public String getlastName()
{
return this.lastName;
}
public String getFirstName()
}
return this.firstName;
}
public int compareTo( Object obj)
{
// complete the code here
}
}
Using the Comparable interface, write a compareTo()
method that returns -1 if the private
instance variable lastName occurs lexicographically before obj,
0 if the private instance
variable lastName and obj are lexicographically the same, or 1 if
the private instance variable
lastName occurs lexicographically after obj. Use a getter method
any time you need to use a
private instance variable.
Thank You!