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

Hello my Chegg friends, can someone give me a little help with the below problem

ID: 3857140 • Letter: H

Question

Hello my Chegg friends, can someone give me a little help with the below problem, if there is one. The book for the class is Introduction to Java Programming, Comprehensive Version Y. Daniel Liang & Prentice Hall 11th Edition / 2018. We are currently working in Chapter 10. This chapter covers the following:

• Class Abstraction

• Encapsulation

• Class Relationships

• Object-Oriented Paradigm

• Primitive/Wrapper Class Conversions

• String Class

I tried doing this earlier, but my instructor gave me his below comments. I need to know line of code the errors are on. Please Help.

Here are your hints. Main has one issue. Think variable "type" that may be missing. The subclass methods have 3 issues. Again, one is a "type" issue. The other two issues: Can the main class even see these methods?

We have a subclass Circle() in our project. It is instantiated as an object, myCircle(). In myCircle, we have a get and set method to determine the area as such:

1.

2. //Set the area

3. private void setArea(double r){

4.     area = r * r * Math.PI;

5. }

6.

7. //Return the area

8. private double getArea(){

9.     return area;

10. }

In the main class, we are calling the set and get methods as such:

1.

2. //Create a Circle object

3. Circle myCircle = new Circle();

4.

5. System.out.print("Enter a radius: ");

6. radius = sc.nextDouble();

7. myCircle.setArea(radius);

8. System.out.printf("The area of this circle is: %.2f ",myCircle.getArea());

9.

What is wrong with this code (if anything)? Will it work? If not, how could it be fixed?

***Note: Assume the scanner object has been created

Explanation / Answer

Circle.java

public class Circle {

private double area;

public Circle() {

}

public void setArea(double r) {
area = r * r * Math.PI;
}

// Return the area
public double getArea() {
return area;
}
}

__________________

Main.java

import java.util.Scanner;

public class Main {

public static void main(String[] args) {
double radius;

// Creating a Scanner class object
Scanner sc = new Scanner(System.in);

// Create a Circle object
Circle myCircle = new Circle();

System.out.print("Enter a radius: ");
radius = sc.nextDouble();
myCircle.setArea(radius);
System.out.printf("The area of this circle is: %.2f ",
myCircle.getArea());

}

}

_______________________

Output:

Enter a radius: 5.5
The area of this circle is: 95.03


_____________Could you rate me well.Plz .Thank You

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote