Can anyone please help me with this program? P.S. The section where it says\" im
ID: 3852194 • Letter: C
Question
Can anyone please help me with this program?
P.S. The section where it says" implement a driver program" after step 3,
Step 4: add length1 and length2 and assign the result to length3
Step 5: Print out length1+length2=length3
Step 6: Subtract length2 from length1 and assign the result to length4
Step 7: Print out length1-length2=length3
STAGE 1 | The length of an object can be described by two integers: feet and inches (where 12 inches equals one foot). Class UML is as follows: Length - feet: int -inches : int +Length) + Length(newFeet: int, newinches: int) +getFeet): int + setFeet(newFeet: int) void + getinches(: int + setinches(newlnches: int): void + add(otherLength : Length): Length + subtract(otherLength: Length) : Length + toString0: String Default constructor sets the length of an object to 0 feet & O inches Overloaded constructor sets the length of an object to given feet & inches For each data field, define the accessor and mutator methods add method, adds two length objects and return the result as a length object (feet & inches must be in range) Subtract method, subtracts two length objects and return the result as a length object (feet & inches must be in range. this object must be larger than otherLength) toString() method returns a String in format of ## ##" For example: Length meLength = new Length( 10, 6); System.out.printin( myLength.toString0); Will display: 10' 6 STAGE 2 1 Implement the Length class using the above UML. STAGE 3 | Driver program Implement a driver program called TestLength,java as follows: 1) Create Length object length1 being 10' 5 2) Create Length object length2 being 5 10 3) Print the two objectExplanation / Answer
Length.java
public class Length {
//Declaring instance variables
private int feet;
private int inches;
//Zero argumented constructor
public Length() {
this.feet = 0;
this.inches = 0;
}
//Parameterized constructor
public Length(int newFeet, int newInches) {
super();
this.feet = newFeet;
this.inches = newInches;
}
//getters and setters
public int getFeet() {
return feet;
}
public void setFeet(int newFeet) {
this.feet = newFeet;
}
public int getInches() {
return inches;
}
public void setInches(int newInches) {
this.inches = newInches;
}
//This method add two Length Objects and return Length Object
public Length add(Length otherLength) {
Length len = new Length();
if ((this.inches + otherLength.getInches()) >= 12) {
len.inches = this.inches + otherLength.getInches() - 12;
len.feet = this.feet + otherLength.getFeet() + 1;
return len;
} else {
len.inches = this.inches + otherLength.getInches();
len.feet = this.feet + otherLength.getFeet();
return len;
}
}
//This method subtract two Length Objects and return Length Object
public Length subtract(Length otherLength) {
Length len = new Length();
if (this.inches < otherLength.getInches()) {
len.feet = this.feet - otherLength.feet - 1;
len.inches = 12 + this.inches - otherLength.inches;
return len;
} else {
len.feet = this.feet - otherLength.feet;
len.inches = this.inches - otherLength.inches;
return len;
}
}
//toString method is used to display the contents of an Length object inside it
@Override
public String toString() {
return feet + "' " + inches + """;
}
}
__________________
Test.java
public class Test {
public static void main(String[] args) {
//1 & 2 .Creating an Two length object by passing feet and inches as arguments
Length length1=new Length(10,5);
Length length2=new Length(5,10);
//3.Displaying the two length objects
System.out.println("Length#1 Obejct :"+length1.toString());
System.out.println("Length#2 Obejct :"+length2.toString());
//4.Creating an Length3 object by adding Length1 and Length2 Object
Length length3=length1.add(length2);
//5.Displaying the Length3 Object
System.out.println("Length#3 Obejct :"+length3.toString());
//6.Creating an Length4 object by subtracting Length1 and Length2 Object
Length length4=length1.subtract(length2);
//7.Displaying the Length4 Object
System.out.println("Length#4 Obejct :"+length4.toString());
}
}
____________________
Output:
Length#1 Obejct :10' 5"
Length#2 Obejct :5' 10"
Length#3 Obejct :16' 3"
Length#4 Obejct :4' 7"
_____________Could you rate me well.Plz .Thank You