Comp 155 Assignment
Comp 155 Assignment
1
Code
interface Pet {
void displayDetails();
String name;
String breed;
int age;
String name;
String color;
int age;
String name;
String species;
int age;
class PetCare {
Q.2
squid
creature 1
tentacles
BIG!
spout
creature 2
ocean-dwelling
creature 1 creature 2
ocean-dwelling
warm-blooded
creature 2
Q.3
1. They cannot access the name and age as they are marked as
private. But, the UndergraduateStudent class can call
the setAge method because it is public, allowing it to be accessed
by subclasses and other classes.
2.
public class UndergraduateStudent extends Student {
private int year;
3.
@Override
public void setAge(int age) {
super.setAge(age);
this.year++;
}
Q.4
Code
class ExceedsBalanceLimitException extends Exception {
public ExceedsBalanceLimitException(String message) {
super(message);
}
}
class Account {
private String accountID;
private double currentBalance;
private int transactionCount;
} catch (AccountNotFoundException e) {
System.out.println(e.getMessage());
} catch (InvalidDepositAmountException e) {
System.out.println(e.getMessage());
} catch (ExceedsBalanceLimitException e) {
System.out.println(e.getMessage());
}
}
}
Output