Results 1 to 6 of 6
  1. #1
    Bgreen7887 is offline Senior Member
    Join Date
    Oct 2010
    Location
    Newark,nj
    Posts
    111
    Rep Power
    0

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

    Java 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 + ".");
    } 
     
    }
    Java 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();
    	 
    	 
    	 }
    
    }
    Java 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;
    	}

  2. #2
    joshdgreen's Avatar
    joshdgreen is offline Senior Member
    Join Date
    Oct 2010
    Location
    Colorado Springs, CO
    Posts
    212
    Rep Power
    4

    Default

    I don't see anything here that shows me that you tried to figure it out yourself. All you did was post the problem and ask us to do it for you.
    Sincerely, Joshua Green
    Please REP if I help :)

  3. #3
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Location
    Zurich, Switzerland
    Posts
    962
    Rep Power
    5

    Default

    the constructors are wrong, so please read this first.

  4. #4
    Bgreen7887 is offline Senior Member
    Join Date
    Oct 2010
    Location
    Newark,nj
    Posts
    111
    Rep Power
    0

    Default

    Thanks for help guys. I actually did create the teammate class...I was stuck once i finished that. fyi all the codes were compiled from scratch so i actually did do something. its just manipulating something that was already done previously.And i didn't want answers i needed someone to point out wat was wrong so i could fix it.Sorry for misunderstanding:):):):)

  5. #5
    al_Marshy_1981 is offline Senior Member
    Join Date
    Feb 2010
    Location
    Waterford, Ireland
    Posts
    748
    Rep Power
    5

    Default

    Some quick observations...
    Java Code:
    public x (String n,String p,teammate1,teammate2)
    you are missing type for teammate1 and teammate2.

    Java Code:
    this.teammate1 = teammate1;
    this.teammate2 = teammate2;
    There are no member fields called teammate1 or teammate2

  6. #6
    Bgreen7887 is offline Senior Member
    Join Date
    Oct 2010
    Location
    Newark,nj
    Posts
    111
    Rep Power
    0

    Default

    ok so after all the editing i've gotten this so far..instead of printing the teammate1 variable it prints teammate@108471f (idk if thats like a point in memory or what)..I believe i fixed the constructors...:):):):D

    Java Code:
      [B] public class xmen [/B]{
          public static void main(String[]args) 
          {
             Teammate teammate1 = new Teammate("B-LOVE","GUNZ",8);
          System.out.println(teammate1);
          
             x wolv;
             wolv = new x("Logan","heal",teammate1);
             wolv.action();
          
          
             x storm;
             storm = new x("Storm","Lightning");
             storm.action();
          
             x magnito;
             magnito = new x("Magnito","Running");
             magnito.action();
          
          
          }
       
       }
    Java Code:
     [B]  public class x [/B]{
        public String name,power;
    	public Teammate teammate1, teammate2;
    
    public x (String n,String p,Teammate teammate1,Teammate teammate2) {
     name = n;
     power = p;
     this.teammate1 = teammate1;
     this.teammate2 = teammate2;
     }
     
     
     public x (String n,String p,Teammate teammate1) {
     name = n;
     power = p;
      this.teammate1 = teammate1;
      }
      
     public x (String n, String p) {
     name = n;
     power = p;
     }
     public x (String n) {
     name = n;
     } 
     public x() { }
     // FINISHED SETTING UP 5 CONSTRUCTORS.
     
     void action () {
     System.out.println("Name is " + name + ".");
    
     System.out.println("My Powers are " + power + ".");
      System.out.println("My teammate is " + teammate1);
    
    } 
     
    }
    Java Code:
    [B]public class Teammate[/B] {
    String name,power;
    int confidence;
    	public Teammate (String na,String po,int c	 ) {
     			name=na;
     			power= po;
     			confidence =c;
    	}
    	public Teammate (String na,String po) {
    	name = na;
    	power = po;
    	}
    	public Teammate(String na) {
    	name = na;
    	}
    	public Teammate() {}
    
    }

Similar Threads

  1. Calling Methods between classes?
    By questionanswer in forum New To Java
    Replies: 2
    Last Post: 03-22-2010, 01:22 AM
  2. Child-Class Calling a Method in a Parent-Class
    By Blah_ in forum New To Java
    Replies: 5
    Last Post: 09-29-2009, 02:48 AM
  3. Calling a method on original class from created class
    By kpedersen in forum Advanced Java
    Replies: 4
    Last Post: 08-20-2008, 12:25 AM
  4. Calling jar classes from java executable
    By SteM in forum Advanced Java
    Replies: 1
    Last Post: 11-27-2007, 08:21 AM
  5. Replies: 2
    Last Post: 11-11-2007, 08:07 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •