Question

Assignment 9: Ultimate Frisbee

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.

  • int throwDisc(int pow) - returns the distance in yards a frisbee is thrown by the person. This is calculated by multiplying the power of the throw by 2. The power is given by the parameter pow, with a minimum value of 1 if pow is below this, and a maximum value of 10 if pow is above this.

  • String toString() - Returns a String with the following format: lastName, firstName

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: ...".

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.

  • int throwDisc(int pow) - returns the distance in yards a frisbee is thrown by the player. This is calculated by multiplying the power of the throw by 4. The power is given by the parameter pow, with a minimum value of 1 if pow is below this, and a maximum value of 10 if pow is above this.

  • 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.

  • int throwDisc(int pow) - returns the distance in yards a frisbee is thrown by the person. This is calculated by multiplying the power of the throw by 5. The power is given by the parameter pow, with a minimum value of 1 if pow is below this, and a maximum value of 10 if pow is above this.

  • 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: ...".

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” in the order they appear in the players list. Each String can be produced using the toString method, and should be followed by a line break.

  • String getHandlers() - Returns a String listing all the UltimateTeams's UltimatePlayers that have the position of “handler” in the order they appear in the players list. Each String can be produced using the toString method, and should be followed by a line break.

  • String toString() - Returns a multiline String listing the Coaches and UltimatePlayers on the UltimateTeam. The String is formatted as shown in this example:

COACHES
Mathour, Maryam
   Role: Head Coach
Van Loben Sels, Soren
   Role: Assistant Coach

PLAYERS
Trong, Sammy
   Jersey #: 1
   Position: handler
Patel, Jayant
   Jersey #: 2
   Position: handler
Ozaeta, Myra
   Jersey #: 3
   Position: cutter
Holbrook, Lisa
   Jersey #: 4
   Position: cutter
Kvale, Lisbeth
   Jersey #: 5
   Position: cutter
Henry, Malik
   Jersey #: 6
   Position: handler
   Captain: offense
Pak, Joseph
   Jersey #: 7
   Position: cutter
   Captain: defense

The coaches listing is made up of all items from the coaches ArrayList in order. The players listing is made up of all items from the players ArrayList in order.

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.

Use the runner class main method to test all your classes, and please don't add a main method to any of the other classes or your code may not be marked correctly.

When debugging your code it makes sense to debug the classes higher in the hierarchy first: for example the methods in the Captain class may not work correctly until the methods in its parent class (UltimatePlayer) work properly. The last thing to debug is the UltimateTeam class, as this relies on methods from all the other classes created.

Milestones

As you work on this assignment, you can use the milestones below to inform your development process:

Milestone 1: Write the Person class, then write the Coach class extending the Person class with all methods implemented.

Milestone 2: Write the UltimatePlayer class extending the Person class with all methods implemented.

Milestone 3: Write the Captain class extending the UltimatePlayer class with all methods implemented.

Milestone 4: Write the UltimateTeam class and implement all the methods it contains.


0 0
Add a comment Improve this question Transcribed image text
Answer #1

//===Person.java=====================

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<1)

    pow=1;

    else if(pow>10)

    pow=10;

    return 2*pow;

  }

  public String toString() {

    return firstName+", "+lastName;

  }

}

//==end of Person.java================

//==Coach.java================================

public class Coach extends Person {

  private String role;

  public Coach(String firstName, String lastName,String role) {

    super(firstName, lastName);

    this.role=role;

  }

  public String toString() {

    String str="";

    str+=super.toString()+"\n";

    str+=" Role: "+role;

    return str;

  }

  

}

//==end of Coach.java==========================

//==UltimatePlayer.java=============================

public class UltimatePlayer extends Person {

  private int jersyNumber;

  private String position;//possible values "handler" and "cutter"

  private static int count;

  

  public UltimatePlayer(String firstName, String lastName,String position) {

    super(firstName, lastName);

    if(position.equals("handler")==false && position.equals("cutter")==false)

    this.position="handler";

    else

    this.position=position;

    count++;

    jersyNumber=count;

  }

  public String getPosition() {

    return position;

  }

  public int throwDisc(int pow) {

    if(pow<1)

    pow=1;

    else if(pow>10)

    pow=10;

    return 4*pow;

  }

  public String toString() {

    String str="";

    str+=super.toString()+"\n";

    str+=" Jersey #: "+jersyNumber+"\n";

    str+=" Position: "+position;

    return str;

  }

  

}

//==end of UltimatePlayer.java=======================

//==Captain,java========================

public class Captain extends UltimatePlayer {

  private boolean type;//true for offense, false for defense

  public Captain(String firstName, String lastName, String position,boolean type) {

    super(firstName, lastName, position);

    this.type=type;

  }

  public int throwDisc(int pow) {

    if(pow<1)

    pow=1;

    else if(pow>10)

    pow=10;

    return 5*pow;

  }

  public String toString() {

    String str="";

    str+=super.toString()+"\n";

    if(type)

    str+=" Captain: "+"offense";

    else

    str+=" Captain: "+"defense";

    return str;

  }

}

//==end of Captain.java====================

//==UltimateTeam.java=======================

import java.util.ArrayList;

public 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 str="";

    for(int i=0;i<players.size();i++) {

      if(players.get(i).getPosition().equals("cutter"))

      str+=players.get(i).toString()+"\n";

    }

    return str;

  }

  public String getHandlers() {

    String str="";

    for(int i=0;i<players.size();i++) {

      if(players.get(i).getPosition().equals("handler"))

      str+=players.get(i).toString()+"\n";

    }

    return str;

  }

  public String toString() {

    String str="";

    str+="COACHES\n";

    for(int i=0;i<coaches.size();i++)

    str+=coaches.get(i).toString()+"\n";

    str+="\n";

    str+="PLAYERS\n";

    for(int i=0;i<players.size();i++)

    str+=players.get(i).toString()+"\n";

    

    return str;

  }

}

//==end of UltimateTeam.java==================

//==runner_Ultimate.java=====================

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();

  }

}

//==end of runner_Ultimate.java================


answered by: codegates
Add a comment
Know the answer?
Add Answer to:
Assignment 9: Ultimate Frisbee
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Assignment 3: Ultimate Frisbee For this assignment, you will create a hierarchy of five classes to...

    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...

  • Introduction In this lab, you will be working with three classes: Person, Student, and Roster. Person...

    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...

  • Start a new project in NetBeans that defines a class Person with the following: Instance variables...

    Start a new project in NetBeans that defines a class Person with the following: Instance variables firstName (type String), middleInitial (type char) and lastName (type String) (1) A no-parameter constructor with a call to the this constructor; and (2) a constructor with String, char, String parameters (assign the parameters directly to the instance variables in this constructor--see info regarding the elimination of set methods below) Accessor (get) methods for all three instance variables (no set methods are required which makes...

  • help please Program Requirements You are given 1 file: Lab1Tests.java. You need to complete 1 file:...

    help please Program Requirements You are given 1 file: Lab1Tests.java. You need to complete 1 file: UWECPerson.java uWECPerson.java UWECPerson uwecld: int firstName: String lastName : String +UWECPerson(uwecld: int, firstName : String, lastName: String) +getUwecid): int setUwecld(uwecld: int): void +getFirstName): String +setFirstName(firstName: String): void getLastName): String setLastName(lastName: String): void +toString): String +equals(other: Object): boolean The constructor, accessors, and mutators behave as expected. The equals method returns true only if the parameter is a UWECPerson and all instance variables are equal. The...

  • C# programming 50 pts Question 2:2 1- Create the base class Book that has the following instance variables, constructor, and methods title (String) isbn (String) authors (String) publisher (Strin...

    C# programming 50 pts Question 2:2 1- Create the base class Book that has the following instance variables, constructor, and methods title (String) isbn (String) authors (String) publisher (String) edition ( int) published year (int) Constructor that takes all of the above variables as input parameters. set/get methods ToString method// that return sting representation of Book object. 2-Create the sub class New_Book that is derived from the base class Book and has the following instance variables, constructor, and methods: title...

  • Write a class called Course_xxx that represents a course taken at a school. Represent each student...

    Write a class called Course_xxx that represents a course taken at a school. Represent each student using the Student class from the Chapter 7 source files, Student.java. Use an ArrayList in the Course to store the students taking that course. The constructor of the Course class should accept only the name of the course. Provide a method called addStudent that accepts one Student parameter. Provide a method called roll that prints all students in the course. Create a driver class...

  • DIRECTIONS FOR THE WHOLE PROJECT BELOW BigInt class The purpose of the BigInt class is to...

    DIRECTIONS FOR THE WHOLE PROJECT BELOW BigInt class The purpose of the BigInt class is to solve the problem using short methods that work together to solve the operations of add, subtract multiply and divide.   A constructor can call a method called setSignAndRemoveItIfItIsThere(). It receives the string that was sent to the constructor and sets a boolean variable positive to true or false and then returns a string without the sign that can then be processed by the constructor to...

  • I have a little problem about my code. when i'm working on "toString method" in "Course"...

    I have a little problem about my code. when i'm working on "toString method" in "Course" class, it always say there is a mistake, but i can not fix it: Student class: public class Student {    private String firstName;    private String lastName;    private String id;    private boolean tuitionPaid;       public Student(String firstName, String lastName, String id, boolean tuitionPaid)    {        this.firstName=firstName;        this.lastName=lastName;        this.id=id;        this.tuitionPaid=tuitionPaid;    }   ...

  • I have currently a functional Java progam with a gui. Its a simple table of contacts...

    I have currently a functional Java progam with a gui. Its a simple table of contacts with 3 buttons: add, remove, and edit. Right now the buttons are in the program but they do not work yet. I need the buttons to actually be able to add, remove, or edit things on the table. Thanks so much. Here is the working code so far: //PersonTableModel.java import java.util.List; import javax.swing.table.AbstractTableModel; public class PersonTableModel extends AbstractTableModel {     private static final int...

  • What this Lab Is About: Given a UML diagram, learn to design a class Learn how...

    What this Lab Is About: Given a UML diagram, learn to design a class Learn how to define constructor, accessor, mutator and toStringOmethods, etc Learn how to create an object and call an instance method. Coding Guidelines for All ments You will be graded on this Give identifiers semantic meaning and make them easy to read (examples numStudents, grossPay, etc) Keep identifiers to a reasonably short length. Use upper case for constants. Use title case (first letter is u case)...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT