schedule program

class interaction

  • (2 Pages)
  • +
  • 1
  • 2

29 Replies - 3928 Views - Last Post: 11 November 2008 - 02:42 PM Rate Topic: -----

#1 gkglock   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 29-October 08

schedule program

Posted 29 October 2008 - 04:35 PM

Im working on a gui program that requires interaction between two classes. One class for students and the other for courses. The students will be placed in a list as well as the courses in another. Clicking on one of the students will show their courses; while clicking on the course will show the students in the course. Students and the courses are read in from separate text files. I know the basic idea I just dont know how to get started.

This is how I got it structured:
/*
 * 
 * 
 */
package s;
import java.io.*;
import java.util.Scanner;

/**
 *
 * @author 
 */
public class schedule
{
	public class Student 
	{
		 
	  
	}
	
	public class Course
	{
	   
		
	}
	/**
	 * @param args the command line arguments
	 */
	public static void main(String[] args)throws IOException
	{
		// TODO code application logic here
		
	}
}


I need a little help on how to get started with this. Im by no means asking for a handout; just a little advice on how to get started.

Is This A Good Question/Topic? 0
  • +

Replies To: schedule program

#2 g00se   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3550
  • View blog
  • Posts: 16,190
  • Joined: 20-September 08

Re: schedule program

Posted 29 October 2008 - 04:47 PM

If you were modelling this with a relational database, we would talk about a many-to-many relationship between Course and Student. You can model it in Java by setting up indexes using Maps, that would be owned by a containing entity such as School or College:

Map<Student, List<Course>>

Map<Course, List<Student>>

The first would be used to find or store which Course[s] each Student does and the second which Student[s] is/are on a particular Course.

Once you have these container classes set up, it becomes fairly simple to reflect this in your gui
Was This Post Helpful? 0
  • +
  • -

#3 pbl   User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8378
  • View blog
  • Posts: 31,956
  • Joined: 06-March 08

Re: schedule program

Posted 29 October 2008 - 05:01 PM

View Postg00se, on 29 Oct, 2008 - 04:47 PM, said:

If you were modelling this with a relational database, we would talk about a many-to-many relationship between Course and Student. You can model it in Java by setting up indexes using Maps, that would be owned by a containing entity such as School or College:

Map<Student, List<Course>>

Map<Course, List<Student>>

The first would be used to find or store which Course[s] each Student does and the second which Student[s] is/are on a particular Course.

Once you have these container classes set up, it becomes fairly simple to reflect this in your gui

Ouf !! G00se you smoked good stuff... I swear I've heard one of my university teacher
Was This Post Helpful? 0
  • +
  • -

#4 gkglock   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 29-October 08

Re: schedule program

Posted 29 October 2008 - 05:20 PM

well the way I think im trying to go about it is using arrays and objects. I just dont know how to start.
Was This Post Helpful? 0
  • +
  • -

#5 pbl   User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8378
  • View blog
  • Posts: 31,956
  • Joined: 06-March 08

Re: schedule program

Posted 29 October 2008 - 05:27 PM

View Postgkglock, on 29 Oct, 2008 - 04:35 PM, said:

Students and the courses are read in from separate text files.

And where do you get the info about which student is in which course ?

You are telling us you a flat file containing a list of students... fair
A list a courses... fair again
How do you cross relate them ? A GUI showing both lists into which you can click on a student an then click on the course to add it to sthe student curriculum ?
Was This Post Helpful? 0
  • +
  • -

#6 gkglock   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 29-October 08

Re: schedule program

Posted 29 October 2008 - 06:03 PM

the course name is in both files.

CS1337,Computer Science I,MW12:30-1:45
ENGL1211,Rhetoric,MW9:00-10:15
PHYS1211,Basic Physics I,MW10:30-11:45
CHEM1304,Intro to Chemistry I,TTH9:30-10:45
MATH1304,Calculus I,TTH11:00-12:15
MATH2306,Differential Equations I,TTH11:00-12:15
CS4340,Computer Architecture,MW12:30-1:45
CS2336,Computer Science II,MW4:00-5:15

12411,Wegner,Tim,CS1337,ENGL1121,PHYS1211,MATH1304,CHEM1304
12412,Kowalski,Brian,CS1337,ENGL1121,PHYS1211,CHEM1304
12417,Ploski,Karen,CS1337,MATH2306,PHYS1211,ENGL1211,CHEM1304
12423,Selemon,Carol,CS1337,MATH2306,PHYS1211,CHEM1304
12427,Simpson,David,CS4340,MATH2306,PHYS1211,ENGL1211,CHEM1304
12429,Winter,Alyssa,CS1337,ENGL1121,MATH2306,CHEM104,PHYS1211
12432,Millen,Bob,CS2336,ENGL1121,MATH2306,CHEM104,PHYS1211
12436,Holley,Nancy,CS2336,ENGL1121,MATH2306,CHEM104,PHYS1211
12438,Barber,Chris,CS1337,ENGL1121,MATH1304,CHEM104,PHYS1211
12440,Ruiz,Victor,CS2336,ENGL1121,MATH2306,CHEM104,PHYS1211
12441,Jain,Ashok,CS2336,ENGL1121,MATH2306,CHEM104,PHYS1211
12447,Walker,Alan,CS2336,ENGL1121,MATH2306,CHEM104,PHYS1211
12451,Noble,Rich,CS2336,MATH1304,PHYS1211,ENGL1211,CHEM1304
12453,Rich,Joseph,CS1337,MATH2306,PHYS1211,ENGL1211,CHEM1304
12455,Chen,Alan,CS2336,MATH2306,PHYS1211,ENGL1211,CHEM1304
Was This Post Helpful? 0
  • +
  • -

#7 pbl   User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8378
  • View blog
  • Posts: 31,956
  • Joined: 06-March 08

Re: schedule program

Posted 29 October 2008 - 06:26 PM

So read the couses first into an array
Then read the students, make a provision for a finite number of courses... scan the array of courses and keep the index in the course array for all student
Was This Post Helpful? 0
  • +
  • -

#8 gkglock   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 29-October 08

Re: schedule program

Posted 29 October 2008 - 09:34 PM

Is this a good start?
/*
 * 
 * 
 */
package 4;
import java.io.*;
import java.util.Scanner;

/**
 *
 * @author 
 */
public class 4
{
	public class Student 
	{
	   
	  
	}
	
	public class Course
	{
	   private String[] classes = new String[8];
	   public void setCourses() throws IOException
	   {
		   File courses = new File("CS1337Asg4Class.txt");
		   Scanner courseFile = new Scanner(courses);
		   while (courseFile.hasNext())
		   {
			   for(int Cindex=0; Cindex<classes.length; Cindex++)
			   {
				   classes[Cindex] = courseFile.nextLine();
				   
			   }
			   
		   }
		   courseFile.close();
	   }
		
	}
	
	
	/**
	 * @param args the command line arguments
	 */
	public static void main(String[] args)throws IOException
	{
		// TODO code application logic here
		
	}
}

This post has been edited by gkglock: 29 October 2008 - 09:35 PM

Was This Post Helpful? 0
  • +
  • -

#9 pbl   User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8378
  • View blog
  • Posts: 31,956
  • Joined: 06-March 08

Re: schedule program

Posted 29 October 2008 - 10:10 PM

Not really... do not want to estinguish your flame...
I cut & paste your courses list into a Course.txt file
There are println to show the progress

here is the code to read the courses

import java.io.File;
import java.io.IOException;
import java.util.Scanner;
import java.util.StringTokenizer;


public class MatchStudentAndCourses {

	Course[] course = new Course[100];
	int nbCourse = 0;

	MatchStudentAndCourses() {
		// we have to read the sourses
		try {
			Scanner rCourse = new Scanner(new File("Course.txt"));

			while(rCourse.hasNext()) {
				course[nbCourse++] = new Course(rCourse.nextLine());
			}
			nbCourse--;
			System.out.println(" Numer of courses registered: " + nbCourse);
		}
		catch(IOException e) {
			System.out.println("Ok we are in deep trouble");
		}

	}


	public static void main(String[] arg) {
		new MatchStudentAndCourses();
	}

	// contains what makes a course
	class Course {
		String code;
		String title;
		String time;
		// receives a line from the file and separate its elements
		Course(String line) {
			System.out.println("Constructor of Course receiving: " + line);
			StringTokenizer st = new StringTokenizer(line, ",");
			code = st.nextToken();
			title = st.nextToken();
			time = st.nextToken();
			System.out.println("Registered: " + code + " - " + title + " - " + time);
		}

	}
}


Was This Post Helpful? 0
  • +
  • -

#10 gkglock   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 29-October 08

Re: schedule program

Posted 30 October 2008 - 10:02 AM

Ok I think Im starting to realize how to put it together. So, do I create the students the same way as the course?
Was This Post Helpful? 0
  • +
  • -

#11 gkglock   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 29-October 08

Re: schedule program

Posted 30 October 2008 - 02:36 PM

Ok I need to know if I got the right idea on this. I read in the students the same way as the courses. Then I do the actual matching between course and student in the actionlistener for the list.
Was This Post Helpful? 0
  • +
  • -

#12 gkglock   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 29-October 08

Re: schedule program

Posted 31 October 2008 - 05:04 PM

This is what I got now, I am not sure how to begin the process of matching the student with the course and vice versa.
/*
 * 
 * 
 */
package schedule;
import java.io.*;
import java.util.Scanner;
import java.util.StringTokenizer; 

/**
 *
 * @author 
 */


	public class schedule 
	{
	   Course[] course = new Course[100];
	   int nbCourse = 0;
	   Student[] student = new Student[100];
	   int nbStudent = 0;
	   
	   schedule() throws IOException
	   {
		   Scanner courseFile = 
				   new Scanner(new File("C:\\CS1337Asg4Class.txt"));
		   
		   while (courseFile.hasNext())
		   {
			   course[nbCourse++] = new Course(courseFile.nextLine());
		   }
		   nbCourse--;
		   System.out.println(" Numer of courses registered: " + nbCourse);
		   
		   Scanner studentFile = 
				   new Scanner(new File("C:\\CS1337Asg4Student.txt"));
		   while (studentFile.hasNext())
		   {
			   student[nbStudent++] = new Student(studentFile.nextLine());
		   }
	   }
	  
	
	
	class Course
	{
	   String courseCode;
	   String title;
	   String time;
	   
	   Course(String line)
	   {
		   System.out.println("Constructor of Course receiving: " + line);  
		   StringTokenizer st = new StringTokenizer(line, ",");  
		   courseCode = st.nextToken();  
		   title = st.nextToken();  
		   time = st.nextToken();  
		   System.out.println("Registered: " + courseCode + " - " + title + " - " 
													+ time);  
	   }
		  
	}
	
	  class Student
	{
	   String id;
	   String lastName;
	   String firstName;
	   
	   Student(String line)
	   {
		   System.out.println("Constructor of Course receiving: " + line);  
		   StringTokenizer st = new StringTokenizer(line, ",");  
		   id = st.nextToken();  
		   lastName = st.nextToken();  
		   firstName = st.nextToken();  
		   System.out.println("Registered: " + id + " - " + lastName + " - " 
													+ firstName);  
	   }
		  
	}
	
	
	/**
	 * @param args the command line arguments
	 */
	public static void main(String[] args)throws IOException
	{
		// TODO code application logic here
		new schedule();
	}

   }

This post has been edited by gkglock: 31 October 2008 - 05:05 PM

Was This Post Helpful? 0
  • +
  • -

#13 pbl   User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8378
  • View blog
  • Posts: 31,956
  • Joined: 06-March 08

Re: schedule program

Posted 31 October 2008 - 08:04 PM

When you read a student line
pass throght all your courses
get the title of each one
use the indexOf(title) method of the String class to see if the title is included in the line
Was This Post Helpful? 0
  • +
  • -

#14 gkglock   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 29-October 08

Re: schedule program

Posted 01 November 2008 - 09:54 PM

I dont know how to make this work with the way its set up right now. Do I do the matching in the seperate Course class and Student Class?
Was This Post Helpful? 0
  • +
  • -

#15 gkglock   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 29-October 08

Re: schedule program

Posted 03 November 2008 - 07:39 PM

This is what im thinking to do. Read the student file again inside the course class. Then match the courseCode with the courseCodes for each student. Then vice versa in the Student class. Or am I missing the whole point.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2