Pls i need help with these 2 Java Questions
1. Describe in detail (i.e., line for line) what the following piece of code does.
class Cube {
int side;
}
_________________________________________
class MainCube {
public static void main(String[] args) {
Cube c = new Cube();
c.side = 10;
System.out.println(“side is “ + c.side);
}
}
2. Circle
Design a Circle class which is described by the length of its radius
Design a method that calculates the total surface area of the circle.
- Equation: Pi * radius * radius
Design a method that calculates the circumference of the circle.
- Equation: 2 * Pi * radius
(Note: Put the design of the class and methods on paper – to be handed up)
Implement the Circle using a java class, i.e. Circle.java
Write a MainCircle.java class which
- Instantiates a new Circle instance,
- Reads in the length of circle’s radius.
- Assigns the value of the radius to the instance variable
- Uses the Circle methods to print the area and circumference to the console.
- Increases the length of the radius by 10.
- Uses the Circle methods to print the increased area and circumference to the console.
this is your homework assigment
jyde, a couple of things:
- Do not cross post your questions (it is VERY obvious that this question does not belong in the Advanced Java section). Cross posting irritates people to no end... the same people who would help you answer your questons.
- The forum is not going to do your homework for you. If you have a specific problem or question with your code, then the forum will help you.
As for answer you posted, yes that is correct.
It will be interesting to see your answer for: Code:
Cube c = new Cube();
CJSL