Question: Write a class called MovableCircle that implements the Movable interface given in Lab1 problem. This class contains three int fields x, y, and r, that

Write a class called MovableCircle that implements the Movable interface given in Lab1 problem. This class contains three int fields x, y, and r, that represents the center and radius of the circle, and one constructor that takes three parameters indicating the initial x and y and radius of the point. Write the constructor and the four methods.

Note: for the MovableCircle, the size() and area() returns the radius and area of the circle,move() method shifts the circle to new position with the specified value of x & y-coordinates given by the user and the printShape prints a string on the console this is a circle at location: xx, yy, where the xx, and yy are the location x and y of the circle.

Extend the given testInterface_HW class to creates a MovablePoint object or a MovableCircle object depending on the users input.

Sample Output:

Enter 1 for movable point and 2 for movable circle. For the Lab assignment, enter only 1.

2

Enter the x coordinate of the circle as an integer

3

Enter the y coordinate of the circle as an integer

4

Enter the radius of the circle as an integer

5

Choose from one of the choices below

1. Move the graph by specifying the x and y coordinates, your graph will be moved by the specified x and y coordinate

2. Display the size of the graph

3. Display the area of the graph

4. Display the location of the graph

5. Exit the program

1

You have chosen to move the graph

Enter the x coordinate that your graph needs to be moved by

4

Enter the y coordinate that your graph needs to be moved by

5

The graph has been moved by 4,5

Choose from one of the choices below

1. Move the graph by specifying the x and y coordinates, your graph will be moved by the specified x and y coordinate

2. Display the size of the graph

3. Display the area of the graph

4. Display the location of the graph

5. Exit the program

4

This is a circle at the location: 7,9

Choose from one of the choices below

1. Move the graph by specifying the x and y coordinates, your graph will be moved by the specified x and y coordinate

2. Display the size of the graph

3. Display the area of the graph

4. Display the location of the graph

5. Exit the program

2

The size of the graph is 5.0

Choose from one of the choices below

1. Move the graph by specifying the x and y coordinates, your graph will be moved by the specified x and y coordinate

2. Display the size of the graph

3. Display the area of the graph

4. Display the location of the graph

5. Exit the program

3

The area of the graph is 78.53981633974483

Choose from one of the choices below

1. Move the graph by specifying the x and y coordinates, your graph will be moved by the specified x and y coordinate

2. Display the size of the graph

3. Display the area of the graph

4. Display the location of the graph

5. Exit the program

5

You have successfully exited the program

-----------------------------------------------------

import java.util.Scanner;

public class testInterface_HW {

private static MovableGraph graph; private static Scanner input = new Scanner(System.in);

public static void displayGraphOptions() { System.out.println("Choose from one of the choices below"); System.out.println( "1. Move the graph by specifying the x and y coordinates, your graph will be moved by the specified x and y coordinate"); System.out.println("2. Display the size of the graph"); System.out.println("3. Display the area of the graph"); System.out.println("4. Display the location of the graph"); System.out.println("5. Exit the program"); executeGraphOptions(input.nextInt()); } public static void executeGraphOptions(int choice) {

switch (choice) { case 1: { System.out.println("You have chosen to move the graph"); System.out.println("Enter the x coordinate that your graph needs to be moved by"); int xMov = input.nextInt(); System.out.println("Enter the y coordinate that your graph needs to be moved by"); int yMov = input.nextInt(); graph.move(xMov, yMov); System.out.println("The graph has been moved by "+xMov+","+yMov); displayGraphOptions(); break; } case 2: { System.out.println("The size of the graph is " + graph.size()); displayGraphOptions(); break; } case 3: { System.out.println("The area of the graph is " + graph.area()); displayGraphOptions(); break; } case 4: { graph.printShape(); displayGraphOptions(); break; } case 5: { System.out.println("You have successfully exited the program"); System.exit(1); break; } default: { System.out.println("Invalid choice, Please choose again"); displayGraphOptions(); } } }

public static void main(String[] args) { // TODO Auto-generated method stub System.out.println("Enter 1 for movable point and 2 for movable circle. For the Lab assignment, enter only 1."); int choice = input.nextInt(); if (choice == 1) { System.out.println("Enter the x coordinate of the Point as an integer"); int x = input.nextInt(); System.out.println("Enter the y coordinate of the Point as an integer"); int y = input.nextInt(); graph = new MovablePoint(x, y); displayGraphOptions(); } else if (choice == 2) { //Add java code -- for the takehome assignment } }

}

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!