This commit is contained in:
ldy
2026-03-01 23:18:55 -05:00
commit 67f753a5d1
3087 changed files with 218259 additions and 0 deletions

View 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>

View 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>

View File

@@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding/<project>=UTF-8

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View 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);
}
}

View 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);
}
}

View 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);
}
}

View 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);
}
}