Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

public abstract class Point { private int y; private int x; public Point() { this.y = 0; this.x = 0; } public Point(int x, int

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

public abstract class Point { private int y; private int x;

public Point() { this.y = 0; this.x = 0; }

public Point(int x, int y) { this.y = y; this.x = x; } public int Y() { return y; }

public void Y(int y) { this.y = y; } public int X() { return x; }

public void X(int x) { this.x = x; }

@Override public String toString() { return " Point ( x , y ) : ( " + x + " , " + y + " ) "; }

public abstract double calcArea();

}

------

public class Circle extends Point { private double radius; public Circle() { this.radius=15; } public Circle( double radius ) { this.radius = radius; }

@Override public double Area() { return Math.PI * radius * radius; }

@Override public String toString() { return " Radius=" + radius +" "+super.toString(); }

}

------

public class Rectangle extends Point { private double length; private double width;

public Rectangle() { length = 15; width = 15; }

public Rectangle( double length , double width ) { this.length = length; this.width = width; }

public double Length() { return length; }

public void Length( double length ) { this.length = length; } public double Width() { return width; }

public void Width( double width ) { this.width = width; } @Override public double calcArea() { return length * width; }

@Override public String toString() { return " Width :" + width + " Length :" + length+" " + super.toString(); }

}

----

public class Box extends Rectangle { private double height;

public Box() { this.height = 15; }

public Box(double height) { this.height = height; }

public double Height() { return height; }

public void Height(double height) { this.height = height; }

@Override public double calcArea() { return 2 * ( Length() * Width()) + 2 * Width() * Height() + 2 * Height() * Length(); }

public double Volume() { return Length() * Width() * Height(); }

@Override public String toString() { return " Length :" + Length() + " Width :" + Width() + " Height :" + Height() + " Area :" + calcArea() + " Volume :" + Volume()+" Point (x,y):( " + X ()+ " , "+ Y ()+ " )"; }

}

-----

public class Cylinder extends Circle { private double height; public Cylinder() { super();

this.height = 15; }

public Cylinder(double height) { this.height = height;

}

public double height() { return height; }

public void height(double height) { this.height = height; }

@Override public double Area() { return super.Area() * height; }

@Override public String toString() { return " height=" + height + super.toString(); }

-----

public class ShapesABSTester {

public static void main(String[] args) {

Point myShapes[] = new Point[4]; myShapes[0] = new Rectangle(10, 20); myShapes[1] = new Box(30); myShapes[2] = new Circle(40); myShapes[3] = new Cylinder(50);

for (int i = 0; i

if (myShapes[i] instanceof Cylinder) { System.out.println("Cylinder :" + ((Cylinder) myShapes[i]).toString());

} else if (myShapes[i] instanceof Box) { System.out.println("Box :" + ((Box) myShapes[i]).toString()); } else if (myShapes[i] instanceof Rectangle) { System.out.println("Rectangle :" + myShapes[i]); } else if (myShapes[i] instanceof Circle) { System.out.println("Cirlce :" + myShapes[i]); }

}

}

}

* Java, make 2 exception classes that will throw errors, the class notgreaterthan10exception is provided in the picture. Create the 2 classes lessthanorequaltoexception and lessthanexception

sample output of what it should do is provided.

tell me if somwthing else is needed
Instructions This program will allow us to enter data for the shapes that we have created in the previous labs. Specifically we want to enter the width, length, and height values. The width and length must be integers (whole numbers) greater than 0. Height may be 0. otherwise it must be a positive integer. Make sure that you are familiar with the example program CreateAndUseException Example from the Chapter 11 lecture notes. You may find it helpful to enter compile, and run this program. Do not forget to enter and compile the class Integer NotGreater Than 10Exception. Of course, both classes must be compiled in the same folder. To accomplish this task you will need to: 1. Create 2 exception classes that will throw errors (see the lecture notes class IntegerNotGreater Than10Exception) a. Less Than OrEqualToZeroException b. Less ThanZeroException 2. Write an executable class called InputWidthLength Height which asks the user to inputs value for three variables of type integer: height, length, width. a. Print your name, Lab number, and date as the first three lines of output. Hard-code the date...do not use the system date You will want to create two public static void methods in this class that will test the data and throw the correct exception. i. public static void less ThanOrEqualToZeroException(String myField, int myNumber throws LessThanOrEqualToZeroException public static void lessThanZeroException( String myField, int myNumber ) throws Less Than ZeroException myField is the current field that is attempting to be input, i.e. " width", "length", "height": iv. myNumber is the value that the user has input c. Input data If the user's data causes an exception your program should respond by explaining the error and asking the user to reenter the inappropriate value. Handle any exceptions which might occur. Your program should not "blow up" or crash but continue to run until all three values contain an appropriate value. iii. Do not use generic exception handling. Set up a catch block for each specific exception you encounter 1. height must be greater than or equal to zero: catch Less Than ZeroException width and length must be greater than 0: catch Less ThanOrEqualToZeroException 3. non-numeric or decimal inputs: catch InputMismatchException All three values must be input with valid data. Once all three value are entered then display a message that alerts the user to the successful input. d. Calculate and display the width to length ratio(width divided by length) 3. Sample Output All Variables Entered with Valid Data 11 12 public class IntegerNotGreaterThan1@Exception extends RuntimeException { 13 14 // no-argument constructor specifies default error message 15 public IntegerNotGreater Than10Exception() 16 { super "Input must be an integer greater than 10" ); 18 // constructor to allow customized error message public IntegerNotGreater Than 10Exception( String message ) ry 23 super(" ***** " + message + " was not greater than 10"); 26 } // end class IntegerNotGreaterThan1@Exception end C:\windows\SYSTEM32\cmd.exe +++++ +++++ ++++++ + +++ +++++ + LAB 4 SAMPLE OUTPUT ++ + + +++++++++++++++++++++ + + + + Programmer Lab 4 Tr... Catch. Wefine and Use Exception 11 January 2014 Please enter a width. Width must be an integer greater than 0. Please enter a length. Length must be an integer greater than 0. Please enter a height. Height must be an integer greater than or equal to 0. ***** All values have been accepted. ******* The width to length ratio is 0.500 Press any key to continue ... b. Width field tested with Invalid Data LAB 4 SAMPLE OUTPUT LAB 4 SAMPLE OUTPUT Programmer Lab 4 Try, Catch, Define and Use Exception 11 January 2014 Please enter a width. Width must be an integer greater than 0. **** You must enter an integer greater than 0. ***** Less Than Or EqualToZero Exception: Width Press the Enter key to continue Please enter a width. Width must be an integer greater than 0. ***** You must enter integers only. Invalid Number Format. ***** java.util.Input MismatchException ---- Press the Enter key to continue Please enter a width. Width must be an integer greater than 0. 2.1 ***** You must enter integers only. Invalid Number Format. ***** java.util.Input MismatchException ---- Press the Enter key to continue Please enter a width. Width must be an integer greater than 0. Please enter a length. Length must be an integer greater than 0. Please enter a height. Height must be an integer greater than or equal to 0. **** All values have been accepted. ***** The width to length ratio is 0.667 Press any key to continue ... Deliverables: Submit a ZIPPED FOLDER OF YOUR FILES. Please see Submit Assignments via compressed folder You must include your: 1. InputWidthLengthHeight class, 2. Less ThanOrEqualToZeroException class 3. Less ThanZeroException class

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

Students also viewed these Databases questions