Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

shapes classes are at the bottom and the top ones are the two examples referenced Instructions This program will allow us to enter data for

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

shapes classes are at the bottom and the top ones are the two examples referenced

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 Create AndUseException 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 Than 10Exception) a. Less Than OrEqualToZeroException b. Less ThanZeroException 2. Write an executable class called InputWidth Length 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 b. You will want to create two public static void methods in this class that will test the data and throw the correct exception. 1. public static void less ThanOrEqualToZeroException(String myField, int myNumber throws Less ThanOrEqualToZeroException 11. public static void less ThanZeroException( String myField, int myNumber) throws Less ThanZeroException iii. 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. 111. 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 ThanZeroException 2. width and length must be greater than 0: catch Less ThanOrEqualToZeroException 3. non-numeric or decimal inputs: catch InputMismatchException iv. 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 a. 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) { System.out.println("+++++++++++++ System.out.println("++ System.out.println("++ Chapter 11 Example System.out.println(" + System.out.println("+++++++ ++++ "); System.out.println(" System.out.println(" System.out.println(" 29 30 Scanner reader = new Scanner(System.in); int myllumberGreater Than 10 = 0; //user input dot //loop until an integer greater than 10 is entered try{ System.out.println(" Please enter an inteeer ereater than 10. "); try{ System.out.println(" Please enter an integer greater than 10. "); myllumberGreater Than 10 = reader.nextInt(); integerGreater Than 10(" Your Number: "mylumberGreater Thanie ); /method to check input break; } end try 1/process improperly formatted input catch (Integerlot Greater Than 10Exception myException ) { System.out.println(" **** You must enter an integer that is greater than 10 ". ****** myException."n"); 1/process if non-numeric or non integer data is entered catch (Input MismatchException myException) System.out.println(" **** You must enter integers only. Invalid Number Format. In". ****** Exception + " "); reader.nextLine(); //clears the input stream while(true); end of wile loop when the input meet the criteria System.out.println(" Your input of " sylumberGreater Than 10. " has been accepted. "); System.out.println("Thank you for using this software"); lend sain method Exceptions HUVULP + 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 " + myNumberGreater Than 10 + " has been accepted. "); System.out.println("Thank you for using this software"); }//end main method //method to test input //if input is not greater than 10 then //an exception will be thrown public static void integerGreater Than10( String myField, int myNumber ) throws IntegerHotGreater Than 10Exception if (myllumber ( 10 ) myField - myField +""+ myNumber; throw new IntegerlotGreater Than1eException(myField); :) lend class Create AlduseExceptionExample 11 212 public class IntegerNotGreater Than1@Exception extends RuntimeException { 13 14 // no-argument constructor specifies default error message 15 public IntegerNotGreater Than1Exception() super( "Input must be an integer greater than 10" ); 210 Il constructor to allow customized error message public Integer NotGreater Than1eException( String message ) super( " *****" + message + " was not greater than 10"); 26 } // end class Integerllot Greater Than 10Exception 27 ClassCircle.java - Notepad File Edit Format View Help 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(); ClassRectangle.java - Notepad ale Edit Format View Help ublic 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(); Class Cylinderjava - Notepad File Edit Format View Help 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 hei this.height - height; @Override ride public double Area() { return super. Area @Override public String toString() { return " height=" + height + super.toString(); public abstract class Point private int y; private int x; public Point() { this.y - B; 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 XO { return x; public void X(int x) { this.x - X; @Override public String toString() { return" Point (x, y): (-+*+ + y + )"; public abstract double calcArea(); 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 ()+")

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

Recommended Textbook for

Database Concepts

Authors: David Kroenke

4th Edition

0136086535, 9780136086536

More Books

Students also viewed these Databases questions

Question

Discuss essential concepts of family therapy.

Answered: 1 week ago

Question

Explain how SIHRM is linked to different global business strategies

Answered: 1 week ago