My name is earth000.
I want to change the order of people and I want to everyoneAT()to be linked.
Explaining in detail with public class Lead,
white, zap black, zap yellow, kaboom
↓ li.swap()
black, zap yellow, kaboom white, zap
Please check Hunter, Swordman, clergyman and Group. The other code is a copy of the problem statement.
public class Human {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Human() {
setName("no name");
}
public Human(String name) {
this();
setName(name);
}
}
/////////////
public class Hunter extends Human{
public Hunter(){}
public Hunter(String name){
super(name);
}
public String attack(){
return "Yaa";
}
}
///////
public class Swordman extends Hunter{
public Swordman(){
}
public Swordman(String name){
super(name);
}
public String attack(){
return "zap";
}
}
/////////////////
public class Clergyman extends Hunter{
public clergyman(){ }
public clergyman(String name){
super(name);
}
public String attack(){
return "kaboom";
}
}
///////////
import java.util.StringJoiner;
import java.util.ArrayList;
public class Humans <T extends Human> {
ArrayList<T> people;
public Humans() {
people = new ArrayList<>();
}
public void add(T one) {
people.add(one);
}
public int size() {
return people.size();
}
@Override
public String toString() {
StringJoiner j = new StringJoiner(", ");
for (T one : people)
j.add(one.getName());
return j.toString();
}
}
///////////
import java.util.StringJoiner;
public class Group extends Humans<Hunter>{
public Group(){
super();
}
public void swap(){
String lead = people(0);
for(int i=0;i<size()-1;i++){
people(i) = people(i+1);
}
people(size()-1) = lead;
if(size()<=1){return;}
}
public String everyoneAT(){
StringJoiner j = new StringJoiner(", ");
for(T one : people){
j.add(one.Attack());
return j.toString();
}
}
}
//////////////////////First challenge
import java.human.*;
public class First{
public static void main(String[] args){
Group li = new Group();
li.add(new Swordman("white"));
li.add(new Swordman("black"));
li.add(new Clergyman("yellow"));
System.out.println(li);
System.out.println(li.everyoneAT());
li.swap();
System.out.println(li);
System.out.println(li.everyoneAT());
}
}
/////////Second challenge
import java.Human.*;
public class Second{
public static void main(String[] args){
Group li = new Group();
System.out.println(li);
System.out.println(li.everyoneAT());
li.swap();
System.out.println(li);
System.out.println(li.everyoneAT());
}
}
///Third challenge
import java.human*;
public class Third{
public static void main(String[] args){
Group li = new Group();
li.add(new Swordman("white"));
System.out.println(li);
System.out.println(li.everyoneAT());
li.swap();
System.out.println(li);
System.out.println(li.everyoneAT());
}
}