Restore
This commit is contained in:
30
Labs/Lab5/Lab5_2230026071/Question1/src/Cat.java
Normal file
30
Labs/Lab5/Lab5_2230026071/Question1/src/Cat.java
Normal file
@@ -0,0 +1,30 @@
|
||||
|
||||
public class Cat {
|
||||
//instance variables
|
||||
private String name;
|
||||
private double weight;
|
||||
|
||||
//constructor
|
||||
public Cat (String name, double weight) {
|
||||
this.name = name;
|
||||
this.weight = weight;
|
||||
}
|
||||
|
||||
//methods
|
||||
public String getName() {return this.name;}
|
||||
|
||||
public double getWeight() {return this.weight;}
|
||||
|
||||
public void feed() {++this.weight;}
|
||||
|
||||
//test
|
||||
public static void testCat() {
|
||||
Cat c = new Cat("Meow", 2.0);
|
||||
System.out.println(c.getName() == "Meow");
|
||||
System.out.println(c.getWeight() == 2.0);
|
||||
c.feed();
|
||||
// The name is still the same but the weight increased by 1.0:
|
||||
System.out.println(c.getName() == "Meow");
|
||||
System.out.println(c.getWeight() == 3.0);
|
||||
}
|
||||
}
|
||||
8
Labs/Lab5/Lab5_2230026071/Question1/src/Start.java
Normal file
8
Labs/Lab5/Lab5_2230026071/Question1/src/Start.java
Normal file
@@ -0,0 +1,8 @@
|
||||
|
||||
public class Start {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Cat.testCat();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user