Assignment 3: Ultimate Frisbee
For this assignment, you will create a hierarchy of five classes to describe various elements of a an ultimate frisbee (Links to an external site.)Links to an external site. team. Ultimate frisbee is a non-contact sport with players at a position of “cutter” or “handler”. A team usually also has a head coach and possibly one or more assistant coaches. An ultimate team has seven players on the field, with four players at the position of cutter and three at the position of handler. Check out the below video to learn more about this great sport!
https://www.youtube.com/watch?v=OqBo-CCf5Gw&feature=youtu.be (Links to an external site.)Links to an external site.
The classes you will write are: Person, UltimatePlayer, Captain, Coach, and UltimateTeam. Detailed below are the requirements for the variables and methods of each class. You may need to add a few additional variables and/or methods; figuring out what is needed is part of your task for this assignment.
Person
Variables
String firstName - Holds the person's first name.
String lastName - Holds the person's last name.
Methods
Person(String firstName, String lastName) - Constructor that takes in String parameters representing the first and last names.
String toString() - Returns a String with the following format: lastName, firstName
UltimatePlayer extends Person
Variables
int jerseyNumber - Using a static variable to keep track of ultimate player jersey numbers, every player should be assigned a unique value for their own jersey number.
String position - Represents a player’s position. Possible values are “handler” and “cutter”.
Methods
UltimatePlayer(String firstName, String lastName, String position) - Constructor that accepts the first name, last name and the position of a player. The first and last names should be set by calling the constructor of the parent class. Position should be set to “handler” if the input string is not “handler” or “cutter”. The UltimatePlayer constructor also sets the jersey number to the next available positive integer. The first UltimatePlayer created should have a jersey number of 1, the second will have a jersey number of 2, third of 3, etc.
String getPosition() - Returns the UltimatePlayer's position.
String toString() - Returns a three-line String with UltimatePlayer information formatted as follows:
Smith, Mary Jersey #: 1 Position: cutter
Note: there are three spaces before "Jersey #: ..." and "Position: ...".
Captain extends UltimatePlayer
Variables
boolean type - Captains on an Ultimate team are usually responsible for either offense or defense. This variable is a boolean representing the type of captain, true for offense, false for defense.
Methods
Captain(String firstName, String lastName, String position, boolean type) - The first and last names and the position should be set by calling the constructor of the parent class.
String toString() - Returns a four-line String with Captain info formatted as follows:
Lee, Sarah Jersey #: 2 Position: handler Captain: offense
Note: there are three spaces before "Jersey #: ...", "Position: ..." and "Captain: ...".
Coach extends Person
Variables
String role - Role of coach on the team. This is a flexible description; there are no required values for this variable. For example, “Head Coach” or “Assistant Coach”.
Methods
Coach(String firstName, String lastName, String role) - The first and last names should be set by calling the constructor of the parent class.
String toString() - Returns a two-line String with Coach info formatted as follows:
Wagner, Rebecca Role: Head Coach
Note: there are three spaces before "Role: ...".
UltimateTeam
Variables
ArrayList<UltimatePlayer> players - The list of ultimate players on the team.
ArrayList<Coach> coaches - A list of the team’s coaches.
Methods
UltimateTeam(ArrayList<UltimatePlayer> players, ArrayList<Coach> coaches) - A constructor that specifies the coaches and players of the team.
String getCutters() - Returns a String listing all the UltimateTeams's UltimatePlayers that have the position of “cutter”. Returns an empty String if the UltimateTeam does not have a player with position of “cutter”. See the Sample Run below for the format of the returned String.
String getHandlers() - Returns a String listing all the UltimateTeams's UltimatePlayers that have the position of “handler”. Returns an empty String if the UltimateTeam does not have a player with position of “handler”. See the Sample Run below for the format of the returned String.
String toString() - Returns a multiline String listing the Coaches and UltimatePlayers on the UltimateTeam. The String is formatted as follows:
COACHES {listing of faculty} PLAYERS {listing of UltimatePlayers}
See the Sample Run below for an example.
Final Notes
Remember, all variables should have an access level of private and all required methods should have an access level of public. Wherever possible, the child class should use a call to the parent's toString and/or constructor methods.
Make sure that all files in your solution are in the same directory. Please download the runner class, Student_Runner_Ultimate.java (Links to an external site.)Links to an external site. into that directory, run the file in DrJava, and verify that the class output matches the Sample Run that follows. We will use a different runner to grade the program. Remember to change the runner to test different values to make sure your program fits the requirements.
Sample Run of Student_Runner_Ultimate.java (Links to an external site.)Links to an external site.:
Printing person: Doe, John Printing player: Smith, Mary Jersey #: 1 Position: cutter Printing captain: Tully, Henry Jersey #: 2 Position: handler Captain: offense Printing coach: Lee, Sara Role: Head coach Printing team: COACHES Mathour, Maryam Role: Head Coach Van Loben Sels, Soren Role: Assistant Coach PLAYERS Trong, Sammy Jersey #: 3 Position: handler Patel, Jayant Jersey #: 4 Position: handler Ozaeta, Myra Jersey #: 5 Position: cutter Holbrook, Lisa Jersey #: 6 Position: cutter Kvale, Lisbeth Jersey #: 7 Position: cutter Henry, Malik Jersey #: 8 Position: handler Captain: offense Pak, Joseph Jersey #: 9 Position: cutter Captain: defense Printing cutters: Ozaeta, Myra Jersey #: 5 Position: cutter Holbrook, Lisa Jersey #: 6 Position: cutter Kvale, Lisbeth Jersey #: 7 Position: cutter Pak, Joseph Jersey #: 9 Position: cutter Captain: defense Printing handlers: Trong, Sammy Jersey #: 3 Position: handler Patel, Jayant Jersey #: 4 Position: handler Henry, Malik Jersey #: 8 Position: handler Captain: offense
CODE TO COPY:
import java.util.ArrayList;
class Person{
private String firstName;
private String lastName;
public Person(String fname, String lname)
{
firstName=fname;
lastName=lname;
}
@Override
public String toString()
{
return lastName+", "+firstName;
}
}
class UltimatePlayer extends Person{
private int jerseyNumber;
private static int uniqNumber;
private String position;
static {
uniqNumber=1;
}
public UltimatePlayer(String fname, String lname, String position)
{
super(fname, lname);
if(!position.equalsIgnoreCase("Handler") && (!position.equalsIgnoreCase("Cutter")))
this.position="Handler";
else
this.position=position;
this.jerseyNumber=uniqNumber;
uniqNumber++;
}
public String getPosition()
{
return position;
}
@Override
public String toString()
{
return super.toString()+"\n Jersey #: "+jerseyNumber+"\n Position: "+position;
}
}
class Captain extends UltimatePlayer{
private boolean isOffence;
public Captain(String fname, String lname, String position, boolean type) {
super(fname, lname, position);
this.isOffence=type;
// TODO Auto-generated constructor stub
}
@Override
public String toString()
{
return super.toString()+"\n Captain: "+(isOffence?"Offence":"Defence");
}
}
class Coach extends Person{
private String role;
public Coach(String fname, String lname, String role) {
super(fname, lname);
this.role=role;
// TODO Auto-generated constructor stub
}
@Override
public String toString()
{
return super.toString()+"\n Role: "+role;
}
}
class UltimateTeam{
private ArrayList<UltimatePlayer> players;
private ArrayList<Coach> coaches;
public UltimateTeam(ArrayList<UltimatePlayer> players, ArrayList<Coach> coaches)
{
this.players=players;
this.coaches=coaches;
}
public String getCutters()
{
String res="";
for(UltimatePlayer player: players)
{
if(player.getPosition().equalsIgnoreCase("Cutter"))
res+=player+"\n";
}
return res;
}
public String getHandlers()
{
String res="";
for(UltimatePlayer player: players)
{
if(player.getPosition().equalsIgnoreCase("Handler"))
res+=player+"\n";
}
return res;
}
public String toString()
{
String coaches="COACHES: \n\n";
String players="PLAYERS: \n\n";
for(Coach coach: this.coaches)
{
coaches+=coach+"\n\n";
}
for(UltimatePlayer player: this.players)
{
players+=player+"\n\n";
}
return coaches+"\n\n"+players;
}
}
public class UltimateFrisbee {
public static void main(String[] args) {
UltimatePlayer pl1=new UltimatePlayer("John", "Cena", "Handler");
UltimatePlayer pl2=new UltimatePlayer("Big", "Show", "Cutter");
UltimatePlayer pl3=new UltimatePlayer("P.V ", "Sindhu", "Handler");
UltimatePlayer pl4=new UltimatePlayer("Saina", "Nehwal", "Handler");
UltimatePlayer pl5=new UltimatePlayer("Virat", "Kohli", "Cutter");
UltimatePlayer pl6=new UltimatePlayer("M.S", "Dhoni", "Cutter");
UltimatePlayer pl7=new UltimatePlayer("Suresh", "Raina", "Cutter");
Coach coach1=new Coach("Lera", "Serra", "Head Coach");
Coach coach2=new Coach("Amyra", "Kiara", "Senior Coach");
ArrayList<UltimatePlayer> players=new ArrayList<UltimatePlayer>();
players.add(pl1);
players.add(pl2);
players.add(pl3);
players.add(pl4);
players.add(pl5);
players.add(pl6);
players.add(pl7);
ArrayList<Coach> coaches=new ArrayList<Coach>();
coaches.add(coach1);
coaches.add(coach2);
UltimateTeam team=new UltimateTeam(players, coaches);
System.out.println(team);
}
}
PROGRAM SCREENSHOTS:
OUTPUT:
Assignment 3: Ultimate Frisbee For this assignment, you will create a hierarchy of five classes to...
The classes you will write are: Person, UltimatePlayer, Captain, Coach, and UltimateTeam. Detailed below are the requirements for the variables and methods of each class. You may need to add a few additional variables and/or methods; figuring out what is needed is part of your task for this assignment.PersonVariablesString firstName - Holds the person's first name.String lastName - Holds the person's last name.MethodsPerson(String firstName, String lastName) - Constructor that takes in String parameters representing the first and last names.int throwDisc(int pow) - returns the...
Introduction In this lab, you will be working with three classes: Person, Student, and Roster. Person and Student represent individuals with a first and last name as String class variables, and Student has an additional int class variable that represents a ID number. The Roster class represents a group of people that are objects of either the Person or Student class. It contains an ArrayList. The Person class has been completed for you with class variables, a constructor, and a...
For this lab assignment, you will be writing a few classes that can be used by an educator to grade multiple choice exams. It will give you experience using some Standard Java Classes (Strings, Lists, Maps), which you will need for future projects. The following are the required classes: Student – a Student object has three private instance variables: lastName, a String; firstName, a String; and average, a double. It has accessor methods for lastName and firstName, and an accessor...
This java assignment will give you practice with classes, methods, and arrays. Part 1: Player Class Write a class named Player that stores a player’s name and the player’s high score. A player is described by: player’s name player’s high score In your class, include: instance data variables two constructors getters and setters include appropriate value checks when applicable a toString method Part 2: PlayersList Class Write a class that manages a list...
In this assignment, we will be making a program that reads in customers' information, and create a movie theatre seating with a number of rows and columns specified by a user. Then it will attempt to assign each customer to a seat in a movie theatre. 1. First, you need to add one additional constructor method into Customer.java file. Method Description of the Method public Customer (String customerInfo) Constructs a Customer object using the string containing customer's info. Use the...
HELP....ITS CLOSING TONIGHT INFSCI 0017 – Assignment 4 You are doing an internship in a company specialized in create role-‐playing computer games. As a part of the programming team, you are asked to implement and test the first version of a RolePlayer class. In the game, a RolePlayer is a knight with the mission of fight and kill monsters: vampires and werewolves. As the player defeat monsters, he/she gains points. The player is considered trainee if he/she has less than...
Assignment Overview In Part 1 of this assignment, you will write a main program and several classes to create and print a small database of baseball player data. The assignment has been split into two parts to encourage you to code your program in an incremental fashion, a technique that will be increasingly important as the semester goes on. Purpose This assignment reviews object-oriented programming concepts such as classes, methods, constructors, accessor methods, and access modifiers. It makes use of...
Activity: Writing Classes Page 1 of 10 Terminology attribute / state behavior class method header class header instance variable UML class diagram encapsulation client visibility (or access) modifier accessor method mutator method calling method method declaration method invocation return statement parameters constructor Goals By the end of this activity you should be able to do the following: > Create a class with methods that accept parameters and return a value Understand the constructor and the toString method of a class...
Please try to write the code with Project 1,2 and 3 in mind. And use java language, thank you very much. Create an Edit Menu in your GUI Add a second menu to the GUI called Edit which will have one menu item called Search. Clicking on search should prompt the user using a JOptionPane input dialog to enter a car make. The GUI should then display only cars of that make. You will need to write a second menu...
Solve it for java Question Remember: You will need to read this assignment many times to understand all the details of the you need to write. program Goal: The purp0se of this assignment is to write a Java program that models an elevator, where the elevator itself is a stack of people on the elevator and people wait in queues on each floor to get on the elevator. Scenario: A hospital in a block of old buildings has a nearly-antique...