Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

[JAVA PROGRAMMING LANGUAGE] CODE: (Please make the changes accordingly) public class LandTract { public int length; public int width; public int area() { return length*width;

[JAVA PROGRAMMING LANGUAGE]

image text in transcribed

CODE: (Please make the changes accordingly)

public class LandTract {

public int length; public int width;

public int area() { return length*width; }

public boolean equals(LandTract landobj) { if((length==landobj.length&&width==landobj.width)||(length==landobj.width&&width==landobj.length)) return true; return false; }

public String toString() { return "LandTract object with length "+length+" width "+width; } }

// LandTractTest.java import java.util.Scanner; public class LandTractTest { public static void main(String[] args) { Scanner sc=new Scanner(System.in); LandTract t1=new LandTract(); LandTract t2=new LandTract(); System.out.print("Enter length of first land tract:"); t1.length=sc.nextInt(); System.out.print("Enter width of first land tract:"); t1.width=sc.nextInt(); System.out.print("Enter length of Second land tract:"); t2.length=sc.nextInt(); System.out.print("Enter width of Second land tract:"); t2.width=sc.nextInt();

System.out.println(t1.toString()+" and area "+t1.area()); System.out.println(t2.toString()+" and area "+t2.area());

System.out.println(t1.equals(t2)?"The two tracks have the same size":"The two tracks don not have the same size"); } }

ERROR: image text in transcribed

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 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. SAMPLE RUN #1: java LandTract Interactive Session Hide Invisibles Highlight: None Show Highlighted Only O Enter length of first land.tract:10- Enter.width of first land.tract:55- Enter ch of d.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. WORK AREA RESULTS Print Content Ask My Results Support COMPILER ERROR MESSAGES Instructor LandTract.java:28: error: class, interface, or enum expected import java.util.Scanner; 1 error 1 public class LandTract 2 { 3 4 public int length; 5 public int width; 6 7 public int area() 8 { 9 return length*width; 10} 11 12 public boolean equals(Landtract landobj) 13 { 14 if((length=rlandobj.length&&width=rlandobj.width)||(length=rlandobj.width&&width==landobj.length)) 15 return true; 16 return false; 17) 18 19 public String toString() 20 { 21 return "Landtract object with length "+length+" width "+width; 22 } 23 } 24 25 26 27 // LandTract Test.java 18 import java.util.Scanner

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2022 Grenoble France September 19 23 2022 Proceedings Part 4 Lnai 13716

Authors: Massih-Reza Amini ,Stephane Canu ,Asja Fischer ,Tias Guns ,Petra Kralj Novak ,Grigorios Tsoumakas

1st Edition

3031264118, 978-3031264115

More Books

Students also viewed these Databases questions