Restore
This commit is contained in:
10
Labs/Lab5/Lab5_2230026071/Question3/.classpath
Normal file
10
Labs/Lab5/Lab5_2230026071/Question3/.classpath
Normal file
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
|
||||
<attributes>
|
||||
<attribute name="module" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
17
Labs/Lab5/Lab5_2230026071/Question3/.project
Normal file
17
Labs/Lab5/Lab5_2230026071/Question3/.project
Normal file
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>Question3</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
@@ -0,0 +1,2 @@
|
||||
eclipse.preferences.version=1
|
||||
encoding/<project>=UTF-8
|
||||
BIN
Labs/Lab5/Lab5_2230026071/Question3/bin/Cat.class
Normal file
BIN
Labs/Lab5/Lab5_2230026071/Question3/bin/Cat.class
Normal file
Binary file not shown.
BIN
Labs/Lab5/Lab5_2230026071/Question3/bin/Dog.class
Normal file
BIN
Labs/Lab5/Lab5_2230026071/Question3/bin/Dog.class
Normal file
Binary file not shown.
BIN
Labs/Lab5/Lab5_2230026071/Question3/bin/Start.class
Normal file
BIN
Labs/Lab5/Lab5_2230026071/Question3/bin/Start.class
Normal file
Binary file not shown.
BIN
Labs/Lab5/Lab5_2230026071/Question3/bin/Student.class
Normal file
BIN
Labs/Lab5/Lab5_2230026071/Question3/bin/Student.class
Normal file
Binary file not shown.
30
Labs/Lab5/Lab5_2230026071/Question3/src/Cat.java
Normal file
30
Labs/Lab5/Lab5_2230026071/Question3/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);
|
||||
}
|
||||
}
|
||||
31
Labs/Lab5/Lab5_2230026071/Question3/src/Dog.java
Normal file
31
Labs/Lab5/Lab5_2230026071/Question3/src/Dog.java
Normal file
@@ -0,0 +1,31 @@
|
||||
|
||||
public class Dog {
|
||||
//instance variables
|
||||
private String name;
|
||||
private double weight;
|
||||
|
||||
//constructor
|
||||
public Dog (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 += 2.0;}
|
||||
|
||||
//test
|
||||
public static void testDog() {
|
||||
Dog d = new Dog("Woof", 2.0);
|
||||
System.out.println(d.getName() == "Woof");
|
||||
System.out.println(d.getWeight() == 2.0);
|
||||
d.feed();
|
||||
// The name is still the same but the weight increased by 2.0:
|
||||
System.out.println(d.getName() == "Woof");
|
||||
System.out.println(d.getWeight() == 4.0);
|
||||
}
|
||||
|
||||
}
|
||||
20
Labs/Lab5/Lab5_2230026071/Question3/src/Start.java
Normal file
20
Labs/Lab5/Lab5_2230026071/Question3/src/Start.java
Normal file
@@ -0,0 +1,20 @@
|
||||
|
||||
public class Start {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// Unit tests
|
||||
Cat.testCat();
|
||||
Dog.testDog();
|
||||
Student.testStudent();
|
||||
// System tests, to test both classes together.
|
||||
Cat c = new Cat("Meow", 2.0);
|
||||
Student s = new Student("Philippe", c);
|
||||
System.out.println(s.getPet().getName() == "Meow");
|
||||
System.out.println(s.getPet().getWeight() == 2.0);
|
||||
// Feeding the student's pet cat:
|
||||
s.getPet().feed();
|
||||
System.out.println(s.getPet().getName() == "Meow");
|
||||
System.out.println(s.getPet().getWeight() == 3.0);
|
||||
}
|
||||
|
||||
}
|
||||
26
Labs/Lab5/Lab5_2230026071/Question3/src/Student.java
Normal file
26
Labs/Lab5/Lab5_2230026071/Question3/src/Student.java
Normal file
@@ -0,0 +1,26 @@
|
||||
|
||||
public class Student {
|
||||
//instance variables
|
||||
private String name;
|
||||
private Cat pet;
|
||||
|
||||
//constructor
|
||||
public Student(String name, Cat pet) {
|
||||
this.name = name;
|
||||
this.pet = pet;
|
||||
}
|
||||
|
||||
//methods
|
||||
public String getName() {return this.name;}
|
||||
|
||||
public Cat getPet() {return this.pet;}
|
||||
|
||||
//test
|
||||
public static void testStudent() {
|
||||
Cat c = new Cat("Meow", 2.0);
|
||||
Student s = new Student("Philippe", c);
|
||||
System.out.println(s.getName() == "Philippe");
|
||||
System.out.println(s.getPet() == c);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user