Question

In: Computer Science

****JAVA Program**** Make a LandTract class with the following fields: • length - an int containing...

****JAVA Program****

Make a LandTract class with the following fields:

• length - an int containing the tract's length
• width - an int containing the tract's width

The class should also have the following methods :

• area - returns an int representing the tract's area
• equals - takes another LandTract object as a parameter and returns a boolean saying
whether or not the two tracts have the same dimensions (This applies regardless of whether the dimensions match up. i.e., if the length of the first is the same as the width of the other and vice versa, that counts as having equal dimensions.)
• toString - returns a String with details about the LandTract object in the format:
LandTract object with length 30 and width 40
(If, for example, the LandTract object had a length of 30 and a width of 40.)

Write a separate program that asks the user to enter the dimensions for the two tracts of
land (in the order length of the first, width of the first, length of the second, width of the second). The program should print the output of two tracts' toString methods followed by a sentence stating whether or not the tracts have equal dimensions. (If the tracts have the same dimensions, print, "The two tracts have the same size." Otherwise, print, "The two tracts do not have the same size.") Print all three statements on separate lines.

****Results have to look like this****

Enter·length·of·first·land·tract:10↵
Enter·width·of·first·land·tract:55↵
Enter·length·of·second·land·tract:36↵
Enter·width·of·second·land·tract:75↵
LandTract·with·length·10,·width·55,·and·area·550↵
LandTract·with·length·36,·width·75,·and·area·2700↵
The·two·tracts·do·not·have·the·same·size.↵

Solutions

Expert Solution

Hi Please find my implementation.

Please let me know in case of any issue.

########### LandTrack.java ############

public class LandTract {

  

   private int length;

   private int width;

  

   public LandTract(int l, int w) {

       length = l;

       width = w;

   }

  

   public int area(){

       return length*width;

   }

  

   public boolean equals(LandTract other){

      

       if(length == other.length && width == other.width)

           return true;

       else if(width == other.length && length == other.width)

           return true;

       else

           return false;

   }

  

   @Override

   public String toString() {

       return "LandTract object with length "+length+" and width "+width;

   }

}

############ LandTrackTest.java ##############

public class LandTrackTest {

   public static void main(String[] args) {

      

       Scanner sc = new Scanner(System.in);

      

       System.out.print("Enter length of first land track: ");

       int l1 = sc.nextInt();

      

       System.out.print("Enter width of first land track: ");

       int w1 = sc.nextInt();

      

       System.out.print("Enter length of second land track: ");

       int l2 = sc.nextInt();

      

       System.out.print("Enter width of second land track: ");

       int w2 = sc.nextInt();

      

       // creating two land track object

       LandTract track1 = new LandTract(l1, w1);

       LandTract track2 = new LandTract(l2, w2);

      

       System.out.println(track1);

       System.out.println(track2);

      

       if(track1.equals(track2))

           System.out.println("The·two·tracts·do·have·the·same·size");

       else

           System.out.println("The·two·tracts·do·not·have·the·same·size");

   }

}

/*

Sample run:

Enter length of first land track: 10

Enter width of first land track: 55

Enter length of second land track: 36

Enter width of second land track: 75

LandTract object with length 10 and width 55

LandTract object with length 36 and width 75

The·two·tracts·do·not·have·the·same·size

*/


Related Solutions

Make a LandTract class with the following fields: • length - an int containing the tract's...
Make a LandTract class with the following fields: • length - an int containing the tract's length • width - an int containing the tract's width The class should also have the following methods: • area - returns an int representing the tract's area • equals - takes another LandTract object as a parameter and returns a boolean saying whether or not the two tracts have the same dimensions (This applies regardless of whether the dimensions match up. i.e., if...
Make a LandTract class with the following fields: • length - an int containing the tract's...
Make a LandTract class with the following fields: • length - an int containing the tract's length • width - an int containing the tract's width The class should also have the following methods: • area - returns an int representing the tract's area • equals - takes another LandTract object as a parameter and returns a boolean saying whether or not the two tracts have the same dimensions (This applies regardless of whether the dimensions match up. i.e., if...
Write a java program using the following information Design a LandTract class that has two fields...
Write a java program using the following information Design a LandTract class that has two fields (i.e. instance variables): one for the tract’s length(a double), and one for the width (a double). The class should have:  a constructor that accepts arguments for the two fields  a method that returns the tract’s area(i.e. length * width)  an equals method that accepts a LandTract object as an argument. If the argument object holds the same data (i.e. length and...
Design a LandTract class that has two fields (i.e. instance variables): one for the tract’s length(a...
Design a LandTract class that has two fields (i.e. instance variables): one for the tract’s length(a double), and one for the width (a double). The class should have:  a constructor that accepts arguments for the two fields  a method that returns the tract’s area(i.e. length * width)  an equals method that accepts a LandTract object as an argument. If the argument object holds the same data (i.e. length and width) as the calling object, this method should...
Design a LandTract class that has two fields (i.e. instance variables): one for the tract’s length(a...
Design a LandTract class that has two fields (i.e. instance variables): one for the tract’s length(a double), and one for the width (a double). The class should have:  a constructor that accepts arguments for the two fields  a method that returns the tract’s area(i.e. length * width)  an equals method that accepts a LandTract object as an argument. If the argument object holds the same data (i.e. length and width) as the calling object, this method should...
Java... Design a Payroll class with the following fields: • name: a String containing the employee's...
Java... Design a Payroll class with the following fields: • name: a String containing the employee's name • idNumber: an int representing the employee's ID number • rate: a double containing the employee's hourly pay rate • hours: an int representing the number of hours this employee has worked The class should also have the following methods: • Constructor: takes the employee's name and ID number as arguments • Accessors: allow access to all of the fields of the Payroll...
write program in java Create a class named PersonalDetails with the fields name and address. The...
write program in java Create a class named PersonalDetails with the fields name and address. The class should have a parameterized constructor and get method for each field.  Create a class named Student with the fields ID, PersonalDetails object, major and GPA. The class should have a parameterized constructor and get method for each field. Create an application/class named StudentApp that declare Student object. Prompts (GUI input) the user for student details including ID, name, address, major and GPA....
Write a Java class called Person. The class should have the following fields: A field for...
Write a Java class called Person. The class should have the following fields: A field for the person’s name. A field for the person’s SSN. A field for the person’s taxable income. A (Boolean) field for the person’s marital status. The Person class should have a getter and setter for each field. The Person class should have a constructor that takes no parameters and sets the fields to the following values: The name field should be set to “unknown”. The...
In Java...create a class Realestate.java with the following fields: location, price, and description. Create a class...
In Java...create a class Realestate.java with the following fields: location, price, and description. Create a class RealestateFinder.java that reads in real estate data from a CSV file (RealestateList.csv). Then provide the user with the following options: Sort per Price, Sort per Location, and Exit. Use ArrayList and Arrays.sort to perform the sorts and display the data to the user.
In java, design a class named Motorcycle that has the following fields: • year – The...
In java, design a class named Motorcycle that has the following fields: • year – The year field is an int that holds the motorcycle’s year • make – The make field references a String object that holds the make of the motorcycle. • speed – The speed field is an int that holds the motorcycle’s current speed The class should have the following constructor and other methods: • Constructor – the constructor should accept the motorcycle’s year and make...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT