Results 1 to 4 of 4
  1. #1
    juxta is offline Member
    Join Date
    Nov 2011
    Posts
    30
    Rep Power
    0

    Default What am I missing out in this simple program?

    Well, I'm back and it has been a while since I last touched on java. Just been fiddling with the code after my lectures. Here's the code:

    Java Code:
    class Band {
    
    	String name = "Goldfrapp";
    	int volume = 5;
    	int attitude = 4;
    	int cool = 14;
    	int eclectism = 44;
    	int hair = 20;
    	
    	public Band (String n, int v, int a, int c, int e, int h){
    		name = n;
    		volume = v;
    		attitude = a;
    		cool = c;
    		eclectism = e;
    		hair = h;
    		
    	}
    	
    	
    	public String getName () {
    		return name;
    	}
    	
    	public int getVolume () {
    		return volume;
    	}
    	
    	public int getAttitude () {
    		return attitude;
    	}
    	
    	
    	public int getCool () {
    		return cool;
    	}
    	
    	public int getEclectism () {
    		return eclectism;
    	}
    	
    	public int getHair () {
    		return hair;
    	}
    	
    
    
    public static void main (String[] args) { 
    	
    	Band myBand = new Band(n,v,a,c,e,h);
    	
    	System.out.println(myBand.getName());
    	System.out.println(myBand.getVolume());
    	System.out.println(myBand.getAttitude());
    	System.out.println(myBand.getCool());
    	System.out.println(myBand.getEclectism());
    	System.out.println(myBand.getHair());
    	
    }
    
    }
    I get an error with the constructor. What have I done wrong?
    Thank you.

  2. #2
    Games2Design is offline Member
    Join Date
    Sep 2012
    Posts
    44
    Rep Power
    0

    Default Re: What am I missing out in this simple program?

    Post the error. "I get an errror" doesn't help anyone :p

  3. #3
    juxta is offline Member
    Join Date
    Nov 2011
    Posts
    30
    Rep Power
    0

    Default Re: What am I missing out in this simple program?

    Quote Originally Posted by Games2Design View Post
    Post the error. "I get an errror" doesn't help anyone :p
    Oops. Okay, here it is:

    Exception in thread "main" java.lang.Error: Unresolved compilation problems:
    n cannot be resolved to a variable
    v cannot be resolved to a variable
    a cannot be resolved to a variable
    c cannot be resolved to a variable
    e cannot be resolved to a variable
    h cannot be resolved to a variable

  4. #4
    Games2Design is offline Member
    Join Date
    Sep 2012
    Posts
    44
    Rep Power
    0

    Default Re: What am I missing out in this simple program?

    This is the errors i got when i ran the program.
    What am I missing out in this simple program?-band.png

    I believe the program lies in that you have said x variable = y variable. When it should be y variable = x variable.
    Example n = name;

    So if you change the order it may work.

    EDIT:
    Nope it didn't work.

    EDIT 2:
    Declare the variables in main method, and then use them as parameters to their respective method. Don't know if that's the approach you want - but it will definetly make the program run as you want it to.
    Last edited by Games2Design; 10-03-2012 at 10:38 PM.

Similar Threads

  1. Simple program, simple problem
    By taymilll in forum New To Java
    Replies: 12
    Last Post: 06-20-2011, 06:12 AM
  2. simple program
    By kayln in forum Eclipse
    Replies: 0
    Last Post: 05-01-2011, 11:03 PM
  3. Please help with simple program.. Very simple.
    By jonytek in forum New To Java
    Replies: 7
    Last Post: 02-14-2011, 01:44 AM
  4. Simple program help
    By jtyler in forum New To Java
    Replies: 3
    Last Post: 09-20-2010, 08:43 AM
  5. Simple Program
    By TheRocket in forum Advanced Java
    Replies: 15
    Last Post: 12-30-2008, 03:35 PM

Posting Permissions

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