Results 1 to 3 of 3
Thread: classes
- 09-30-2010, 03:25 PM #1
Member
- Join Date
- Sep 2010
- Posts
- 19
- Rep Power
- 0
classes
Hi,
I have three clases:
1. Module class
2. Menu ClassJava 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; } }
3. Student ClassJava 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; } }
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.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; } }
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
ExoseLast edited by exose; 09-30-2010 at 03:29 PM.
- 09-30-2010, 03:52 PM #2
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.
- 09-30-2010, 04:21 PM #3
Member
- Join Date
- Sep 2010
- Posts
- 19
- Rep Power
- 0
can I use a database with "basic java application"? I guess, serialization would be easier? :)
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?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.
Similar Threads
-
A little help with classes.
By ThrashingBoy in forum New To JavaReplies: 8Last Post: 06-10-2010, 09:52 AM -
Three classes help!!
By arrech326 in forum New To JavaReplies: 4Last Post: 11-24-2009, 06:34 AM -
Get name of available classes
By escuja in forum CLDC and MIDPReplies: 0Last Post: 07-26-2008, 12:03 PM -
Help with classes
By freswood in forum New To JavaReplies: 5Last Post: 04-21-2008, 03:28 PM -
Using a JAR from other classes
By Joe2003 in forum Advanced JavaReplies: 1Last Post: 01-02-2008, 07:08 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks