Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Here is the link for part 1 post: http://www.chegg.com/homework-help/questions-a

ID: 3648848 • Letter: H

Question

Here is the link for part 1 post:
http://www.chegg.com/homework-help/questions-and-answers/5-parts-program-i-posting-separate-chance-earn-points-respond-post-garbage-code-thank-1-mo-q2848766

Here is the link for part 2 post:
http://www.chegg.com/homework-help/questions-and-answers/link-1-post-http-wwwcheggcom-homework-help-questions-answers-5-parts-program-i-posting-sep-q2848776

Here is the link for part 3 post:
http://www.chegg.com/homework-help/questions-and-answers/link-1-post-http-wwwcheggcom-homework-help-questions-answers-5-parts-program-i-posting-sep-q2848788?user_id=14180834&timestamp=1347376244&multiPartWarningResponse=ask&question_id=2848788

Part 4: Driver class

Create a driver class that tests objects of classes Ellipse, and Circle. It should allow the user to select whether they want to construct a Circle, Ellipse, or GeometricObject. It should then ask the user the appropriate questions to create the object of the desired type.

Use JOptionPanes for input. You should all be familiar with the JOptionPane.showInputDialog(...) method that opens a text box. However, there are some other useful JOptionPane methods. I list them below, with code examples for you to experiment with:
Fun with JOptionPanes

The following code is an example of the use of dropdown menus. This particular code is a subset of the infamous "select your state" code that you see on all sorts of web sites. This one defaults to Minnesota.

Object[] stateList = { "Minnesota", "Iowa", "North Dakota", "South Dakota", "Wisconsin"};

String state = (String)JOptionPane.showInputDialog(null, "Please select your state:", "State", JOptionPane.PLAIN_MESSAGE, null, stateList, "Minnesota");

The following code puts up a box that allows you to select Yes or No.

Object[] options = {"Yes", "No"};

int answer = JOptionPane.showOptionDialog( null,

"Make a Decision",

"Decision", JOptionPane.YES_NO_OPTION,

JOptionPane.QUESTION_MESSAGE, null, options, null );

Explanation / Answer

Thsi just creates the objects and doesn't actually manipulate them or use the area/perimeter methods. It didn't specifically say to do that, so I decided not to bother.... import javax.swing.*; public class Driver { /** * @param args */ public static void main(String[] args) { Object[] objectList = {"Geometric Object", "Ellipse", "Circle"}; GeometricObject gO; Ellipse e; Circle c; String objectType = (String)JOptionPane.showInputDialog(null, "Please select your object type:", "Object", JOptionPane.PLAIN_MESSAGE, null, objectList, "Geometric Object"); char choice = objectType.charAt(0); String color = ""; switch (choice) { case 'G': Object[] colorList = { "Red", "Blue", "Green", "Yellow"}; color = (String)JOptionPane.showInputDialog(null, "Please select your Color:", "Color", JOptionPane.PLAIN_MESSAGE, null, colorList, "Red"); Object[] options = {"Yes", "No"}; int answer = JOptionPane.showOptionDialog( null, "Would you like your Geometric Object to be filled?", "Fill", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, null ); gO = new GeometricObject(color, (answer==1)); break; case 'E': double a = Double.parseDouble(JOptionPane.showInputDialog("What would is half the length of the major axis of the ellipse?")) ; double b = Double.parseDouble(JOptionPane.showInputDialog("What would is half the length of the minor axis of the ellipse?")) ; e = new Ellipse(a,b); break; case 'C': double r = Double.parseDouble(JOptionPane.showInputDialog("What would is the radius of the circle?")) ; c = new Circle(r); break; } //ADD stuff here if you need to call methods for area/perimeter and/or display them...it wasn't specified in the problem, so I didn't bother } }