Question

Can you please help me with with problem. please follow all the specific insturctions, and try...

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

0 0
Add a comment Improve this question Transcribed image text
Answer #1

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+"\nNo. 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("\nHere 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

*/

Add a comment
Know the answer?
Add Answer to:
Can you please help me with with problem. please follow all the specific insturctions, and try...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • JAVA :The following are descriptions of classes that you will create. Think of these as service...

    JAVA :The following are descriptions of classes that you will create. Think of these as service providers. They provide a service to who ever want to use them. You will also write a TestClass with a main() method that fully exercises the classes that you create. To exercise a class, make some instances of the class, and call the methods of the class using these objects. Paste in the output from the test program that demonstrates your classes’ functionality. Testing...

  • Java Program (PLEASE PROVIDE SCREENSHOT OF THE CODE) Create a class Person which is a super...

    Java Program (PLEASE PROVIDE SCREENSHOT OF THE CODE) Create a class Person which is a super class. The class includes four private String instance variables: first name, last name, social security number, and state. Write a constructor and get methods for each instance variable. Also, add a toString method to print the details of the person. After that create a class Teacher which extends the class, Person. Add a private instance variable to store number of courses. Write a constructor...

  • Here is a sample run of the tester program: Make sure your program follows the Java...

    Here is a sample run of the tester program: Make sure your program follows the Java Coding Guidelines. Consider the following class: /** * A store superclass with a Name and Sales Tax Rate */ public class Store {      public final double SALES_TAX_RATE = 0.06;      private String name;           /**      * Constructor to create a new store      * @param newName      */      public Store(String newName)      {           name = newName;      }     ...

  • In a project named 'DogApplication', create a class called 'Dog' 1. declare two instance variables in...

    In a project named 'DogApplication', create a class called 'Dog' 1. declare two instance variables in 'Dog' : name (String type) age (int type) 2. declare the constructor for the 'Dog' class that takes two input parameters and uses these input parameters to initialize the instance variables 3. create another class called 'Driver' and inside the main method, declare two variables of type 'Dog' and call them 'myDog' and 'yourDog', then assign two variables to two instance of 'Dog' with...

  • This is for Java Programming Please use comments Customer and Employee data (15 pts) Problem Description:...

    This is for Java Programming Please use comments Customer and Employee data (15 pts) Problem Description: Write a program that uses inheritance features of object-oriented programming, including method overriding and polymorphism. Console Welcome to the Person Tester application Create customer or employee? (c/e): c Enter first name: Frank Enter last name: Jones Enter email address: frank44@ hot mail. com Customer number: M10293 You entered: Name: Frank Jones Email: frank44@hot mail . com Customer number: M10293 Continue? (y/n): y Create customer...

  • N-Sided Polygon An n-sided polygon is a planed figure whose sides have the same length and...

    N-Sided Polygon An n-sided polygon is a planed figure whose sides have the same length and whose angles have the same degree. Write a class called NSidedPolygon that contains the following components: Private members to store the name of a polygon, the number of sides, and the length of each side. (You are expected to select the appropriate data types for each member.) A constructor that accepts the number of sides and the length of each side. A private method...

  • Java Question 3 Implement a program to store the applicant's information for a visa office. You...

    Java Question 3 Implement a program to store the applicant's information for a visa office. You need to implement the following: A super class called Applicant, which has the following instance variables: A variable to store first name of type String. A variable to store last name of type String. A variable to store date of birth, should be implemented as another class to store day, month and year. A variable to store number of years working of type integer...

  • Anyone helps me in a Java Languageif it it is possible thanks. Write a class called...

    Anyone helps me in a Java Languageif it it is possible thanks. Write a class called Player that holds the following information: Team Name (e.g., Ravens) . Player Name (e.g., Flacco) . Position's Name (e.g. Wide reciver) . Playing hours per week (e.g. 30 hours per week). Payment Rate (e.g., 46 per hour) . Number of Players in the Team (e.g. 80 players) . This information represents the class member variables. Declare all variables of Payer class as private except...

  • Hello. I need help writing the following Java Program. Thank you Develop a class encapsulating the...

    Hello. I need help writing the following Java Program. Thank you Develop a class encapsulating the concept of a college course, assuming that a course has following attributers: code (for instance COSC1337), a description, and a number of credits (for instance 3). Include a constructor, the accessors, mutators and methods ‘toString’, ‘equals’, and ‘finalize’. Write a client class to test the behavior of the class and its methods. The outline of the class is given as follows: public class Course...

  • In Java Code Needed is Below the Question Using Program 3: Encapsulating Dogs, modify this program...

    In Java Code Needed is Below the Question Using Program 3: Encapsulating Dogs, modify this program to create a database of dogs of your own. You will also include File I/O with this program. You will create 3 classes for this assignment. The first class: Create a Class representing the information that is associated with one item (one dog) of your database. Name this class Dog. Using Lab 3, this will include the information in regard to one dog. The...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT