I'm creating a tv schedule for a hotel and need to be able to fill the schedule with particular programs that take up various amounts of time each slot is 30 mins so a film with a 1hr 30 min run time would take up 3 slots but i'm not sure how to go about doing this. i've created a boolean array that would have the slots and if a show takes up 3 slots it will set the values of the boolean array to true and then the user would no longer be able to use those slots. I'm a bit confused as how to go about this though.

import java.util.*; 


public class Schedule {

private int maxduration = 18*2;

private ArrayList<Programme>schedule; 
private boolean [] times; 

	
    public Schedule() {
    schedule = new ArrayList<Programme>();
    times= new boolean[maxduration];	
    }
    
    public boolean[] getTimes() {
		return times;
	}

	public void setTimes(boolean[] times) {
		this.times = times;
	}

	public void addProgramme(int statTime, Programme p)
    {
    	schedule.add(p);
    } 
    
    public void printSchedule()
    {
    	System.out.println(schedule);
    }
    
    
    public void removeProgramme(String title){
    	Programme prog = null;
    	for(Programme p: schedule){
    		if(p.getTitle().equals(title)){
    		    prog = p;
    		    break; 	
    		}
    	}
    	
    	schedule.remove(prog);
    	
    }
    	   
    
}

the boolean array would take up time slots in my schedule eg slot[0] would refer to 06:00 am and slot [1] would be 06:30 am

am i just missing a simple if statement or something?

any help appreciated

Cheers

public class Main {
	
	public static void main(String [] args){
		
	
		
	Schedule s = new Schedule();
	
	//(String director, String actors, String synopsis, String title, boolean rentable, int duration, boolean trailer, String rating)
	s.addProgramme(0,new Film("Spielberg","George","blah","Star", false, 120, true, "18"));
	s.addProgramme(3,new Film("Spielberg","George","blah","Star Wars", false, 120, true, "18"));
	s.addProgramme(6,new Film("Spielberg","George","blah","phantom", false, 120, true, "18"));
	s.addProgramme(7,new Film("Spielberg","George","blah","Star Wars", false, 120, true, "18"));
	s.addProgramme(5,new Film("Spielberg","George","blah","Star Wars", false, 120, true, "18"));
	s.addProgramme(12,new Film("Spielberg","George","blah","Star Wars", false, 120, true, "18"));
	s.printSchedule();
	
	s.removeProgramme("phantom");
	s.printSchedule();
	
		
	
}


}

May I ask where is the Programme class

public class Programme {
	
	private String title;
	private boolean rentable;
	private int duration;
	private int startTime;
	private boolean trailer;
	
public Programme(String title, boolean rentable, int duration, boolean trailer){
		
		this.title   	  = title;
		this.rentable     = rentable;
		this.duration     = duration;
		//this.startTime    = startTime;
		this.trailer      = trailer;
		
	}

public Programme(){	
}
	
	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	public boolean isRentable() {
		return rentable;
	}
	public void setRentable(boolean rentable) {
		this.rentable = rentable;
	}
	public int getDuration() {
		return duration;
	}
	public void setDuration(int duration) {
		this.duration = duration;
	}
	public int getStartTime() {
		return startTime;
	}
	public void setStartTime(int startTime) {
		this.startTime = startTime;
	}
	public boolean isTrailer() {
		return trailer;
	}
	public void setTrailer(boolean trailer) {
		this.trailer = trailer;
	}
	public boolean equals(Object o){
		
		if(o instanceof Programme){
			Programme p=(Programme)o;
			if(p.getTitle().equals(title)){
				return true;
			} 
		}
		return false;
	}
	
	public String toString()
	{
		return "Title: "+getTitle()+ " is Rentable " + isRentable()+ " the duration " + getDuration()+" Start time " +getStartTime()+ " Trailer is " +isTrailer();
		
	}

}

what isn't working on it? do you get an error message? what do you want it to do and what does it do?

What i need to do is make it so that you can only add a programme to the schedule if there is an availble timeslot for example i would add a programme to the 07:00 am slot of the schedule and it would subsequently take up 3 slots because the programmes duration is 90 mins and each slot holds only 30 mins.

i'm just not sure how to do the timeslots for the programme.

at the moment i can populate the list with programmes and remove programmes but i don't have a way to make a particular programme take up a number of slots to represent the time in the day?

well, you'll need to go and look into the boolean array (index that you provide) whether or not it is true or false.

I assume true 'll mean it is already taken, and false means it's available.
if it is taken, don't add anything to the arrayList, if it is not, set it to true, and add your value to the arraylist.

when you remove, don't forget to put the appropriate boolean value to false.

Um thats what I said in my original post. I'm just a bit confused as to how I would implement it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.