Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java, shapes classes are here, 2 others in pictures. public abstract class Point { private int y; private int x; public Point() { this.y =

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

Java, shapes classes are here, 2 others in pictures.

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(); }

}

please complete the lab with the info provided
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 3 import java.util.InputMismatchException; import java.util.Scanner; 6 public class CreateAndUseExceptionExample{ public static void main(String[] args) { 9 System.out.println(" + System.out.println(" ++ System.out.println("++ Chapter 11 Example System.out.println("++ System.out.println("++ 22 23 "); 24 25 26. System.out.println(" System.out.println(". System.out.println( 27 28 29 30 31 32 33 Scanner reader = new Scanner(System.in); int myNumberGreaterThan10 = 0; //user input do{ //loop until an integer greater than 10 is entered try{ System.out.println(" Please enter an inteeer ereater than 10. "): 34 try{ System.out.println(" Please enter an integer greater than 10. "); myllumberGreater Than 10 = reader.nextInt(); integerGreateifThan10(" Your Number: ", my NumberGreater Than10 ); //method to check input break; } //end try //process improperly formatted input catch (IntegerNotGreater Than 10Exception myException ) { System.out.println(" **** You must enter an integer that is greater than 10 " + ****** * + myException + " "); //process if non-numeric or non integer data is entered catch (InputMismatchException myException ) { System.out.println(" ***** You must enter integers only. Invalid Number Format. " + ****** * + myException + " "); reader.nextLine(); //clears the input stream } while(true); //end of wile loop when the input meet the criteria System.out.println(" Your input of " + myNumberGreater Thante + " has been accepted. "); System.out.println("Thank you for using this software"); }//end main method System.out.println(" ***** You must enter integers only. Invalid Number Format. In + ****** " + myException + " "); reader.nextLine(); //clears the input stream }while(true); //end of wile loop when the input meet the criteria System.out.println(" Your input of " + my NumberGreater Than 10 + " has been accepted. "); System.out.println("Thank you for using this software"); }//end main method //method to test input 1/if input is not greater than 10 then //an exception will be thrown public static void integerGreater Than10( String myField, int myNumber ) throws IntegerNotGreater Than10Exception if ( myNumber

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