Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Scheduling Problem

  1. #1
    Junior Member
    Join Date
    Feb 2011
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Scheduling Problem

    This program creates an array of assignments and sorts them in order from the earliest end first to the latest end time last. Also there is a Boolean array to keep track of which assignments can actually be used(true if actually on the schedule). Once they are sorted, I am supposed to create a schedule method that will take the assignments and turn each assignments' corresponding Boolean to true if it can be placed on the schedule. The first assignment on the list of 12 assignments is the current assignment and its corresponding Boolean must be set to true, then every assignment after the current assignment whose start time is before the end time of the current assignment must be skipped, then once you reach the first assignment whose start time is after the end time of the current assignment that assignment's corresponding Boolean must be set to true, then the same process again, etc... I have a for loop in the Schedule method, because I'm pretty sure that's what I need but I can't figure out how to set it up. Thanks.

    Here is the code:
    package homework4;
     
    import java.io.*;
     
    import java.util.Scanner;
     
    public class Scheduler {
    	Assignment[] assign = new Assignment[12];
    	boolean[] b = new boolean[12];
     
    	public void load(Scanner sc) {
    		int numberOfAssign = sc.nextInt();
     
    		for (int i = 0; i < assign.length; i++) {
    			assign[i] = new Assignment(sc.next(), sc.nextInt(), sc.nextInt());
    			// System.out.println(assign[i].getStartTime());
    		}
     
    	}
     
    	private void sort(Assignment[] array) {
    		int i, j;
    		int maxindex;
     
    		for (i = array.length - 1; i >= 1; i--) {
    			maxindex = 0;
    			for (j = 1; j <= i; j++) {
    				if (array[j].getEndTime() > array[maxindex].getEndTime()) { 
     
    					maxindex = j;
    				}
    			}
    			// swap minindex and i
    			Assignment temp = array[i];
    			array[i] = array[maxindex];
    			array[maxindex] = temp;
     
    		}
     
    	}
     
    	public void Schedule() {
    		sort(assign);
    		for (int i = 0; i < assign.length; i++) {
     
     
    		}
     
    	}


  2. #2
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: Scheduling Problem

    I don't know what's in your assignment class, but you don't need that load method.

    2nd, only a class with a main method will even be able to run the console. I don't see a main method.

    You should put a Scanner

    Scanner console = new Scanner(System.in):

    in your main method.

    You have the right idea with the for loop.

    But you should have each variable be read one at a time and then when you have enough to satisfy your constructor, then you create the new Assignment object. Right now it's going to be confused.

    And ask for this in the main method.

    Also, ti appears that you'll be missing index 0 of your array with your sort method.

    Edit---Oh, you're assign variable is ok after all.

    But your for loop is doing nothing in that Schedule method.

    Instead of having boolean array, which not have a boolean variable as part of your Assignment class? It would make things easier.

    You never called Load method anywhere. So as far as the compiler knows, your array is empty.

    You'll be sorting an empty array.
    Last edited by javapenguin; February 19th, 2011 at 09:31 PM. Reason: assign array is fine.

  3. #3
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,676
    Thanks
    25
    Thanked 329 Times in 305 Posts

    Default Re: Scheduling Problem

    Quote Originally Posted by javapenguin View Post
    I don't know what's in your assignment class, but you don't need that load method.

    Also, as it's not in a constructor, your method that calls sort won't know what that array is and will say

    cannot find symbol: assign
    What is wrong with that? Assign is a variable whose scope is within the view of the load method.

    2nd, only a class with a main method will even be able to run the console. I don't see a main method.
    The OP could have a main in another class for all we know. There may be a main that just has not been posted.

    You should put a Scanner

    Scanner console = new Scanner(System.in):

    in your main method.
    Entirely stylistic, and it would appear that the Scanner is in the main since it is being sent to the load method. It is debatable how to go about this, but what is currently being done is not wrong.

    You have the right idea with the for loop.

    But you should have each variable be read one at a time and then when you have enough to satisfy your constructor, then you create the new Assignment object. Right now it's going to be confused.
    There shouldnt be any real confusion by the JVM. It will read in each value one at a time like it would if it was spread out to multiple lines like you suggest.

    And ask for this in the main method.

    Also, ti appears that you'll be missing index 0 of your array with your sort method.
    It would appear that the array index 0 is taken care of at the first iteration of the loop that uses i as a variable. Either way, I am unclear if the intent of the OP is to miss the index 0, so this could be a real concern.


    javapenguin, word of advice, when providing advice be wary if what you are suggesting is fixing the problem or just stylistic changes that will more than likely not fix the problem at hand.
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

  4. The Following User Says Thank You to aussiemcgr For This Useful Post:

    copeg (February 19th, 2011)

Similar Threads

  1. askfor some idea on examination scheduling using Harmony algorithm
    By starmove in forum Algorithms & Recursion
    Replies: 0
    Last Post: January 10th, 2011, 12:25 AM
  2. Help in Scheduling please????
    By touches in forum Algorithms & Recursion
    Replies: 2
    Last Post: October 20th, 2010, 07:41 AM
  3. non preemptive scheduling.....challenging!!
    By snehil2009 in forum Java Theory & Questions
    Replies: 0
    Last Post: November 8th, 2009, 03:07 AM
  4. Replies: 1
    Last Post: March 18th, 2009, 06:21 AM