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

Can you please help me with with problem. please follow all the specific insturc

ID: 3815869 • Letter: C

Question

Can you please help me with with problem. please follow all the specific insturctions, and try to make simple for a beginner in java.

Write a class called Shape that contains instance data that represents the name and number of sides of the shape. Define a constructor to initialize these values. Include mutator(setter) methods – with the this reference – for the instance data, and a toString method that returns a the shape data. Create a static variable to keep track of the number of shapes, and a static method to return the number of shapes entered. Create a driver class called ShapeTest, whose main method instantiates the objects and updates several Shape objects by prompting the user for the information.

In the Shape Class, you will need:

Two private members to store data

A static variable to store the number of shapes

One constructor, which should not accept any values during instantiation

Mutators for each private member of the class (Note: you don’t need to create accessors this time.)

A static method which returns the number of shapes

A toString method to output the information

In the ShapeTest driver, you will need:

At three Shape objects (no hardcoded info this time)

A Scanner Object to get information for all of the objects

Local variables to store information

To reference the static variable (with the updated number of shapes) in the driver

Here is some sample output:

Enter info on 3 shapes:

Enter the name of the shape: Square
Enter the number of sides: 4
Enter the name of the shape: Hexagon
Enter the number of sides: 6
Enter the name of the shape: Octagon
Enter the number of sides: 8


Here is the info you entered for the 3 shapes:
Shape: Square
No. of sides:4

Shape: Hexagon
No. of sides:6

Shape: Octagon
No. of sides:8

Explanation / Answer

HI, Please find my implementation.

Please let me know in case of any issue.

##################################

public class Shape {

  

   private int sides;

   private String name;

  

   private static int numShape;

  

   public Shape(int sides, String name) {

       this.sides = sides;

       this.name = name;

       numShape++;

   }

   public void setSides(int sides) {

       this.sides = sides;

   }

   public void setName(String name) {

       this.name = name;

   }

  

   public static int getNumberOfShapes(){

       return numShape;

   }

  

   @Override

   public String toString() {

       return "Shape: "+name+" No. of sides: "+sides;

   }

}

#############################

import java.util.Scanner;

public class ShapeTest {

   public static void main(String[] args) {

       Scanner sc = new Scanner(System.in);

       int side;

       String name;

       System.out.println("Enter info on 3 shapes: ");

       System.out.print("Enter the name of the shape: ");

       name = sc.next();

       System.out.print("Enter the number of sides: ");

       side = sc.nextInt();

       // creating first Shape

       Shape s1 = new Shape(side, name);

       System.out.print("Enter the name of the shape: ");

       name = sc.next();

       System.out.print("Enter the number of sides: ");

       side = sc.nextInt();

       // creating second Shape

       Shape s2 = new Shape(side, name);

       System.out.print("Enter the name of the shape: ");

       name = sc.next();

       System.out.print("Enter the number of sides: ");

       side = sc.nextInt();

       // creating third Shape

       Shape s3 = new Shape(side, name);

      

       System.out.println(" Here is the info you entered for the 3 shapes: ");

       System.out.println(s1);

       System.out.println(s2);

       System.out.println(s3);

   }

}

/*

Sample run:

Enter info on 3 shapes:

Enter the name of the shape: Square

Enter the number of sides: 4

Enter the name of the shape: Hexagon

Enter the number of sides: 6

Enter the name of the shape: Octagon

Enter the number of sides: 8

Here is the info you entered for the 3 shapes:

Shape: Square

No. of sides: 4

Shape: Hexagon

No. of sides: 6

Shape: Octagon

No. of sides: 8

*/