Results 1 to 3 of 3
Thread: Array of Objects, not working!
- 11-15-2012, 08:08 PM #1
Member
- Join Date
- Nov 2012
- Posts
- 6
- Rep Power
- 0
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
$ 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.
- 11-15-2012, 08:22 PM #2
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);
- 11-16-2012, 09:49 AM #3
Member
- Join Date
- Nov 2012
- Posts
- 14
- Rep Power
- 0
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);
Similar Threads
-
Using an array of objects
By katiebear128 in forum New To JavaReplies: 2Last Post: 11-17-2011, 07:05 PM -
How to convert array of Objects into array of Strings
By elenora in forum Advanced JavaReplies: 1Last Post: 06-10-2011, 04:48 PM -
Working with many objects
By Reshi in forum New To JavaReplies: 2Last Post: 12-06-2010, 11:26 AM -
Trouble working with/calling Objects! Any Help?
By ramathews in forum New To JavaReplies: 4Last Post: 03-24-2010, 03:50 PM -
Working with Vector objects + textfile
By SGRocker in forum New To JavaReplies: 5Last Post: 09-16-2008, 11:55 PM
Bookmarks