Question

Write method createTeams() that Has no parameters Has return type void Instantiate the member variable of...

Write method createTeams() that

Has no parameters

Has return type void

Instantiate the member variable of type ArrayList<Team>

Instantiates two instances of class Team

one for TeamOne

one for TeamTwo

set names for each team as appropriate

add each instance to the ArrayList<Team> member variable

Instantiate the member variable of class Scanner passing “System.in” as the argument to the constructor

Using System.out.println() static method, prompt the user for the human player’s name

Instantiate an instance of class String set equal to the reference object of class Scanner using its method .next()

Instantiate an instance of class HumanPlayer

Call method .setName() on the reference object of class HumanPlayer passing the value stored in the variable from step g. above

Add the reference object of class HumanPlayer to the instance of class Team representing Team One

Write a for loop to generate three AiPlayer instances

Generate a unique name for each AiPlayer and call method .setName() passing the unique name as an argument

Add one AiPlayer instance to the instance of class Team representing Team One

Add the other two AiPlayer instances to the instance of class Team representing Team Two

Write method outputTeams() so that

It has no parameters

Has a return type of void

Uses an enhanced for loop to loop through the collection of member variable of type ArrayList<Team>

Outputs the current Team’s name

Uses an enhanced for loop to loop through the collection of class Team’s member variable ArrayList<Player>

Outputs the current Player’s name

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

public void createTeams(){
list=new ArrayList<Team>();
Team teamOne=new Team();
Team teamTwo=new Team();
teamOne.setName("TeamOne");
teamTwo.setName("TeamTwo");
list.add(teamOne);
list.add(teamTwo);
  
Scanner scn=new Scanner(System.in);
System.out.println("Enter player name");
String name=scn.next();
HumanPlayer plyr = new HumanPlayer();
plyr.setName(name);
  
teamOne.add(plyr);
  
String[] names={"Plr1","Plr2","Plr3"};
AiPlayer[] arr=new AiPlayer[3];
for(int i=0;i<3;i++){
arr[i]=new AiPlayer();
arr[i].setName(names[i]);
}
teamOne.add(arr[0]);
teamTwo.add(arr[1]);
teamTwo.add(arr[2]);
  
}
  
public void outputTeams(){
  
for(Team a : list){
System.out.println("Team Name : "+a.getName());
for(Player p : a.getListOfPlayers()){
System.out.println("Player name : "+p.getName());
}
}
}

Add a comment
Know the answer?
Add Answer to:
Write method createTeams() that Has no parameters Has return type void Instantiate the member variable of...
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
  • CodebreakerUi.java Add member variables of type: Color colorSelected; Updated method initComponents() where it is instantiating the...

    CodebreakerUi.java Add member variables of type: Color colorSelected; Updated method initComponents() where it is instantiating the RoundButtons for the 1D array on the JPanel displaying the codebreaker’s colors; it should add the following Add action listener ColorListener to each round button Updated method initComponents() where it is instantiating the RoundButtons for the 2D array on the JPanel for the codebreaker’s attempt; it should add the following Add client property “row” to each RoundButton set to the current iteration of the...

  • Define a class named Payment that contains an instance variable "paymentAmount" (non-static member variable) of type...

    Define a class named Payment that contains an instance variable "paymentAmount" (non-static member variable) of type double that stores the amount of the payment and appropriate accessor (getPaymentAmount() ) and mutator methods. Also create a method named paymentDetails that outputs an English sentence to describe the amount of the payment. Override toString() method to call the paymentDetails() method to print the contents of payment amount and any other details not included in paymentDetails(). Define a class named CashPayment that is...

  • Write three object-oriented classes to simulate your own kind of team in which a senior member...

    Write three object-oriented classes to simulate your own kind of team in which a senior member type can give orders to a junior member type object, but both senior and junior members are team members. So, there is a general team member type, but also two specific types that inherit from that general type: one senior and one junior. Write a Python object-oriented class definition that is a generic member of your team. For this writeup we call it X....

  • Modification to be completed by group member 4: In the processLineOfData method, write the code to...

    Modification to be completed by group member 4: In the processLineOfData method, write the code to handle case "M" of the switch statement such that: A Manager object is created using the firstName, lastName, salary, and bonus local variables. Notice that salary and bonus need to be converted from String to double. You may use parseDouble method of the Double class as follows:               Double.parseDouble(salary) Call the parsePaychecks method in this class passing the Manager object created in the previous step...

  • PLEASE WRITE IN JAVA FOR Q's A & B: Three investors are starting a new startup....

    PLEASE WRITE IN JAVA FOR Q's A & B: Three investors are starting a new startup. Each investor has a first name, last name and phone number all of type String and the amount of investment dollars of type double. A.) Write an Investor class that includes the above information. 1.) Make the instance variable of the investor class private. 2.) Write getter and setter methods for each instance variable. 3.) Add a constructor method to the investor class that...

  • Write a C++ program for the instructions below. Please read the instructions carefully and make sure they are followed correctly.   and please put comment with code! Problem:2 1. Class Student Create...

    Write a C++ program for the instructions below. Please read the instructions carefully and make sure they are followed correctly.   and please put comment with code! Problem:2 1. Class Student Create a "Hello C++! I love CS52" Program 10 points Create a program that simply outputs the text Hello C++!I love CS52" when you run it. This can be done by using cout object in the main function. 2. Create a Class and an Object In the same file as...

  • MasterMind in Java Activity MasterMind project Create a new Java Application project named MasterMind allowing Netbeans...

    MasterMind in Java Activity MasterMind project Create a new Java Application project named MasterMind allowing Netbeans IDE to create the main class called MasterMind.java MasterMind class Method main() should: Call static method System.out.println() and result in displaying “Welcome to MasterMind!” Call static method JOptionPane.showMessageDialog(arg1, arg2) and result in displaying a message dialog displaying “Let’s Play MasterMind!” Instantiate an instance of class Game() constants Create package Constants class Create class Constants Create constants by declaring them as “public static final”: public...

  • Generics Objectives: OOWorking with a Generic Class 1. Create a class called Node that is Generic...

    java Generics Objectives: OOWorking with a Generic Class 1. Create a class called Node that is Generic. The class has one class attribute that is an element. It will need 2 Constructors, a setter and getter for the class attribute, and a toString method. 2. Write a Lab10Driver that will: Instantiate a Node Integer object with no value. I. Il. Ill. IV. a. Then call the set method to set the value to 5. Instantiate a Node String object with...

  • Download BankAccount.java and BankAccountTester.java starting files and drag and drop them into your eclipse project. The...

    Download BankAccount.java and BankAccountTester.java starting files and drag and drop them into your eclipse project. The BankAccount class declaration in file BankAccount.java is the blueprint of a BankAccount object. Check out the design of a BankAccount class. 1. In BankAccount.java class, all of the method stubs ( methods with a header but empty bodies ) are present to help you get started. Your task is to complete the method bodies. All comments in red in the diagram above indicates what...

  • CompSci 251: Intermediate Computer Programming Spring 2017 -Java Lab 5 For this lab we will be...

    CompSci 251: Intermediate Computer Programming Spring 2017 -Java Lab 5 For this lab we will be looking at static, or class variables. Remember that where instances variables are associated with a particular instance, static variables are associated with the particular class. Specifically, if there are n instances of a class, there are n copies of an instance variable, but exactly one copy of a static variable (even when n = 0). Student - uniqueId : int - id: int -...

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