generated from microsoft/vscode-remote-try-java
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(9): finish Assignment9: Ultimate Frisbee
- Loading branch information
Showing
6 changed files
with
241 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |