stefan balling

Greenhorn
+ Follow
since Nov 28, 2012
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by stefan balling

I've actually made a few changes to improve the code. I actually code the enqueue and dequeue the wrong way round. The rear was the last element in the queue therefore if would be the first to be removed. The problem now is every time I add a new element in, I get the element plus the next element added as null. I.e I add cat and I get (cat, null) displayed.. Anyone could help with that?

11 years ago
I'm not, the class variables were declared before we started. We only implemented the methods. I had a feeling that was the issue but the test program was throwing up data larger than 10 so do you think there could be an error in the testing data sizes?

Thanks
11 years ago
Hi

I'm currently working on a uni exercise which I have finished but I keep getting an error when I compile an array greater than 10. I am creating an ArrayQueue. It should act as a stack basically and I was asked to implement these methods and test on data samples he gave me. Apologizes if I upload this wrong. My code is:




My error when I run an array of size 10 or above is an ArrayOutOfBounds exception. I know why that exception is cropping up in theory but I don't see where my code is causing this.

Thanks for any help.

Stefan
11 years ago

Jayesh A Lalwani wrote:I would suggest that you break down the problem into 3 parts a) Reading the student.txt file and loading it into a data structure in memory b) Reading the course. txt file and loading in into a data structure in memory c) merging the 2 inputs to get the output that you need. These are your 3 high level modules.

Next start thinking about what those input and output data structures will look like and how you would merge them. This will guide you towards defining the interface between the modules

Once you have the interfaces designed, work on one module at a time, test them independently, then hook them up and test them all together

As a general guideline, programming is an exercise in breaking down problems into manageable pieces. Don't try to solve the entire problem at once. At any time, a problem starts to overwhelm you, start thinking about how you can break it down into independent manageable pieces. Any problem is solvable as long as you break it down.




Thank you for this, it's very helpful!
12 years ago

Winston Gutkowski wrote:

stefan balling wrote:So, my idea was to run through the course file first and take the course name off and pass the remain info into the timeslot class and play around with it there. Then run through the student file and take the student ID into the student class and pass the rest again into timeslot. The problem is I dont know how to seperate the two files when I pass them into the timeslot. I wanted to add a boolean value to determine which one is being passed in but I was told I can't do that. Can anyone give me some guidance? I don't want answers just a step in the right direction!


OK, well firstly, I'd follow Campbell's advice and play around before you start ANY coding. And don't forget to write out your findings in English.

Secondly, I'd split the problem into two major phases:
1. Load the data.
2. Validate it.
In the first phase, don't worry about whether things are correct or not, simply convert all those 'orrible Strings into proper Java objects.

Third, I'd probably add a Day class (or, probably even better, an enum) to the ones you've already got.

Basically, Strings make bad substitutes for other types, so you want to convert as many of them as you can as fast as you can.

However, I do have a question:
The course file contains a LabGroup AND a TimeSlot, but no indication as to whether the two are related or not.
For example: is LabGroup 'H' always associated with the TimeSlot 'Mon 13:00 15:00' - with or without the 'Mon' - or is it simply the designation for a lab room which could be used with any (presumably non-overlapping) TimeSlot?

My suspicion is the latter, but it's something that would be worth finding out before you get too far down the road.

Winston




Hi Winston,

Thank you for your response. I haven’t coded yet as I’m not sure how to solve the problem. I cannot add another class unfortunately, I have to use what I’m given. I’ll need to read up on enums as I’m not too sure about them. The problem I can see is each class has to have a constructor using a scanner. Now I’m not sure how to implement that through each class. For example if I go through the file and take the student ID then I want the timeslot class to read in the info after the ID if that makes sense?

I’m also not sure if when I load the remaining data into the timeslot class from both files, they have a different format so I’m not sure how can I load each file through the timeslot class. Does that make sense?

Also to your question, you are right it is the latter, different course may vary to the example given.

Thank you again.
12 years ago

Jelle Klap wrote:Hi, and welcome to the Ranch!
I've take the liberty to add quote-tags to the section of your post to make it clear that this is the actual worksheet text.

stefan balling wrote:The problem is I dont know how to seperate the two files when I pass them into the timeslot. I wanted to add a boolean value to determine which one is being passed in but I was told I can't do that.


I don't quite follow what you mean by this, could you elaborate?
Maybe you could describe to us in pseudocode the steps you think the program should take?





Thanks for the quick reply guys!

Sorry I find it difficult to convey my thoughts on to paper (or computer).

Basically:

1) Read file course.txt into the course class.
2) Take the first part (course name) and store it into course, pass the remaining line down to the lab group class.
3) In the lab group class take the first part again (Lab name A-H) and store that and pass the rest of the line down to timeslot.
4) In timeslot run through the remaining file and store the day, start time and finish time accordingly.
5) Somehow pass the timeslot class back up for the checkstudent class to use?

1) Read the student.txt into the student class.
2) Take the first part of the line (student ID) and store it in the student class, pass the remaining line down to the timeslot class.
3) Repeat 4 in other part.
4) Again somehow pass this back up to the checkstudent class.
5) Check the eligibility and print?

Again I’m not particularly good at this but this is how I thought I could solve this problem.


Thanks.
12 years ago
Hi all!

First time poster so I apologise if I make any nooby mistakes in advance!

I'm currently studying CS and i'm in my second year at Glasgow uni learning Java. Now I'll admit i'm really struggling with it this year.

I have some course work which I'm working through and I have an idea how to code it but I'm struggling with how.

The program is to check the eligibility of students available for lab times. Two text files (course.txt which contains course name then subsequent lines are the lab group and times) and (students.txt which contains lines starting with the student ID then all the times they are committed to).

The code should print out if the student is eligible or not and if so give him an appropriate lab. Need these classes, Course, Student, Time, TimeSlot and check student. Check student is written and does the eligibility check for us and Time is also written for us and contains methods to make using time easier.

So, my idea was to run through the course file first and take the course name off and pass the remain info into the timeslot class and play around with it there. Then run through the student file and take the student ID into the student class and pass the rest again into timeslot. The problem is I dont know how to seperate the two files when I pass them into the timeslot. I wanted to add a boolean value to determine which one is being passed in but I was told I can't do that. Can anyone give me some guidance? I don't want answers just a step in the right direction!

I feel I didn't explain this well so im sorry if this is really long.

The below is the course work sheet.

Thanks everyone for any help!

Course worksheet wrote:
The purpose of the program is to determine students’ eligibility and availability for lab groups for a given course. The program is to read data from two input files, one containing details of a course and the other details of students.

The Course file

The first line of the file course.txt contains the course name, which may contain embedded spaces, for example

Java Programming 2

Each subsequent line of the file contains information on a laboratory group associated with the course. A typical line has the form

H Mon 13:00 15:00

where the first item is the lab group label (a single character), and the other three items give the time slot for that lab group.

The student file

Each line of the file students.txt contains a student number followed by a sequence of time slots, representing the existing commitments of the student, for example

0903612 Mon 12:00 14:00 Tue 14:00 16:00 Wed 09:00 11:00 Wed 14:00 16:00 Thur 12:00 13:00 Fri 10:00 12:00

(Note that this represents a single line of the file.)

The program

The program is to read the data from the two files and write to standard output the name of the course, followed by one line for each student. This line should contain the student number, an indication of whether the student is eligible for the course, and if so a list of the lab groups for which s/he is available. A student is eligible for the course if at least one of the lab group time slots does not overlap any of his/her commitments, and is available for each of the lab groups with a scheduled time slot that does not overlap any of those commitments1. So the first three lines of output might be:

Java Programming 2
0903612 ineligible
0951411 eligible A C F

You are given a complete class CheckStudents containing a main program that is designed to solve this problem. However, a number of other classes are required to complete the solution.

Task 1. You are given a complete class Time to represent a time in hours and minutes, and a skeleton class TimeSlot to represent a time slot consisting of a day, a start time and a finish time. You are to complete the implementation of this TimeSlot class.

In the TimeSlot class, you should provide a full set of constructors, accessors and mutators, together with equals and toString methods, and any other methods that may be appropriate for the context. In the other classes, you need give only methods that are actually used in your program.

Task 2. You are given a skeleton of a class LabGroup to represent a lab group. You are to complete the implementation of this class.

Task 3. You are given a skeleton of a class Course to represent a course, which involves an unknown number of lab groups. You are to complete the implementation of this class. It is suggested that the class should use an ArrayList to hold the lab groups for the course.

Task 4. You are given a skeleton of a class Student to represent a student, to include information on the student’s commitments and other attributes relevant to the context. You are to complete the implementation of this class.

Notes
1. The program assumes that the input files are in exactly the right format.

2. Each class is to include a constructor that creates an object by reading from a scanner, tailored for the context. This will be the only constructor that is needed in the LabGroup, Course and Student classes. The given Time class has such a constructor2.

3. You should not make any changes to the classes Time or CheckStudents.

4. Some of the methods required in the classes that you have to implement are immediately apparent from inspection of the main program. Others you will have to discover for yourself.

5. You may assume that the days are represented as Mon, Tue, Wed, Thur and Fri (no labs take place at the weekend!)


12 years ago