using and calling class within classes..
hey guys need some help with this hw problem..1. Aggregation. Modify the Xmen class we have been discussing such that it has two variables teammate1 and teammate2 of class Teammate. This Teammate class has three variables: name, power, and confidence, where confidence indicates how confident the teammate is considered. Assume 10 being the highest while 0 being the lowest, indicating no confidence.
Provide all the necessary getters and setters for Xmen class as well as Teammate.
Provide a toString method that returns a summary of an Xmen object with its teammate information.
Overload the Xmen constructor such that an Xmen object may be created with or without temamates, or even without the name and power. In the latter case default initialization should be provided. In summary, there will be five Xmen constructors:
* Xmen(name,power,teammate1,teammate2)
* Xmen(name,power,teammate1)
* Xmen(name,power)
* Xmen(name)
* Xmen()
Teammate will be overloaded as well with the following four constructors:
* Teammate(name,power,confidence)
* Teammate(name,power)
* Teammate(name)
* Teammate()
When no teammates are provided at the time of initialization, you must provide two default teammates of your choice.
Write a driver that creates 10 different Xmen objects each of which has two teammates.
Find the fantastic four that shows (a) the top four number of appearances as a teammate, and (b) the top four confidence.
Find the team leader of the fantastic four with (a) the highest number of appearances as a teammate, and (b) the highest confidence.
When creating 10 Xmen characters, you need to be imaginative to use various combination of names, power, teammates, confidence, etc.
.HERE ARE THE THREE CODES.
Code:
[B]public class x [/B]{
String name;
String power;
public x (String n,String p,teammate1,teammate2) {
name = n;
power = p;
this.teammate1 = teammate1;
this.teammate2 = teammate2;
}
public x (String n,String p, teammate1) {
name = n;
power = p;
this.teammate1 = teammate1;
}
public x (String n, String p) {
name = n;
power = p;
}
public x (name) {
name = n;
}
public x() {
name = n
power = p;
this.teammate1 = teammate1;
this.teammate2 = teammate2;
}
// FINISHED SETTING UP 5 CONSTRUCTORS.
void action () {
System.out.println("Name is " + name + ".");
System.out.println("My Powers are " + power + ".");
}
}
Code:
[B]public class xmen[/B] {
public static void main(String[]args)
{
x wolv;
wolv = new x("Logan","heal");
wolv.action();
x storm;
storm = new x("Storm","Lightning");
storm.action();
x magnito;
magnito = new x("Magnito","Running");
magnito.action();
}
}
Code:
[B]public class Teammate[/B] {
String name,power;
int confidence;
public Teammate (String name,String power,int confidence ) {
this.name = name;
this.power = power;
this.confidence = confidence;
}