Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-13-2007, 08:08 PM
Member
 
Join Date: Dec 2007
Posts: 1
rednessc is on a distinguished road
problems with asigning elements of an array to a constructor
I have created an array which holds data that is entered by a user using JOptionPane.

I would now like to create an object of a class called Module that was previously created. But the program says that the constructor module() cannot be found. Can somebody help because I need that object to be declared so that I can display the data that is entered by the user with the use of System.out.print(). Below is the code for the Module class:

public class Module

{
int level, finalMark ;
String moduleCode ;

Module(String mc, int l, int fm)
{
moduleCode = mc;
level = l;
finalMark = fm;
}

public String toString()
{
return level + " " + moduleCode + " " + finalMark ;
}

} // end class Module

Now this is the start of the code for class ModuleTest, where I am stuck. Like explained before, all I need is for the details entered by the user to be stored in an object in order to then display them:

import javax.swing.* ;

public class ModuleTest
{

public static void main ( String [] args )
{
int size ;
size = 3 ;
int level=0 ;
int finalMark ;

String moduleCode ;
String levelStr ;
String finalMarkStr ;

Module [] moduleInfo;
moduleInfo = new Module[size] ;

System.out.printf( "%s %8s %8s\n", "Level" , "ModuleCode", "FinalMark" ) ;
System.out.println( "------------------------------" ) ;

for (int i = 0 ; i < (moduleInfo.length - 1) ; i++ )
{
levelStr = JOptionPane.showInputDialog( "Please enter level: " ) ;

moduleCode = JOptionPane.showInputDialog( "Please enter module code: " ) ;

finalMarkStr = JOptionPane.showInputDialog( "Please enter final mark: " ) ;

// the string values that are entered have to be converted into integer
level = Integer.parseInt(levelStr) ;
finalMark = Integer.parseInt(finalMarkStr) ;

// create new object
Module m1 = new Module() ;
}

}
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 12-14-2007, 09:25 AM
Member
 
Join Date: Aug 2007
Posts: 22
revathi17 is on a distinguished road
In your Module class, you have defined the constructor as
Code:
Module(String mc, int l, int fm) { moduleCode = mc; level = l; finalMark = fm; }
and in Module test you are calling Module(), which does not exist
you have to pass the parameters and call the constructor in the module class like this:
Code:
...... Module m1 = new Module(moduleCode, level, finalMark) ;

-R
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Calling constructor of parent class from a constructor Java Tip Java Tips 0 12-19-2007 11:10 AM
Calling constructor of same class from a constructor Java Tip Java Tips 0 12-19-2007 11:01 AM
reference to elements in array Igor New To Java 1 12-14-2007 01:56 PM
problems with array index mary New To Java 2 08-01-2007 06:30 PM
Help with array of elements zoe New To Java 1 07-24-2007 07:33 PM


All times are GMT +3. The time now is 04:12 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org