Escolar Documentos
Profissional Documentos
Cultura Documentos
1. Line 1: Private: Should be: Public to give the class a package scope.
2. Line 2: 3.14: Should be 3.14F.
3. Line 8: this.r: Should be r only.
4. Line 11: double in the construction: Should be removed: Constructions don’t have a return type.
5. Line 15: Missing the closing brace for the constructor “ } ”.
6. Line 18: r^2: Should be: PI*r*r as the symbol ^ means XOR in java.
7. Line 21: Missing the closing of the comment */.
8. Line 22: Missing the type od the variable in the parameters for y1 which should be a double.
9. Line 23: dx has the type int but calculates floats so it should have a casting.
10. Line 24: dy has the type int but calculates floats so it should have a casting.
11. Line 29: String should be Strings.
12. Line 31: int i; is defined already in line 30.
13. Line 32: Missing the starting braces for the loop for { .
Question 2:
Pair Class:
Private int i;
Instance variable, accessed inside the class only.
Private String s:
Instance variable, accessed inside the class only.
Public Pair(int I, String s):
Method in the stack for the class pair.
Int i:
Local variable for the constructor.
String s:
Local variable for the constructor.
This.i = I;
References the int i in the constructor to the instance variable in the class private inti i;
This s = s;
References the String s in the constructor to the instance variable in the class private
String s;
Octopus Class:
Main( ):
Method in the stack.
Octopus o = new Octopus();
Create an object from the type Octopus and reference to it by o .
O.test( );
Calls the method test in the class Octopus for the object o.
declares local variables int j;
declares local variable String t;
declares an object Pair with reference p;
Initialize j = 42;
Initialize t = “hello Mr. squid”; in the String pool.
Initialize the object p to the constructor Pair( j , t);
References the j and t to the constructor parameters.
Question 3:
a. Time Class.
b. Book Class.
c. Person Class:
Person
+ Name: String.
+ Age: int.
Dancer DountMaker
+ Company: String + Shop: String.
Time.java
public Time() {
this.second = 0;
this.minute = 0;
this.hour = 0;
}
this.second = second;
this.minute = minute;
this.hour = hour;
}
Page 1
Time.java
Page 2
Book.java
public Book (String name, Author author, double price, int qty) {
this. name = name;
this. author = author;
this. price = price;
this. qty = qty;
}
Page 1
Book.java
Page 2