Results 1 to 3 of 3

Thread: classes

  1. #1
    exose is offline Member
    Join Date
    Sep 2010
    Posts
    19
    Rep Power
    0

    Default classes

    Hi,

    I have three clases:

    1. Module class
    Java Code:
    public class Module
    {
      private String moduleName;
      private int semesterNo;
      private int enrolmentNo;
    
        // default constructor - initializes default attr values
    	public Module()
       	{
       	}
    
        public Module(String newModuleName, int newSemesterNo, int newEnrolmentNo)
        {
          this.moduleName = newModuleName;
          this.semesterNo = newSemesterNo;
          this.enrolmentNo = newEnrolmentNo;
        }
    
    //Setters
    	public void setModuleName (String newModuleName)
    	{
    		moduleName = newModuleName;
    	}
    
    	public void setSemesterNo (int newSemesterNo)
    	{
    		semesterNo = newSemesterNo;
    	}
    
    	public void setEnrolmentNo (int newEnrolmentNo)
    	{
    		enrolmentNo = newEnrolmentNo;
    	}
    
    //Getters
        public String getModuleName()
        {
          return moduleName;
        }
    
        public int getSemesterNo()
        {
          return semesterNo;
        }
    
        public int getEnrolmentNo()
        {
          return enrolmentNo;
        }
    
    }
    2. Menu Class
    Java Code:
    import java.io.*;
    import java.util.*;
    
    public class Menu
    {
    	// Scanner for user input
       private Scanner scan;
    
       //String to display the layout of the menu to the user
       private String menuString = "*****Main Menu*****\n\n" +
       							   "Select (1) to Add Student\n" +
       							   "Select (2) to Delete Student\n" +
       							   "Select (3) to Add Module\n" +
       							   "Select (4) to Delete Module\n" +
       							   "Select (5) to Assign Student to Module\n" +
       							   "Select (6) to Display Student Details\n" +
       							   "Select (7) to Display Module Details\n" +
       							   "Select (8) to Exit Program\n";
    
    
    	public Menu()
       	{
       		//Call the scanner class
        	scan = new Scanner(System.in);
       	}
    
       	public int mainMenu()
       	{
       		int choice;
    
       		System.out.println(menuString);
    
       		System.out.println("Please select an option: ");
    
       		//Read the input from the user
       		choice = scan.nextInt();
    
       		//Return the user's choice
       		return choice;
       	}
    }
    3. Student Class
    Java Code:
    public class Student
    {
      public String firstName;
      private String lastName;
      private String enrollmentDate; // better would be to use util.Date not String ??
    
      // default constructor - initializes default attr values
    	public Student()
       	{
       	}
    
        public Student(String newFirstName, String newLastName, String newEnrollmentDate)
        {
          this.firstName = newFirstName;
          this.lastName = newLastName;
          this.enrollmentDate = newEnrollmentDate;
        }
    
    //setters
    	public void setFirstName (String newFirstName)
    	{
    		firstName = newFirstName;
    	}
    
    	public void setLastName (String newLastName)
    	{
    		lastName = newLastName;
    	}
    
    	public void setEnrollmentDate (String newEnrollmentDate)
    	{
    		enrollmentDate = newEnrollmentDate;
    	}
    
    //getters
        public String getFirstName()
        {
          return firstName;
        }
    
        public String getLastName()
        {
          return lastName;
        }
    
        public String getEnrollmentDate()
        {
          return enrollmentDate;
        }
    }
    Now, I am trying to create new class where all those three classes would be connected and they would be working as a one program.

    I have red few ways to do this for exmaple on:

    What Is Inheritance? (The Java™ Tutorials > Learning the Java Language > Object-Oriented Programming Concepts)

    and also on this forum.

    but this is still a little bit not clear for me.

    Would you be able to give me an example how I can start the last class for this assignemt? What I am trying to achieve is the database where I would be able to store, edit, delete, add modules etc.

    Anyway, should I store all this information in the file or in the buffer? I am guessing storing Student, Module information should not be that complicated?

    thanks in advance
    Exose
    Last edited by exose; 09-30-2010 at 03:29 PM.

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

    Default

    hello, inside the Module class your could instantiate a collection of type Student and each time a student is assigned to a module the student is added to the Student collection inside the Module class.

    for storing your datas you have to decide if you want to use the serialization of java or a database. if you use a database the relation between Student and Module is stored in a 1:n table reflecting Module:Student relations, so there's no need for composition in java.

  3. #3
    exose is offline Member
    Join Date
    Sep 2010
    Posts
    19
    Rep Power
    0

    Default

    can I use a database with "basic java application"? I guess, serialization would be easier? :)

    inside the Module class your could instantiate a collection of type Student and each time a student is assigned to a module the student is added to the Student collection inside the Module class.
    So... I should define that if I asign a module to the student (modules_assigned_to_each_student < 4) this should be added to the collection of the module? I think, it should be student collection not module or it doesnt matter?

Similar Threads

  1. A little help with classes.
    By ThrashingBoy in forum New To Java
    Replies: 8
    Last Post: 06-10-2010, 09:52 AM
  2. Three classes help!!
    By arrech326 in forum New To Java
    Replies: 4
    Last Post: 11-24-2009, 06:34 AM
  3. Get name of available classes
    By escuja in forum CLDC and MIDP
    Replies: 0
    Last Post: 07-26-2008, 12:03 PM
  4. Help with classes
    By freswood in forum New To Java
    Replies: 5
    Last Post: 04-21-2008, 03:28 PM
  5. Using a JAR from other classes
    By Joe2003 in forum Advanced Java
    Replies: 1
    Last Post: 01-02-2008, 07:08 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
  •