cs-3443: initial lab 1
This commit is contained in:
parent
82212475d0
commit
f295ba1982
5
Summer-2024/CS-3443/Labs/Lab1/.gitignore
vendored
Normal file
5
Summer-2024/CS-3443/Labs/Lab1/.gitignore
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
.classpath
|
||||||
|
.settings/
|
||||||
|
target/
|
||||||
|
.metadata/
|
||||||
|
.project
|
101
Summer-2024/CS-3443/Labs/Lab1/Assignment.org
Normal file
101
Summer-2024/CS-3443/Labs/Lab1/Assignment.org
Normal file
@ -0,0 +1,101 @@
|
|||||||
|
*Objective:* Here, you'll have the opportunity to showcase your mastery of Java syntax, arrays, String class, OOP concepts, and class relationships. Embrace the challenge and let your understanding shine!
|
||||||
|
|
||||||
|
--------
|
||||||
|
|
||||||
|
*Estimated Time:* 3 hours
|
||||||
|
|
||||||
|
------
|
||||||
|
|
||||||
|
*Task:* Mr. John Hammond has asked for some basic software to help manage his theme park. (He says he will "spare no expense", but we'll see.) Version 1.0 of the software will create Java objects to represent the park itself and the dinosaurs within. Yes, dinosaurs. With this software, park operators will be able to plan each of the different types of dinosaurs the park contains as it develops and opens.
|
||||||
|
|
||||||
|
------
|
||||||
|
|
||||||
|
* Instructions
|
||||||
|
|
||||||
|
Begin by creating a new Java project in Eclipse, named according to the lab guidelines - project name should be "abc123-lab1", where abc123 is your UTSA ID.
|
||||||
|
|
||||||
|
Create the following new Java classes in the default package: (Use these names exactly!)
|
||||||
|
|
||||||
|
| Java Class | Comment |
|
||||||
|
|--------------------|----------------------------------------------------------|
|
||||||
|
| Park.java | |
|
||||||
|
| Dinosaur.java | This will be an interface |
|
||||||
|
| Theropod.java | This will be an abstract class, 1 of 3 types of Dinosaur |
|
||||||
|
| Sauropod.java | This will be an abstract class, 1 of 3 types of Dinosaur |
|
||||||
|
| Stegosaur.java | This will be an abstract class, 1 of 3 types of Dinosaur |
|
||||||
|
| Tyrannosaurus.java | This will be a class, 1 of 2 types of Theropod |
|
||||||
|
| Velociraptor.java | This will be a class, 1 of 2 types of Theropod |
|
||||||
|
| Apatosaurus.java | This will be a class, 1 of 2 types of Sauropod |
|
||||||
|
| Brachiosaurus.java | This will be a class, 1 of 2 types of Sauropod |
|
||||||
|
| Stegosaurus.java | This will be a class, 1 of 1 types of Stegosaur |
|
||||||
|
|
||||||
|
Note that we will have a few relationships between these classes. A Park contains ('has-a') Dinosaurs. There are 3 types of Dinosaurs: Theropods, Sauropods, and Stegosaurs. Velociraptor and Tyrannosaurus are types of Theropod. Apatosaurus and Brachiosaurus are types of Sauropod. Stegosaurus is a type of Stegosaur.
|
||||||
|
|
||||||
|
Place the given =Lab1.java= class in the default package within your project. =Lab1.java= has a main method and will be the class to run our application. Follow the remaining instructions for each class in this lab in order to get your code to compile - do not change the given class. Note that this code will not compile until you have completed the requirements of this lab. There will be syntax errors until all dependencies (classes and methods) are implemented. Once your code compiles, you will be able to examine the output of your program. The output of your program must match the format of the sample below. This sample is the result of running the =Lab1.java= class with the given main method.
|
||||||
|
|
||||||
|
#+begin_src
|
||||||
|
Welcome to Jurassic Park!
|
||||||
|
|
||||||
|
- - - - - - - - - - - - -
|
||||||
|
|
||||||
|
* Theropod: Velociraptor named Blue (carnivore)
|
||||||
|
|
||||||
|
* Theropod: Velociraptor named Delta (carnivore)
|
||||||
|
|
||||||
|
* Theropod: Velociraptor named Echo (carnivore)
|
||||||
|
|
||||||
|
* Theropod: Tyrannosaurus named Rex (carnivore)
|
||||||
|
|
||||||
|
* Sauropod: Apatosaurus named Littlefoot (not carnivore)
|
||||||
|
|
||||||
|
* Sauropod: Brachiosaurus named Bob (not carnivore)
|
||||||
|
|
||||||
|
* Stegosaur: Stegosaurus named Spike (not carnivore)
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
** More Details
|
||||||
|
|
||||||
|
*** Park.java
|
||||||
|
|
||||||
|
This class will represent a Park object, which we will define as having:
|
||||||
|
- A name, represented as a String (e.g: Jurassic Park)
|
||||||
|
- A max capacity of dinosaurs, represented as an int (e.g. in =Lab1.java=, the max capacity is set to $10$)
|
||||||
|
- Dinosaurs, stored as an array of Dinosaur objects (e.g. ~Dinosaur[]~)
|
||||||
|
- A constructor that initializes all instance variables and any other constructors as needed
|
||||||
|
- An ~addDino(...)~ method, which takes as a parameter a ~Dinosaur~ object and returns nothing
|
||||||
|
- A ~toString()~ method, which calls upon the ~toString()~ method in =Dinosaur.java= to return as a String all needed information (see the output above)
|
||||||
|
- Getters and setters for all variables
|
||||||
|
|
||||||
|
*** Dinosaur.java
|
||||||
|
|
||||||
|
This class will represent a Dinosaur, which we will define as an interface. This interface should declare the following methods (for the subclasses to implement):
|
||||||
|
|
||||||
|
- A method ~isVegetarian()~, which takes no parameters and returns a ~boolean~ for whether or not the dinosaur is a vegetarian (if not, they eat meat!)
|
||||||
|
- A ~getName()~ which takes no parameters and returns a String of the dinosaur’s name (e.g. "Echo")
|
||||||
|
- A ~getType()~ method which takes no parameters and returns a String of the dinosaur’s type (e.g. "Theropod - Velociraptor")
|
||||||
|
- A ~toString()~ method which returns a String representation of the dinosaur (see output above)
|
||||||
|
|
||||||
|
*** Theropod.java, Sauropod.java, Stegosaur.java
|
||||||
|
|
||||||
|
These classes will be abstract classes, representing the types of dinosaurs in our park. Each class should implement the Dinosaur interface and each should have:
|
||||||
|
|
||||||
|
- A name, represented as a String (i.e.: Rex)
|
||||||
|
- Whether or not the dino is a vegetarian - very important! This will be represented as a ~boolean~ (e.g. ~false~, for Rex, our tyrannosaurus)
|
||||||
|
- A constructor that initializes all instance variables, and any other constructors as needed
|
||||||
|
- A ~toString()~ method which returns a String representation of the dinosaur by calling upon "getter" methods.
|
||||||
|
- A ~getType()~ method, fulfilling the requirements of the super class.
|
||||||
|
- An abstract method ~getSubType()~ which takes no parameters and returns a sub type of dinosaur (e.g. "Velociraptor"). This method should be called by the ~getType()~ method.
|
||||||
|
|
||||||
|
*** Velociraptor.java, Tyrannosaurus.java, Apatosaurus.java, Brachiosaurus.java, Stegosaurus.java
|
||||||
|
|
||||||
|
These classes these will be very short classes in terms of amount of code. The classes will represent the specific types of dinosaurs which can be added to the park. Each class should extend its respective abstract class (see above for which classes should extend which abstract classes). In addition, they should have:
|
||||||
|
|
||||||
|
- A constructor that initializes all instance variables, and any other constructors as needed
|
||||||
|
- A ~getType()~ method which fulfills the requirements of the super class.
|
||||||
|
|
||||||
|
** Additional Notes
|
||||||
|
|
||||||
|
- Follow Java code style including the capitalization of your zip file, project name, and class names, and variables. (Recall that names of Java variables and methods should be in camel case)
|
||||||
|
- This lab is meant to review regular arrays in Java, no other data structure may be used to store the objects required. (No ArrayLists are permitted, for example).
|
||||||
|
- All classes should have Javadoc comments.
|
||||||
|
- The grader will test your code by modifying the main method in Lab1.java to add different dinos to a different park. If coded according to the requirements of this lab, your submission will output the correct result. However, if you "hard code" any portion of the lab (except Lab1.java, which again, you should not modify) your submission will fail this test case.)
|
0
Summer-2024/CS-3443/Labs/Lab1/README.org
Normal file
0
Summer-2024/CS-3443/Labs/Lab1/README.org
Normal file
47
Summer-2024/CS-3443/Labs/Lab1/pom.xml
Normal file
47
Summer-2024/CS-3443/Labs/Lab1/pom.xml
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<groupId>org.zfp106.lab1</groupId>
|
||||||
|
<artifactId>lab1</artifactId>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
<version>0.1</version>
|
||||||
|
<name>lab1</name>
|
||||||
|
<url>http://maven.apache.org</url>
|
||||||
|
<dependencyManagement>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.junit</groupId>
|
||||||
|
<artifactId>junit-bom</artifactId>
|
||||||
|
<version>5.10.2</version>
|
||||||
|
<type>pom</type>
|
||||||
|
<scope>import</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</dependencyManagement>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.junit.jupiter</groupId>
|
||||||
|
<artifactId>junit-jupiter</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
<version>3.2.5</version>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
|
<version>3.0.2</version>
|
||||||
|
<configuration>
|
||||||
|
<archive>
|
||||||
|
<manifest>
|
||||||
|
<mainClass>com.zfp106.lab1.Lab1</mainClass>
|
||||||
|
</manifest>
|
||||||
|
</archive>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
@ -0,0 +1,7 @@
|
|||||||
|
package com.zfp106.lab1;
|
||||||
|
|
||||||
|
public class Apatosaurus extends Sauropod {
|
||||||
|
public Apatosaurus(String name, Boolean isVegetarian) {
|
||||||
|
super(name, isVegetarian, "Apatosaurus");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
package com.zfp106.lab1;
|
||||||
|
|
||||||
|
public class Brachiosaurus extends Sauropod {
|
||||||
|
public Brachiosaurus(String name, Boolean isVegetarian) {
|
||||||
|
super(name, isVegetarian, "Brachiosaurus");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
package com.zfp106.lab1;
|
||||||
|
|
||||||
|
public interface Dinosaur {
|
||||||
|
public boolean isVegetarian();
|
||||||
|
|
||||||
|
public String getName();
|
||||||
|
|
||||||
|
public String getType();
|
||||||
|
|
||||||
|
public String toString();
|
||||||
|
}
|
@ -0,0 +1,57 @@
|
|||||||
|
package com.zfp106.lab1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lab1 is a Java class containing a main method to run your program when
|
||||||
|
* completed.
|
||||||
|
* This class will not compile until you have completed the requirements
|
||||||
|
* outlined in
|
||||||
|
* the lab description.
|
||||||
|
*
|
||||||
|
* @author Price Hiller (zfp106)
|
||||||
|
* UTSA CS 3443 - Lab 1
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class Lab1 {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
// create a Park object
|
||||||
|
Park jurassicPark = new Park("Jurassic Park", 10);
|
||||||
|
|
||||||
|
// All Parks contains Dinosaurs which come in different 3 types in our Jurassic
|
||||||
|
// Park: theropods, sauropods, & stegosaurs.
|
||||||
|
|
||||||
|
// create dinosaurs to add to the park
|
||||||
|
Theropod blue = new Velociraptor("Blue", false); // Velociraptors are a type of Theropod, which is a type of
|
||||||
|
// Dinosaur
|
||||||
|
Theropod delta = new Velociraptor("Delta", false); // Velociraptors are a type of Theropod, which is a type of
|
||||||
|
// Dinosaur
|
||||||
|
Theropod echo = new Velociraptor("Echo", false); // Velociraptors are a type of Theropod, which is a type of
|
||||||
|
// Dinosaur
|
||||||
|
Theropod rex = new Tyrannosaurus("Rex", false); // Tyrannosaurus are a type of Theropod, which is a type of
|
||||||
|
// Dinosaur
|
||||||
|
Sauropod littleFoot = new Apatosaurus("Littlefoot", true); // Apatosaurus are a type of Sauropod, which is a
|
||||||
|
// type of Dinosaur
|
||||||
|
Sauropod bob = new Brachiosaurus("Bob", true); // Brachiosaurus are a type of Sauropod, which is a type of
|
||||||
|
// Dinosaur
|
||||||
|
Stegosaur spike = new Stegosaurus("Spike", true); // Stegosaurus are a type of Stegosaur, which is a type of
|
||||||
|
// Dinosaur
|
||||||
|
|
||||||
|
// add all dinos to the park
|
||||||
|
jurassicPark.addDino(blue);
|
||||||
|
jurassicPark.addDino(delta);
|
||||||
|
jurassicPark.addDino(echo);
|
||||||
|
jurassicPark.addDino(rex);
|
||||||
|
jurassicPark.addDino(littleFoot);
|
||||||
|
jurassicPark.addDino(bob);
|
||||||
|
jurassicPark.addDino(spike);
|
||||||
|
|
||||||
|
// print the state of the park (see lab description)
|
||||||
|
System.out.println(jurassicPark);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fun Fact:
|
||||||
|
// Did you know? There are generally considered to be 7 types of dinos:
|
||||||
|
// theropods, sauropods, stegosaurs, ankylosaurs, ornithopods, ceratopsians, and
|
||||||
|
// pachycephalosaurs!
|
@ -0,0 +1,63 @@
|
|||||||
|
package com.zfp106.lab1;
|
||||||
|
|
||||||
|
public class Park {
|
||||||
|
private String name;
|
||||||
|
private Integer capacity;
|
||||||
|
private Dinosaur[] dinosaurs;
|
||||||
|
|
||||||
|
public Park(String name, Integer capacity) {
|
||||||
|
this.name = name;
|
||||||
|
this.capacity = capacity;
|
||||||
|
this.dinosaurs = new Dinosaur[this.capacity];
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
String out = String.format("Welcome to %s!\n\n- - - - - - - - - - - - -", this.name);
|
||||||
|
for (Dinosaur dino : this.dinosaurs) {
|
||||||
|
if (dino != null) {
|
||||||
|
out = String.format("%s\n\n%s", out, dino.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a dinosaur to the park, note that if you exceed the park capacity this
|
||||||
|
* will cause an
|
||||||
|
* error
|
||||||
|
*
|
||||||
|
* @param dino The dinosaur to add
|
||||||
|
*/
|
||||||
|
public void addDino(Dinosaur dino) {
|
||||||
|
for (int i = 0; i < dinosaurs.length; i++) {
|
||||||
|
// Instead of tracking how many dinosaurs are currently in the park, we can
|
||||||
|
// instead just check for an empty spot in the array. Less efficient, but I'm
|
||||||
|
// lazy 🤷
|
||||||
|
if (this.dinosaurs[i] == null) {
|
||||||
|
this.dinosaurs[i] = dino;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getCapacity() {
|
||||||
|
return capacity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Dinosaur[] getDinosaurs() {
|
||||||
|
return dinosaurs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDinosaurs(Dinosaur[] dinosaurs) {
|
||||||
|
this.capacity = dinosaurs.length;
|
||||||
|
this.dinosaurs = dinosaurs;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,50 @@
|
|||||||
|
package com.zfp106.lab1;
|
||||||
|
|
||||||
|
public abstract class Sauropod implements Dinosaur {
|
||||||
|
private String name;
|
||||||
|
private boolean isVegetarian;
|
||||||
|
private String subType;
|
||||||
|
|
||||||
|
public Sauropod(String name, boolean isVegetarian, String subtype) {
|
||||||
|
this.setName(name);
|
||||||
|
this.setVegetarian(isVegetarian);
|
||||||
|
this.setSubType(subtype);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return String.format("* %s named %s (%s)", this.getType(), this.getName(),
|
||||||
|
this.isVegetarian() ? "not carnivore" : "carnivore");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isVegetarian() {
|
||||||
|
return this.isVegetarian;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setVegetarian(boolean isVegetarian) {
|
||||||
|
this.isVegetarian = isVegetarian;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getType() {
|
||||||
|
return "Sauropod: " + this.getSubType();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSubType() {
|
||||||
|
return this.subType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSubType(String subtype) {
|
||||||
|
this.subType = subtype;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,46 @@
|
|||||||
|
package com.zfp106.lab1;
|
||||||
|
|
||||||
|
public abstract class Stegosaur implements Dinosaur {
|
||||||
|
private String name;
|
||||||
|
private boolean isVegetarian;
|
||||||
|
private String subType;
|
||||||
|
|
||||||
|
public Stegosaur(String name, boolean isVegetarian, String subtype) {
|
||||||
|
this.setName(name);
|
||||||
|
this.setVegetarian(isVegetarian);
|
||||||
|
this.setSubType(subtype);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
return String.format("* %s named %s (%s)", this.getType(), this.getName(),
|
||||||
|
this.isVegetarian() ? "not carnivore" : "carnivore");
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isVegetarian() {
|
||||||
|
return this.isVegetarian;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setVegetarian(boolean isVegetarian) {
|
||||||
|
this.isVegetarian = isVegetarian;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getType() {
|
||||||
|
return "Stegosaur: " + this.getSubType();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSubType() {
|
||||||
|
return this.subType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSubType(String subtype) {
|
||||||
|
this.subType = subtype;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
package com.zfp106.lab1;
|
||||||
|
|
||||||
|
public class Stegosaurus extends Stegosaur {
|
||||||
|
public Stegosaurus(String name, Boolean isVegetarian) {
|
||||||
|
super(name, isVegetarian, "Stegosaurus");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,46 @@
|
|||||||
|
package com.zfp106.lab1;
|
||||||
|
|
||||||
|
public abstract class Theropod implements Dinosaur {
|
||||||
|
private String name;
|
||||||
|
private boolean isVegetarian;
|
||||||
|
private String subType;
|
||||||
|
|
||||||
|
public Theropod(String name, boolean isVegetarian, String subtype) {
|
||||||
|
this.setName(name);
|
||||||
|
this.setVegetarian(isVegetarian);
|
||||||
|
this.setSubType(subtype);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
return String.format("* %s named %s (%s)", this.getType(), this.getName(),
|
||||||
|
this.isVegetarian() ? "not carnivore" : "carnivore");
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isVegetarian() {
|
||||||
|
return this.isVegetarian;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setVegetarian(boolean isVegetarian) {
|
||||||
|
this.isVegetarian = isVegetarian;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getType() {
|
||||||
|
return "Theropod: " + this.getSubType();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSubType() {
|
||||||
|
return this.subType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSubType(String subtype) {
|
||||||
|
this.subType = subtype;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
package com.zfp106.lab1;
|
||||||
|
|
||||||
|
public class Tyrannosaurus extends Theropod {
|
||||||
|
public Tyrannosaurus(String name, Boolean isVegetarian) {
|
||||||
|
super(name, isVegetarian, "Tyrannosaurus");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
package com.zfp106.lab1;
|
||||||
|
|
||||||
|
public class Velociraptor extends Theropod {
|
||||||
|
public Velociraptor(String name, Boolean isVegetarian) {
|
||||||
|
super(name, isVegetarian, "Velociraptor");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,49 @@
|
|||||||
|
package com.zfp106.lab1;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
class ParkTests {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void parkStringReprIsCorrect() {
|
||||||
|
Park jurassicPark = new Park("Jurassic Park", 10);
|
||||||
|
|
||||||
|
Theropod blue = new Velociraptor("Blue", false);
|
||||||
|
Theropod delta = new Velociraptor("Delta", false);
|
||||||
|
Theropod echo = new Velociraptor("Echo", false);
|
||||||
|
Theropod rex = new Tyrannosaurus("Rex", false);
|
||||||
|
Sauropod littleFoot = new Apatosaurus("Littlefoot", true);
|
||||||
|
Sauropod bob = new Brachiosaurus("Bob", true);
|
||||||
|
Stegosaur spike = new Stegosaurus("Spike", true);
|
||||||
|
|
||||||
|
jurassicPark.addDino(blue);
|
||||||
|
jurassicPark.addDino(delta);
|
||||||
|
jurassicPark.addDino(echo);
|
||||||
|
jurassicPark.addDino(rex);
|
||||||
|
jurassicPark.addDino(littleFoot);
|
||||||
|
jurassicPark.addDino(bob);
|
||||||
|
jurassicPark.addDino(spike);
|
||||||
|
|
||||||
|
String expected = "Welcome to Jurassic Park!\n" +
|
||||||
|
"\n" +
|
||||||
|
"- - - - - - - - - - - - -\n" +
|
||||||
|
"\n" +
|
||||||
|
"* Theropod: Velociraptor named Blue (carnivore)\n" +
|
||||||
|
"\n" +
|
||||||
|
"* Theropod: Velociraptor named Delta (carnivore)\n" +
|
||||||
|
"\n" +
|
||||||
|
"* Theropod: Velociraptor named Echo (carnivore)\n" +
|
||||||
|
"\n" +
|
||||||
|
"* Theropod: Tyrannosaurus named Rex (carnivore)\n" +
|
||||||
|
"\n" +
|
||||||
|
"* Sauropod: Apatosaurus named Littlefoot (not carnivore)\n" +
|
||||||
|
"\n" +
|
||||||
|
"* Sauropod: Brachiosaurus named Bob (not carnivore)\n" +
|
||||||
|
"\n" +
|
||||||
|
"* Stegosaur: Stegosaurus named Spike (not carnivore)";
|
||||||
|
|
||||||
|
assertEquals(expected, jurassicPark.toString());
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user