Question: Using this code, create a UML diagram: GeomtryDemo.java /* * To change this license header, choose License Headers in Project Properties. * To change this

Using this code, create a UML diagram:

GeomtryDemo.java

/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package geometrydemo;

import java.text.DecimalFormat; import java.util.Scanner;

public class GeometryDemo {

/** * @param args the command line arguments */ public static void main(String[] args) { // declare variables int choice; double radius; double width; double length; double base; double height; //Scanner object for keyboard input Scanner keyboard = new Scanner(System.in); //Since we are dealing with numbers, decimals must be formatted DecimalFormat form = new DecimalFormat("##.###"); while (true) { System.out.println("Geometry Calculator"); System.out.println(" 1. Calculate the area" + " of circle"); System.out.println(" 2. Calculate the area" + " of rectangle"); System.out.println(" 3. Caclulate the area" + " of triangle"); System.out.println(" 4. Quit"); System.out.println(); System.out.print("Enter your choice (1-4):" + ""); //since there is a choice being made, the choice has to be read choice = keyboard.nextInt(); switch (choice) { // I am doing a switch/case/break statement to find the // area of the cirlce using the circlesArea case 1: System.out.print("Enter the radius of the" + " circle "); radius = keyboard.nextDouble(); System.out.println(" Area of circle " + form.format(Geometry.circlesArea(radius))); break; // The second case is added to prompt user to enter length and // width of a rectangle by using the static rectanglesArea case 2: System.out.print("Enter the length of the" + " rectangle "); length = keyboard.nextDouble(); System.out.print("Enter the width of the" + " rectangle "); width = keyboard.nextDouble(); System.out.println("Area of rectangle " + form.format(Geometry.rectanglesArea(length,width))); break; // The third case is to prompt the user to input the base // and height of the triangle using the static // trianglesArea case 3: System.out.print("Enter the base of the " + " triangle "); base = keyboard.nextDouble(); System.out.print("Enter the height of the " + " triangle "); height = keyboard.nextDouble(); System.out.println("Area of triangle " + form.format(Geometry.trianglesArea(base, height))); break; // assign a case to #4 to close the program case 4: System.exit(0); break; // case 5 is to display an error message if user // enters invalid numbers case 5: System.out.println("You have selected" + "an out of range." + " Please" + "select your choice in" + "1-4 range" ); } System.out.println(); } } Geometry.java class code:

package geometrydemo;

/** * * */ class Geometry { public static double circlesArea(double circle_radius) { if (circle_radius<0) { errorMessage("circle's radius"); return 0; } else { return Math.PI * circle_radius * circle_radius; } } public static double rectanglesArea(double rectangle_length, double rectangle_width) { if (rectangle_length<0 || rectangle_width<0) { errorMessage("rectangle's length or" + " width"); return 0; } else { return rectangle_length * rectangle_width; } } public static double trianglesArea(double tri_base, double tri_height) { if (tri_base<0 || tri_height<0) { errorMessage(" triangle's base or height" ); return 0;

} else { return tri_base * tri_height * 0.5; } } private static void errorMessage(String circles_radius) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!