Question

JAVA you will design and write a class that represents a real-world object of your choice....

JAVA

you will design and write a class that represents a real-world object of your choice. In the second part, you will write a program that demonstrates the use of the class.

Part I:

Select a "real-world" object that has not been used in class lecture and/or the textbook.

The object you choose must be defined by at least:

Have at least two characteristics (attributes).

Have at least two behaviors (operations).

The class that you write to represent the object must minimally meet the requirements of:

The "data" part must declare the attributes correctly.

The "operations" part must include at least the following methods:

A no-arg constructor method that creates an object with reasonable defaults for the initial state.

The set and get methods for each attribute.

Two methods that appropriately carry out the behaviors identified in the design.

Bonus (10 points) : A constructor that takes the initial values for the object's attributes from the user rather than setting defaults.

Part II: Write a "client" class that demonstrates the use of the object. Examples from class: RectangleDemo class & CircleDemo.

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

package demo;

import java.util.Scanner;

class Shape {
private int length;
private int bredth;

public Shape(int length,int bredth)
{
this.bredth=bredth;
this.length=length;
}

public int getArea()
{
return length*bredth;
}

public int getPerimeter()
{
return 2*(length+bredth);
}

}
class RectangleDemo extends Shape
{
private int length;
private int bredth;

public int getArea()
{
return length+bredth;
}

public int getPerimeter()
{
return 2*(length+bredth);
}
public RectangleDemo(int length, int bredth) {
super(length, bredth);
this.bredth=bredth;
this.length=length;
}
}

class CircleDemo extends Shape
{
private int length;
private int bredth;

public int getArea()
{
return length*bredth;
}

public int getPerimeter()
{
return 2*(length+bredth)/2;
}
public CircleDemo(int length, int bredth) {
super(length, bredth);
this.bredth=bredth;
this.length=length;
}
}

public class DemoClasses{
public static void main(String[] args) {
Scanner scan=new Scanner(System.in);

System.out.println("enter the length");
int len=scan.nextInt();
System.out.println("enter the bredth");
int bred=scan.nextInt();

Shape rect=new RectangleDemo(len, bred);
Shape cir=new CircleDemo(len, bred);

System.out.println("area of rectangle "+rect.getArea());
System.out.println("perimeter of rectangle "+rect.getPerimeter());
System.out.println("area of circle "+cir.getArea());
System.out.println("perimeter of circle "+cir.getPerimeter());
}

}

Add a comment
Know the answer?
Add Answer to:
JAVA you will design and write a class that represents a real-world object of your choice....
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 - Object Oriented Programming Declare a class named Customer that has two private fields? Write...

    Java - Object Oriented Programming Declare a class named Customer that has two private fields? Write a set method to make sure that if age > 125 years or less than 0 then it is set to 0 (default value) What does it indicate when declaring a class's instance variables with private access modifier? What is the role of a constructor? The data part of by an object's instance variables is known as? Do all methods have to always return...

  • in java need to review 20) (1 point) Write the constructor for the class Customer, which...

    in java need to review 20) (1 point) Write the constructor for the class Customer, which has the name and the ID of the Customer and a reference to an Account object as its attributes. You do not need to write anything for Account class or declare the Customer class's attributes, just write the constructor.

  • In JAVA, please In this module, you will combine your knowledge of class objects, inheritance and...

    In JAVA, please In this module, you will combine your knowledge of class objects, inheritance and linked lists. You will need to first create an object class encapsulating a Trivia Game which INHERITS from Game. Game is the parent class with the following attributes: 1. description - which is a string 2. write the constructor, accessor, mutator and toString methods. Trivia is the subclass of Game with the additional attributes: 1. trivia game id - integer 2. ultimate prize money...

  • When answering this question, can you please specify what you name your files? Thank you! Write a...

    When answering this question, can you please specify what you name your files? Thank you! Write a Java application, and an additional class to represent some real-world entity. Keep in mind that a class is a model in code of something real or imagined, which has attributes (member variables) and behaviors (member methods). The class will: a. Create a total of 5 member variables for the class, selecting the appropriate data types for each field. For example, a class to...

  • IN JAVA Goals The primary goal of this lab is to write, test and complete a...

    IN JAVA Goals The primary goal of this lab is to write, test and complete a program with multiple classes, where you have designed and implemented those classes. You will also code and use methods and at tributes. This program will have an interactive behavior. This will reinforce the need for good design and creating and using new classes. The lab will build a rudimentary chat system to reinforce the concept ofc objects. betweern 1. Design a Person class. 2....

  • write in java and please code the four classes with the requirements instructed You will be...

    write in java and please code the four classes with the requirements instructed You will be writing a multiclass user management system using the java. Create a program that implements a minimum of four classes. The classes must include: 1. Employee Class with the attributes of Employee ID, First Name, Middle Initial, Last Name, Date of Employment. 2. Employee Type Class that has two instances of EmployeeType objects: salaried and hourly. Each object will have methods that calculates employees payrol...

  • In C++ Write a program that contains a BankAccount class. The BankAccount class should store the...

    In C++ Write a program that contains a BankAccount class. The BankAccount class should store the following attributes: account name account balance Make sure you use the correct access modifiers for the variables. Write get/set methods for all attributes. Write a constructor that takes two parameters. Write a default constructor. Write a method called Deposit(double) that adds the passed in amount to the balance. Write a method called Withdraw(double) that subtracts the passed in amount from the balance. Do not...

  • Write a code in java by considering the following conditions. Task :- 1. Design, implement and test a class RationalNumber. 2. Your class must have a constructor. 3. Your class must implement an inter...

    Write a code in java by considering the following conditions. Task :- 1. Design, implement and test a class RationalNumber. 2. Your class must have a constructor. 3. Your class must implement an interface Number that has methods to perform different operations on a rational numbers (addition, subtraction, reciprocal, multiplication and division). 4. Also design some methods to check whether two rational numbers are same or not (consider numbers are in reduced form). 5. You must develop an appropriate GUI...

  • Part I: (The Myate class) Design a class named MyDate. The class contains: • The data...

    Part I: (The Myate class) Design a class named MyDate. The class contains: • The data fields year, month, and day that represent a date. Month is 0-based, i.e., 0 is for January. • A no-arg constructor that creates a MyDate object for the current date. • A constructor that constructs a MyDate object with a specified elapsed time since midnight, January 1, 1970, in milliseconds. • A constructor hat constructs a MyDate object with the specified year, month, and...

  • Java Eclipse Coding question: Use data abstraction (real-world modeling) to come up with 3 instance variables...

    Java Eclipse Coding question: Use data abstraction (real-world modeling) to come up with 3 instance variables and 2 effectors for a new data type – the class HospitalPatient. You have the freedom to design the instance variables and effectors. instance variables effectors 1. 1. 2. 2. 3. Write the code for class HospitalPatient, according to the requirement above. Include the default constructors with no argument, and the constructor with all arguments. Provide a getter and setter for each individual instance...

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