Skip to content

Commit

Permalink
feat(9): finish Assignment9: Ultimate Frisbee
Browse files Browse the repository at this point in the history
  • Loading branch information
101zh committed Feb 16, 2024
1 parent fe35208 commit c55a799
Show file tree
Hide file tree
Showing 6 changed files with 241 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/main/java/Unit9/Captain.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package Unit9;

// Have to get rid of package statement

public class Captain extends UltimatePlayer {
private boolean type;

public Captain(String firstName, String lastName, String position, boolean type) {
super(firstName, lastName, position);
this.type = type;
}

@Override
public int throwDisc(int pow) {
return (int) (super.throwDisc(pow) * 1.25);
}

@Override
public String toString() {
String typeName;

if (type) {
typeName = "offense";
} else {
typeName = "defense";
}

return super.toString() + "\n" +
" Captain: " + typeName;
}

}
17 changes: 17 additions & 0 deletions src/main/java/Unit9/Coach.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package Unit9;

// Have to get rid of package statement

public class Coach extends Person {
String role;

public Coach(String firstName, String lastName, String role) {
super(firstName, lastName);
this.role = role;
}

public String toString() {
return super.toString() + "\n" +
" Role: " + role;
}
}
28 changes: 28 additions & 0 deletions src/main/java/Unit9/Person.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package Unit9;

// Have to get rid of package statement

public class Person {
private String firstName;
private String lastName;

public Person(String firstName, String lastName) {
this.firstName = firstName;
this.lastName = lastName;
}

public int throwDisc(int pow) {
if (pow > 10) {
pow = 10;
} else if (pow < 1) {
pow = 1;
}

return pow * 2;
}

@Override
public String toString() {
return lastName + ", " + firstName;
}
}
37 changes: 37 additions & 0 deletions src/main/java/Unit9/UltimatePlayer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package Unit9;

// Have to get rid of package statement

public class UltimatePlayer extends Person {
private static int players = 1;
private int jerseyNumber;
private String position;

public UltimatePlayer(String firstName, String lastName, String position) {
super(firstName, lastName);
if (!(position.equals("handler") || position.equals("cutter"))) {
position = "handler";
}

this.position = position;
this.jerseyNumber = players;
players++;
}

public String getPosition() {
return position;
}

@Override
public int throwDisc(int pow) {
return super.throwDisc(pow) * 2;
}

@Override
public String toString() {
return super.toString() + "\n" +
" Jersey #: " + jerseyNumber + "\n" +
" Position: " + getPosition();
}

}
52 changes: 52 additions & 0 deletions src/main/java/Unit9/UltimateTeam.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package Unit9;

// Have to get rid of package statement

import java.util.ArrayList;

public class UltimateTeam {
ArrayList<UltimatePlayer> players;
ArrayList<Coach> coaches;

UltimateTeam(ArrayList<UltimatePlayer> players, ArrayList<Coach> coaches) {
this.players = players;
this.coaches = coaches;
}

public String getCutters() {
String cutters = "";
for (UltimatePlayer player : players) {
if (player.getPosition().equals("cutter")) {
cutters += player.toString() + "\n";
}
}

return cutters;
}

public String getHandlers() {
String handlers = "";
for (UltimatePlayer player : players) {
if (player.getPosition().equals("handler")) {
handlers += player.toString() + "\n";
}
}

return handlers;
}

@Override
public String toString() {
String team = "COACHES\n";

for (Coach coach : coaches) {
team += coach.toString() + "\n";
}
team += "\nPLAYERS\n";
for (UltimatePlayer player : players) {
team += player.toString() + "\n";
}

return team;
}
}
75 changes: 75 additions & 0 deletions src/test/java/Unit9/runner_Ultimate.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package Unit9;

// Have to get rid of package statement

import java.util.ArrayList;
import java.util.Scanner;

public class runner_Ultimate {

public static void main(String[] args) {
ArrayList<UltimatePlayer> players = new ArrayList<UltimatePlayer>();
ArrayList<Coach> coaches = new ArrayList<Coach>();
Scanner scan = new Scanner(System.in);
String ins = "";
while (!ins.equals("q")) {
System.out.println(
"\nWhat do you want to do?\np - make a person\nt - make a team from the current player/coach lists\nq - quit");
ins = scan.nextLine().toLowerCase();
if (ins.equals("p")) {
Person p;
System.out.println(
"\nWhich class do you want to use?\np - Person\nu - UltimatePlayer\nc - Captain\no - Coach");
String cls = scan.nextLine().toLowerCase();
System.out.println("First name?");
String fn = scan.nextLine();
System.out.println("Last name?");
String ln = scan.nextLine();
if (cls.equals("u") || cls.equals("c")) {
System.out.println("Position?");
String ps = scan.nextLine();
if (cls.equals("c")) {
System.out.println("Offensive coach? (t/f)");
boolean tp = scan.nextLine().toLowerCase().equals("t");
p = new Captain(fn, ln, ps, tp);
} else
p = new UltimatePlayer(fn, ln, ps);
players.add((UltimatePlayer) p);
System.out.println("\n" + fn + " " + ln + " was added to the players list.");
} else if (cls.equals("o")) {
System.out.println("Role?");
String rl = scan.nextLine();
p = new Coach(fn, ln, rl);
coaches.add((Coach) p);
System.out.println("\n" + fn + " " + ln + " was added to the coaches list.");
} else {
p = new Person(fn, ln);
System.out.println("\nSorry, only UltimatePlayers, Captains and Coaches can be added to the team.");
}
System.out.println("\n" + p);
System.out.println("\nType \"t\" for " + fn + " to throw a disc.");
if (scan.nextLine().toLowerCase().equals("t")) {
System.out.println("Enter power level between 1 and 10.");
System.out.println(fn + " threw the disc " + p.throwDisc(scan.nextInt()) + " yards.");
scan.nextLine();
}
} else if (ins.equals("t")) {
UltimateTeam t = new UltimateTeam(players, coaches);
System.out.println("\nYour team is ready!\n");
while (!ins.equals("q")) {
System.out.println(
"\nWhat do you want to do?\nc - see the cutters\nh - see handlers\nt = see the whole team\nq - quit");
ins = scan.nextLine().toLowerCase();
if (ins.equals("h"))
System.out.println("\n" + t.getHandlers());
else if (ins.equals("c"))
System.out.println("\n" + t.getCutters());
else if (ins.equals("t"))
System.out.println("\n" + t + "\n");
}
}
}

scan.close();
}
}

0 comments on commit c55a799

Please sign in to comment.