Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Song
- {
- private String name;
- private String author;
- private String preformer;
- private int length;
- public Song(String name, String author, String preformer,int length)
- {
- this.name = name;
- this.author = author;
- this.preformer = preformer;
- this.length = length;
- }
- public Song(Song s)
- {
- this.name = s.name;
- this.author = s.author;
- this.preformer = s.preformer;
- this.length = s.length;
- }
- public String getName()
- {
- return this.name;
- }
- public String getAuthor()
- {
- return this.author;
- }
- public String getPreformer()
- {
- return this.preformer;
- }
- public int getLength()
- {
- return this.length;
- }
- public void setName(String name)
- {
- this.name = name;
- }
- public void setAuthor(String author)
- {
- this.author = author;
- }
- public void setPreformer(String preformer)
- {
- this.preformer = preformer;
- }
- public void setLength(int length)
- {
- this.length = length;
- }
- public String toString()
- {
- return this.name + "," + this.author + "," + this.preformer + "," + this.length;
- }
- }//End of class song
- public class RadioProgram
- {
- private int hour;
- private Song [] songArr;
- private int numSong;
- public final int arraySize = 30;
- public RadioProgram()
- {
- this.hour = 0;
- this.songArr = new Song[arraySize];
- this.numSong = 0;
- }
- public boolean addSong(Song s)
- {
- if(numSong <30)
- {
- songArr[numSong] = new Song(s);
- return true;
- }
- return false;
- }
- public void removeSong(Song s)
- {
- for(int i = 0; i < numSong; i++)
- if(songArr[i].getName() == s.getName())
- {
- songArr[i] = new Song(songArr[numSong]);
- songArr[numSong] = null;
- break;
- }
- numSong--;
- }
- public int getHour()
- {
- return this.hour;
- }
- public int getNumSong()
- {
- return this.numSong;
- }
- public Song[] getSongArr()
- {
- Song [] a = new Song[arraySize];
- for(int i = 0; i < this.numSong; i++)
- a[i] = new Song(this.songArr[i]);
- return a;
- }
- public void setHour(int hour)
- {
- this.hour = hour;
- }
- public void setNumSong(int numSong)
- {
- this.numSong = numSong;
- }
- }//End of class RadioProgram
- import java.util.*;
- public class TestRadio
- {
- static Scanner reader = new Scanner(System.in);
- public static int castTime(RadioProgram rp)
- {
- int sum = 0 ;
- for(int i = 0; i < rp.getNumSong(); i++)
- sum += rp.getSongArr()[i].getLength();
- return sum;
- }
- public static RadioProgram buildSongArray(int hour)
- {
- int sum = 0;
- RadioProgram rp = new RadioProgram();
- rp.setHour(hour);
- while(sum < 3600)
- {
- Song s = new Song(reader.next(),reader.next(),reader.next(),reader.nextInt());//Gets a song to input the array.
- rp.addSong(s);
- sum += s.getLength();
- }
- int temp = rp.getNumSong();
- Song [] a = rp.getSongArr();
- rp.removeSong(a[temp]);
- return rp;
- }
- public static void main(String[]args)
- {
- RadioProgram [] dayArray = new RadioProgram[24];
- for(int i = 0; i < dayArray.length; i++)
- dayArray[i] = buildSongArray(i);
- for(int i = 0; i <dayArray.length; i++)
- System.out.println(castTime(dayArray[i]));
- }//End of main method
- }//End of class TestRadio
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement