Question

As an academic student, your number one tool to help you achieve your degree is your...

As an academic student, your number one tool to help you achieve your degree is your computer. Using object-oriented analysis, what class and what two subclasses could you think of for your computer? Also, think of one attribute for each of the subclasses. Explain why you selected the two subclasses and the attributes.

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

Note : Could you please check the output .If you required any changes Just intimate.I will modify it.Thank You.

===========================================

I choosed two Sub classes named Circle, Square class which will calculate the area of that Shape

Based on the shape tyep I choosed radius for Circle and Side for Square.

===========================================

Shape.java

public abstract class Shape {

//Declaring instance variables

private String type;

//Parameterized constructor

public Shape(String type) {

super();

this.type = type;

}

//Abstract method

public abstract double getArea();

  

//toString method is used to display the contents of an object inside it

@Override

public String toString() {

return "Shape : type =" + type ;

}

  

}

___________________

Circle.java

public class Circle extends Shape {

//Declaring instance variables

private double radius;

  

//Parameterized constructor

public Circle(double radius) {

super("Circle");

this.radius = radius;

}

//getters and setters

public double getRadius() {

return radius;

}

public void setRadius(double radius) {

this.radius = radius;

}

//This method will calculate the area of the Circle

@Override

public double getArea() {

return Math.PI*radius*radius;

}

//toString method is used to display the contents of an object inside it

@Override

public String toString() {

return super.toString()+" Radius=" + radius +" Area = "+getArea();

}

}

____________________

Square.java

public class Square extends Shape {

//Declaring instance variables

private double side;

//Parameterized constructor

public Square(double side) {

super("Square");

this.side = side;

}

// getters and setters

public double getSide() {

return side;

}

public void setSide(double side) {

this.side = side;

}

//This method will calculate the area of the Square

@Override

public double getArea() {

return side * side;

}

//toString method is used to display the contents of an object inside it

@Override

public String toString() {

return super.toString() +" Side="+side+ ", Area = " + getArea();

}

}

_____________________

ShapeMain.java

public class ShapeMain {

public static void main(String[] args) {

//Creating an Shape class Array

Shape shapes[]={new Circle(5),new Square(5)};

//Displaying the info of each Shape object

for(int i=0;i<shapes.length;i++)

{

System.out.println(shapes[i]);

}

}

}

____________________

Output:

Shape : type =Circle Radius=5.0 Area = 78.53981633974483
Shape : type =Square Side=5.0, Area = 25.0

________________Thank YOu

Add a comment
Know the answer?
Add Answer to:
As an academic student, your number one tool to help you achieve your degree is your...
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
  • Use Java and please try and show how to do each section. You are creating a 'virtual pet' program...

    Use Java and please try and show how to do each section. You are creating a 'virtual pet' program. The pet object will have a number of attributes, representing the state of the pet. You will need to create some entity to represent attributes in general, and you will also need to create some specific attributes. You will then create a generic pet class (or interface) which has these specific attributes. Finally you will make at least one subclass of...

  • A) Please implement a Python script to define a student class with the following attributes (instance...

    A) Please implement a Python script to define a student class with the following attributes (instance attributes): cwid: student’s CWID first_name : student’s first name last_name: student’s last name gender: student’s gender gpa: student’s gpa Please make these attributes as private ones so they have to be accessed via getter/setter methods or property. For this purpose, please define a getter/setter method and property for each of the attributes. Another thing you need to do is to define a constructor that...

  • Please help Describe how a new laptop would assist you in achieving your academic goals? If...

    Please help Describe how a new laptop would assist you in achieving your academic goals? If you already have a computer, please explain how a new computer would help you in your program.

  • Please help Can you help me writing 400 words to answer this question What are your specific academic goals of nursing d...

    Please help Can you help me writing 400 words to answer this question What are your specific academic goals of nursing degree? Describe your current or planned field of study at Seattle central college and why did you choose this field? Do you have academic plans after Seattle central college?

  • Problem 1: There are 8 males and 12 females in a class. If one student is...

    Problem 1: There are 8 males and 12 females in a class. If one student is chosen at random, what is the probability a female student is selected? Problem 2: From the class described in the previous question (8 males, 12 females) how many ways are there to line up 5 students (regardless of gender)? Problem 3:The following college degrees were awarded at a university in a recent academic year:    Bachelor’s Master’s    Doctorate Men:    307 138 84...

  • Using Python: Par 1. You will define Student class with the following attributes: CWID: the student’s...

    Using Python: Par 1. You will define Student class with the following attributes: CWID: the student’s CWID FirstName: the student’s first name LastName: the student’s last name Gender: the student’s gender (‘M’ or ‘F’) BirthDate: the student’s date of birth (e.g. ‘03/14/1999’) ClassID: the class id that the student took ClassDate: the date when the student took the class (e.g. ‘01/26/2018’) Grade: the student’s grade for the class In addition, you will do the following tasks: Implement a set of...

  • Java is an object-oriented programming language that enables us to define classes and to instantiate them...

    Java is an object-oriented programming language that enables us to define classes and to instantiate them into objects. These objects then call each other’s methods to implement the behavior of the application. The Unified Modeling Language (UML) is an object-oriented visual notation to document the design of object-oriented classes. For this discussion, you will practice designing a Java class called Course, drawing a UML class diagram for the Course class, and then implementing the Course class in Java code. Review...

  • share one or two examples of challenges you have encountered communicating in the online environment. What...

    share one or two examples of challenges you have encountered communicating in the online environment. What do you think caused those challenges? In what ways does formal communication (such as academic or professional) differ from informal communication that you have with friends or family? What resources available to you as a student at the University would be most useful to help improve your academic communication? Share which activities or resources were most meaningful to you this week. What resources or...

  • You take out student loans to help pay for your degree at a 5% annual interest...

    You take out student loans to help pay for your degree at a 5% annual interest rate. Assume the bank expected inflation to average 3% per year. What real interest rate did they expect to earn from your loan? What happens if inflation is actually 5% per year? Who is better off if inflation is higher than expected? What if it is lower than expected? Why?

  • Can you name three technological tools that meet the following requirement? P.S. You don't need to write anything. Technology Review Overview Find a technological tool designed to help students l...

    Can you name three technological tools that meet the following requirement? P.S. You don't need to write anything. Technology Review Overview Find a technological tool designed to help students learn, understand, or complete a geometric concept or procedure. This tool could be a tool, activity, applet, or manipulative used on a computer, on a calculator, on a cell phone, or on a tablet. A tool alone cannot foster geometric reasoning; it takes an activity also. So, you are to review...

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