Write your own custom-made class that includes the following items: a default co
ID: 3613918 • Letter: W
Question
Write your own custom-made class that includes the following items: a default constructor 1 or more "other" constructors 5 or more instance fields (i.e. properties) a modifier for each instance field an accessor for each instance field 2 or more additional "interesting" methods that may modify instance fields' values but that are meant to manipulate an object in an "interesting" way Write a test class named Ch2Proj1 that instantiates 2 or more objects from your class and that uses every constructor and method from the class, displaying output so that the instructor can easily tell that the methods and constructors work properly.Explanation / Answer
please rate - thanks in Java Test Program import java.util.Scanner; public class Squaretest { public static void main (String[] args) {Scanner in=new Scanner(System.in); int l,w; double diag,area,perimeter; Square s1= new Square(); System.out.println("Enter length: "); l=in.nextInt(); System.out.println("Enter width: "); w=in.nextInt(); Square s2=new Square(l,w); s1.print(); s2.print(); System.out.println("Enter new length: "); l=in.nextInt(); s1.setlength(l); s1.print(); System.out.println("Enter new width: "); w=in.nextInt(); s2.setwidth(w); s2.print(); System.out.println("S1 has a length of "+s1.getlength()+" and awidth "+s1.getwidth()); System.out.println("S2 area= "+s2.getarea()+" perimeter="+s2.getperimeter()); System.out.println("S2 diagnol= "+s2.getdiagnol()); } } CLASS public class Square { private double length,width; public Square() {length=0; width=0; } public Square(double l, double w) { length=l; width=w; } public void print() {System.out.println("The dimensions of your square are: "); System.out.println("Length="+length); System.out.println("width="+width); } public double getlength() { return length; } public double getwidth() { return width; } public void setlength(double l) {length=l; } public void setwidth(double w) {width=w; } public double getdiagnol() {return Math.sqrt(length*length+width*width); } public double getarea() {return length*width; } public double getperimeter() {return length*2+width*2; } };
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.