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

more information for question i just post 20mins ago. i didn\'t known how to edi

ID: 3601876 • Letter: M

Question

more information for question i just post 20mins ago. i didn't known how to edit it, so just post new one...

HEPT me please ...thanks

1. Write an interface called MovableGraph with four void methods a. public void move(int x, int y) b. public double size() c. public double area() d. public void printShape()

Write a class called MovablePoint that implements the MovableGraph interface above. This class contains two intfields x and y, and one constructor that takes two parameters indicating the initial x and y of the point.Write the constructor and the four methods.

Note: for the MovablePoint, the size() and area() returns 0, move() method shifts the point 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 point at location: xx, yy”, where the xx, and yy are the location x and y of the point. Use the testInterface_Lab class to test your code.

Sample Output: Enter the x coordinate of the Point as an integer

2

Enter the y coordinate of the Point as an integer

3

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

3

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

4

The graph has been moved by 3,4

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 point at location:5,7

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 0.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 0.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

5 You have successfully exited the program

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

import java.util.Scanner;

public class testInterface_Lab {

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

}

Explanation / Answer

Please do give this a upvote the program gives the output as requested

//interface

public interface MovableGraph {

public void move(int x, int y);

public double size();

public double area();

public void printShape();

}

//MovablePoint Class

public class MovablePoint implements MovableGraph{

private int x;

private int y;

public MovablePoint(int x, int y) {

this.x = x;

this.y = y;

}

@Override

public void move(int x, int y) {

this.x = x;

this.y = y;

}

@Override

public double size() {

return 0;

}

@Override

public double area() {

return 0;

}

@Override

public void printShape() {

System.out.println("This is a point at location:"+this.x+","+this.y);

}

}

//Test class

import java.util.Scanner;
public class Main {
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 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();
  
  
}
}