Results 1 to 3 of 3
  1. #1
    JoelC is offline Member
    Join Date
    Nov 2012
    Posts
    6
    Rep Power
    0

    Default Array of Objects, not working!

    Hi i'm trying to create an array of objects, for the first time, could anyone help me sort this out. Thank you in advance.

    Java Code:
    import java.util.*;
    	
    class Student{
    	
    	String name;
    	int id, entryYear, progressionLevel;
    	boolean isRegistered, fullTime;
    	int totalCourses = 7;
    
    	public static void main(String[] args){
    	
    	
    	Module module = new Module (1, 58, true); 
        printModule (module); 
    	
    		}//end method() main
    	
    	
    
    }//end class Student
    
    
    import java.util.*;
    	
    public class Module 
    {
    	int moduleName;
    	float mark;
    	boolean passed;
    	
    	
    	public void Module() {
    	this.moduleName = 0; 
    	this.mark = 0; 
    	this.passed = false; 
    	}//end method Module
    	
    	
    	public void Module(int moduleName,float mark, boolean passed) {
    		this.moduleName = moduleName;
    		this.mark = mark;
    		this.passed = passed;
    	}//end Method() module(a,b,c)
    	
    	public static void printModule (Module m) {
    	String[] moduleNames = {"MUSIC COMPUTING 1","APPROACHES TO 20TH CENTURY MUSICS", "TONAL HARMONY AND FORM", "MUSIC TECHNOLOGY", "AV COMPUTING", "INTRODUCTION TO PROGRAMMING", "MATHEMATICAL MODELLING FOR PROBLEM SOLVING"};
    	System.out.println (moduleNames[m.moduleName]);
    	}//end method() printModule
    	
    	
    	
    	
    }//end class module
    so basically i get an error when compiling Student class. below:

    $ javac Student.java
    Student.java:38: cannot find symbol
    symbol : constructor Module(int,int,boolean)
    location: class Module
    Module module = new Module (1, 58, true);
    ^
    Student.java:39: cannot find symbol
    symbol : method printModule(Module)
    location: class Student
    printModule (module);
    ^
    2 errors

    any advice would be much appreciated.

  2. #2
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    6

    Default Re: Array of Objects, not working!

    Your constructor for Module requires an int, a float, and a boolean, but you are giving it an int, int, password. Give it a float for the second param instead, something like:
    Java Code:
    Module module = new Module (1, 58.0F, true);

  3. #3
    Jingoism is offline Member
    Join Date
    Nov 2012
    Posts
    14
    Rep Power
    0

    Default Re: Array of Objects, not working!

    These are constructors for your class Module, and should therefore not have a type specified ( ie. void ).

    Java Code:
    public Module() {
        	this.moduleName = 0; 
        	this.mark = 0; 
        	this.passed = false; 
        }//end method Module
         
         
        public Module(int moduleName,float mark, boolean passed) {
            this.moduleName = moduleName;
            this.mark = mark;
            this.passed = passed;
        }//end Method() module(a,b,c)

    Also here I think you mean to call the method printModule from the object you just instantiated. So would be more like:


    Java Code:
    module.printModule(module);
    Take all this with a grain o salt as I too am new to this.

Similar Threads

  1. Using an array of objects
    By katiebear128 in forum New To Java
    Replies: 2
    Last Post: 11-17-2011, 06:05 PM
  2. How to convert array of Objects into array of Strings
    By elenora in forum Advanced Java
    Replies: 1
    Last Post: 06-10-2011, 03:48 PM
  3. Working with many objects
    By Reshi in forum New To Java
    Replies: 2
    Last Post: 12-06-2010, 10:26 AM
  4. Trouble working with/calling Objects! Any Help?
    By ramathews in forum New To Java
    Replies: 4
    Last Post: 03-24-2010, 02:50 PM
  5. Working with Vector objects + textfile
    By SGRocker in forum New To Java
    Replies: 5
    Last Post: 09-16-2008, 10:55 PM

Tags for this Thread

Posting Permissions

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