Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
assignment 3
//'main' method must be in a class 'Rextester'. //Compiler version 1.8.0_111 import java.util.*; import java.lang.*; import java.util.Scanner; import java.lang.Math; import java.util.ArrayList; class Rextester { public static void main(String[] args) { Person person = new Person("John", "Doe"); System.out.println("Printing person:\n" + person + "\n"); UltimatePlayer player = new UltimatePlayer("Mary", "Smith", "cutter"); System.out.println("Printing player:\n" + player + "\n"); Captain captain = new Captain("Henry", "Tully", "handler", true); System.out.println("Printing captain:\n" + captain + "\n"); Coach coach = new Coach("Sara", "Lee", "Head coach"); System.out.println("Printing coach:\n" + coach + "\n"); ArrayList<UltimatePlayer> players = new ArrayList<UltimatePlayer>(); players.add(new UltimatePlayer("Sammy", "Trong", "handler")); players.add(new UltimatePlayer("Jayant", "Patel", "handler")); players.add(new UltimatePlayer("Myra", "Ozaeta", "cutter")); players.add(new UltimatePlayer("Lisa", "Holbrook", "cutter")); players.add(new UltimatePlayer("Lisbeth", "Kvale", "cutter")); players.add(new Captain("Malik", "Henry", "handler", true)); players.add(new Captain("Joseph", "Pak", "cutter", false)); ArrayList<Coach> coaches = new ArrayList<Coach>(); coaches.add(new Coach("Maryam", "Mathour", "Head Coach")); coaches.add(new Coach("Soren", "Van Loben Sels", "Assistant Coach")); UltimateTeam team = new UltimateTeam(players, coaches); System.out.println("Printing team:\n" + team.toString() + "\n"); System.out.println("Printing cutters:\n" + team.getCutters() + "\n"); System.out.println("Printing handlers:\n" + team.getHandlers() + "\n"); } } class Person { //private ArrayList <Boxcar> train = new ArrayList <Boxcar>(); private String frstName = ""; private String lstName = ""; //private String tempstr = ""; //private int tempnumero = 0; public Person(String firstName, String lastName) { frstName = firstName; lstName = lastName; } public String toString() { return (lstName + ", " + frstName); } } class UltimatePlayer extends Person { //private ArrayList <Boxcar> train = new ArrayList <Boxcar>(); private int jerseyNumber = 0; private static int num = 0; private String psition = ""; //private String tempstr = ""; //private int tempnumero = 0; public UltimatePlayer(String firstName, String lastName, String position) { super(firstName,lastName); psition = position; if ( (position).equals("handler") || (position).equals("cutter") ) psition = position; else { psition = "handler"; } num++; jerseyNumber = num; } public String getPosition() { return (psition); } public String toString() { return (super.toString() + "\n " + "Jersey #: " + jerseyNumber + "\n Position: " + psition); } } class Captain extends UltimatePlayer { //private ArrayList <Boxcar> train = new ArrayList <Boxcar>(); private boolean typee = false; //private String tempstr = ""; //private int tempnumero = 0; public Captain(String firstName, String lastName, String position, boolean type) { super(firstName,lastName,position); typee = type; } public String getType() { if (typee == true) return ("offense"); else return ("defense"); } public String toString() { return (super.toString() + "\n " + "Captain: " + getType()); } } class Coach extends Person { //private ArrayList <Boxcar> train = new ArrayList <Boxcar>(); private String rle = ""; //private String tempstr = ""; //private int tempnumero = 0; public Coach(String firstName, String lastName, String role) { super(firstName,lastName); rle = role; } public String toString() { return (super.toString() + "\n " + "Role: " + rle); } } class UltimateTeam { private ArrayList <UltimatePlayer> playerz = new ArrayList <UltimatePlayer>(); private ArrayList <Coach> coachez = new ArrayList <Coach>(); private String rle = ""; private String tempstr = ""; private String tempstr2 = ""; //private int tempnumero = 0; public UltimateTeam (ArrayList<UltimatePlayer> players, ArrayList<Coach> coaches) { playerz = (ArrayList<UltimatePlayer>) players.clone(); coachez = (ArrayList<Coach>) coaches.clone(); } public String getCutters() { tempstr = ""; for(UltimatePlayer s: playerz) { if ((s.getPosition()).equals("cutter")) { tempstr = (tempstr + "\n" + String.valueOf(s)); } } return (tempstr); } public String getHandlers() { tempstr = ""; for(UltimatePlayer s: playerz) { if ((s.getPosition()).equals("handler")) { tempstr = (tempstr + "\n" + String.valueOf(s)); } } return (tempstr); } public String toString() { tempstr = ""; for(Coach s: coachez) { tempstr = (tempstr + "\n" + String.valueOf(s)); } tempstr2 = ""; for(UltimatePlayer s: playerz) { tempstr2 = (tempstr2 + "\n" + String.valueOf(s)); } return ("COACHES" + "\n" + tempstr + "\nPLAYERS\n" + tempstr2 ); } }
run
|
edit
|
history
|
help
0
Strings Ops
Product of Array Except Self
bit left 2
add2
luas
Java tree
Main
Rextester.java
1*2-3+4
4c