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,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,9 @@
public class Start {
public static void main(String[] args) {
Cat.testCat();
Dog.testDog();
}
}