java - Implement a subclass Square that extends the Rectangle class -


//implement subclass square extends rectangle class. in constructor, accept x- , y-positions of center , side length of square. call setlocation , setsize methods of rectangle class. these methods in documentation rectangle class. supply method getarea computes , returns area of square. write sample program asks center , side length, prints out square (using tostring method inherit rectangle) , area of square.

//ok... last minute, don't understand wrong code giving me error square cannot resolved type... here class:

    import java.awt.rectangle;    public class squares22 extends rectangle  {   public squares22(int x, int y, int length) {     setlocation(x - length / 2, y - length / 2);     setsize(length, length); }  public int getarea() {     return (int) (getwidth() * getheight()); }  public string tostring() {     int x = (int) getx();     int y = (int) gety();     int w = (int) getwidth();     int h = (int) getheight();     return "square[x=" + x + ",y=" + y + ",width=" + w + ",height=" + h            + "]"; } }  //and tester class...  import java.util.scanner;  public class squares22tester    {    public static void main(string[] args)    {  scanner newscanx =  new scanner(system.in); scanner newscany =  new scanner(system.in); scanner newscanl =  new scanner(system.in);   system.out.println("enter x:"); string x2 = newscanx.nextline(); system.out.println("enter y:"); string y2 = newscany.nextline(); system.out.println("enter length:"); string l2 = newscanl.nextline();  int x = integer.parseint(x2); int y = integer.parseint(y2); int length = integer.parseint(l2);    square sq = new square(x, y, length);    system.out.println(sq.tostring());     } } 

//can please assignment due @ midnight.. says square cannot resolved type on tester class when compliling....

square isn't name of class. name of class 'squares22'. why 'square' cannot recognized. change square in test squares22 or vice versa. should solve issues.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -