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

Hi, i need help with java, i have never user it before. design a Java class that

ID: 3118475 • Letter: H

Question

Hi, i need help with java, i have never user it before. design a Java class that includes at least 3 data fields, 2 constructors and 4 methods. When designing class, pick an object that you are familiar with and make it your own, realistic, yet simple design with reasonable data fields.

Then implement a test file that tests your Java class (in the main method you should instantiate at least two objects and call all the methods available for each object). Name your Java test file hw1test.java. Be sure your code compiles and runs as expected. Capture a screenshot of the execution in a file hw1.jpeg or hw1.gif (or another graphical format).

Explanation / Answer

public class Circle { public static final double PI = 3.14159; // A constant public double r; // An instance field that holds the radius of the circle // The constructor method: initialize the radius field public Circle(double r) { this.r = r; } // The instance methods: compute values based on the radius public double circumference() { return 2 * PI * r; } public double area() { return PI * r*r; } } When we relied on the default constructor supplied by the compiler, we had to write code like this to initialize the radius explicitly: Circle c = new Circle(); c.r = 0.25; With this new constructor, the initialization becomes part of the object creation step: Circle c = new Circle(0.25); Here are some important notes about naming, declaring, and writing constructors: The constructor name is always the same as the class name. Unlike all other methods, a constructor is declared without a return type, not even void. The body of a constructor should initialize the this object. A constructor should not return this or any other value.

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