Start New Discussion within our Software Development Community

Please dont tell me to "google" it obviously I'v tried everything and this is my last resort. k thanks :)

ok so I have to set a value to be restricted in the constructor
___________
Modify the constructor and set methods of the Shape class to verify the values of X and Y stay between zero and the MAX size. If X or Y are out of range, issue an error message on the console and set the value to zero.
___________

I don't remember how to do this nor can i find it online

import java.util.Scanner;




public abstract class Shape {

    int x;
    int y;
//--------------------------------------------phase2 add in    
protected final static int X_MAX_SIZE = 800;
protected final static int Y_MAX_SIZE = 600;

//--------------------------------------------
     int getX(){

        return x;
    }
    void setY(int l_ycoord){

        y = l_ycoord;
    }
    

    //--------------------------------------------

    void setX(int l_xcoord){

        x = l_xcoord;
    }

 int getY(){

        return y;
    }



        //--------------------------------------------

        public Shape (){

    }


public void Shape(int l_xcoord, int l_ycoord){
        x = l_xcoord;
        y = l_ycoord;
    }

    //--------------------------------------------
abstract void display();
abstract double area();


    //--------------------------------------------

    public static void main(String[] args) {

    }

}

I think this is what you're looking for. It revolves around the basics but everyone has to learn them at some point.

public void Shape(int l_xcoord, int l_ycoord) {
        if (l_xcoord > 0 && l_xcoord < X_MAX_SIZE &&
                l_ycoord > 0 && l_ycoord < Y_MAX_SIZE) {
            x = l_xcoord;
            y = l_ycoord;
        } else System.err.println("Shape constructor out of range error.");
    }
This article has been dead for over six months. Start a new discussion instead.