You are on page 1of 2

2.

64 Name is getCode, return type is String

2.65 Name of method is setCredits, name of parameter is creditValue and the type of parameter is
integer

2.66 public class Person{ }

2.67 String name, int age, String code, int credits

2.68 public Module (String moduleCode) { code=moduleCode; }

2.69 public Person(String myName, int myAge) { name = myName; age = myAge; }

2.70 should be public int getAge() { return age; }

2.71 public String getName() { return name ;}

2.72 public void setAge(int newAge) {age = newAge;}

2.73 public void printDetails() {System.out.prinln(“The name of this person is ” + name);}

2.74 Student1 : Student

private String ‘Benjamin Jonson’

private int studentID‘738321 ’

2.75 Henr557

2.76 This will not compiler, because range of the getLoginName() method is too large for student
instance “djb”, and that why this method wouldn’t run.
2.77
Add conditional statements to the constructor of Student to print an error message if either the length of
the fullNameparameter is less than four characters, or the length of the studentId parameter is less than
three characters. However, the constructor should still use those parameters to set
the name and id fields, even if the error message is printed. Hint: Use if-statements of the following form
(that is, having no else part) to print the error messages.

if(fullName.lenght()<4) {
System.out.prinln(“Error”);
}
If(studentId.lenght()<3){
System.out.prinln(“Error”);
}
2.79
99+3
returned int 102
"cat" + "fish"
returned String "catfish"
"cat" + 9
returned String "cat9"
9 + 3 + "cat"
returned String "12cat"
"cat" + 3 + 9
returned String "cat39"
"catfish".substring(3,4)
returned String "f"
"catfish".substring(3,8)
Exception occurred.
“catfish” String
In this exercise everything was working as expected.

You might also like