Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Congratulations, you have just become Java TV\'s newest owner! Java TV is the gr

ID: 3633853 • Letter: C

Question

Congratulations, you have just become Java TV's newest owner! Java TV is the greatest TV channel ever, and it prides itself in its 24 hour interesting ' programming' . To help you run this channel you will need to write a dynamic program that uses Data Lists to store all its TV show information.

Your program will contain the following Menu Options:

1. Enter TV Shows/ Add a TV Show:

This option should allow the user to enter as many shows as he wants, your program should always keep track of how many shows the user has entered.

2. Modify TV Show:

This option should ask the user what show he would like to modify and search for it using the name of the show as the search key. The user should be able to modify that show information

3.Delete TV Show:

Like the Modify option, the delete option searches for a show using the show's name. Once found the show should be removed by shifting the array one space.
(Example: to delete array position 4, 5->4, 6->5,7->6...and so on)

4.Sort TV Shows:

The sort function asks the user what sort key he would like to use (name, day, time) and sorts the list using that key.
Note: The sort by day will sort alphabetically, that is fine,
see the Bonus for a proper day sort

5.Show all TV Shows:

This option outputs all the shows and also gives totals for the number of shows per day.

6.Exit: This will quit the program

***IMPORTANT: I ONLY use java 1.4.2. I cannot use newer versions, therefore classes such as scanner dont work. please make sure it works with 1.4.2. Thank you. Lifesaver Ratings

Explanation / Answer

Save the file as TVShow.java. Compile and Test it. Let me know, in case of any errors or issues. I can fix it.

//TVShow.java
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class TVShow
{
    static ArrayList ListTvShows = new ArrayList();
    public static void main(String[] args)
    {
        InputStreamReader inp = null;
        BufferedReader input = null;
        int nOption = 0;
        try
        {
            inp = new InputStreamReader(System.in);
            input = new BufferedReader(inp);
            while(true)
            {
                System.out.println("1. Enter TV Shows/ Add a TV Show.");
                System.out.println("2. Modify TV Show.");
                System.out.println("3. Delete TV Show.");
                System.out.println("4. Sort TV Shows.");
                System.out.println("5. Show all TV Shows.");
                System.out.println("6. Exit.");
                System.out.println(" Choose an option(1-6) >> ");
                nOption = Integer.parseInt(input.readLine());
               
                switch(nOption)
                {
                    case 1:
                        AddTVShow(input);
                        break;
                    case 2:
                        ModifyTVShow(input);
                        break;
                    case 3:
                        DeleteTVShow(input);
                        break;
                    case 4:
                        SortTVShow(input);
                        break;
                    case 5:
                        ShowAllTVShows();
                        break;
                    case 6:
                        System.out.println("Exiting program. Press any key to continue....");
                        input.read();
                        System.exit(0);
                        break;
                }
            }
        }
        catch(Exception exp)
        {
        }
    }
   
    private static void AddTVShow(BufferedReader input) throws IOException
    {
        TVShowTemplate tmpObject = null;
        while(true)
        {
            tmpObject = new TVShowTemplate();
            System.out.println("Name of the TV Show >> ");
            tmpObject.ShowName = input.readLine().toString();
            System.out.println("Day of the TV Show "+tmpObject.ShowName+"(Mon...Sun) >> ");
            tmpObject.Day = input.readLine().toString();
            System.out.println("Time of the TV Show "+tmpObject.ShowName+" (in HH:MM AM/PM format) >> ");
            tmpObject.Time = input.readLine().toString();
            if(tmpObject != null)
                ListTvShows.add(tmpObject);
           
            System.out.println(" Do you want to add another TV Show?(y/n) >>");           
            if(!input.readLine().toLowerCase().equals("y"))
                break;
        }
    }

    private static void ModifyTVShow(BufferedReader input) throws IOException
    {
         TVShowTemplate tmpObject = null;
         System.out.println("Name of the TV Show to modify >> ");
         String OldTVShowName = input.readLine();
         int index = getTVShowIndexByName(OldTVShowName);
         if(index == -1)
         {
             System.out.println(" TV Show " + OldTVShowName+ " not found.");
         }
         else
         {
             tmpObject = (TVShowTemplate)ListTvShows.get(index);
             showTVShow(tmpObject);
             System.out.println("What you want to modify (Name|Day|Time)? >>");
             String strOption = input.readLine();
             if("name".equals(strOption.toLowerCase()))
             {
                System.out.println("New Name of the TV Show >> ");
                tmpObject.ShowName = input.readLine().toString();
             }
             else if("day".equals(strOption.toLowerCase()))
             {
                System.out.println("New Day of the TV Show "+tmpObject.ShowName+"(Mon...Sun) >> ");
                tmpObject.Day = input.readLine().toString();
             }
             else if("time".equals(strOption.toLowerCase()))
             {
                System.out.println("New Time of the TV Show "+tmpObject.ShowName+" (in HH:MM AM/PM format) >> ");
                tmpObject.Time = input.readLine().toString();
             }
             else
             {
                 System.out.println("Unable to locate the propety entered..");
             }
             ListTvShows.set(index, tmpObject);
         }
    }
   
    private static int getTVShowIndexByName(String Name)
    {
        int index = -1;
        TVShowTemplate tmp =null;
        for(int i=0;i<ListTvShows.size();i++)
        {
            tmp = (TVShowTemplate)ListTvShows.get(i);
            if(tmp.ShowName.toLowerCase().equals(Name.toLowerCase()))
            {   
                index = i;
                break;
            }
        }
        return index;
    }
   
    private static void showTVShow(TVShowTemplate tshow)
    {
        System.out.println(tshow.ShowName+" "+tshow.Day+" "+tshow.Time);
    }
   
    private static void DeleteTVShow(BufferedReader input) throws IOException
    {
         System.out.println("Name of the TV Show to delete >> ");
         String OldTVShowName = input.readLine();
         int index = getTVShowIndexByName(OldTVShowName);
         if(index == -1)
         {
             System.out.println(" TV Show " + OldTVShowName+ " not found.");
         }
         else
         {
             ListTvShows.remove(index);
             System.out.println(" TV Show " + OldTVShowName+ "deleted successfully.");
         }
    }

    private static void SortTVShow(BufferedReader input) throws IOException
    {
         System.out.println("Enter the key to sort (Name|Day|Time)? >>");
         String strOption = input.readLine();
         int nSize = ListTvShows.size();
         String str1, str2;
         if("name".equals(strOption.toLowerCase()))
         {
             for(int i = 0;i<nSize;i++)
             {
                 for(int j = (i+1);j<nSize;j++)
                 {
                     str1 = ((TVShowTemplate)ListTvShows.get(i)).ShowName;
                     str2 = ((TVShowTemplate)ListTvShows.get(j)).ShowName;
                    
                     if(str1.compareToIgnoreCase(str2) > 0)
                     {
                         TVShowTemplate tmp = (TVShowTemplate) ListTvShows.get(i);
                         ListTvShows.set(i, (TVShowTemplate) ListTvShows.get(j));
                         ListTvShows.set(j, tmp);
                     }
                 }
             }
         }
         else if("day".equals(strOption.toLowerCase()))
         {
             for(int i = 0;i<nSize;i++)
             {
                 for(int j = (i+1);j<nSize;j++)
                 {
                     str1 = ((TVShowTemplate)ListTvShows.get(i)).Day;
                     str2 = ((TVShowTemplate)ListTvShows.get(j)).Day;
                    
                     if(str1.compareToIgnoreCase(str2) > 0)
                     {  
                         TVShowTemplate tmp = (TVShowTemplate) ListTvShows.get(i);
                         ListTvShows.set(i, (TVShowTemplate) ListTvShows.get(j));
                         ListTvShows.set(j, tmp);
                     }
                 }
             }
         }
         else if("time".equals(strOption.toLowerCase()))
         {
             for(int i = 0;i<nSize;i++)
             {
                 for(int j = (i+1);j<nSize;j++)
                 {
                     str1 = ((TVShowTemplate)ListTvShows.get(i)).Time;
                     str2 = ((TVShowTemplate)ListTvShows.get(j)).Time;
                    
                     if(str1.compareToIgnoreCase(str2) > 0)
                     {
                         TVShowTemplate tmp = (TVShowTemplate) ListTvShows.get(i);
                         ListTvShows.set(i, (TVShowTemplate) ListTvShows.get(j));
                         ListTvShows.set(j, tmp);
                     }
                 }
             }
         }
         else
         {
             System.out.println("Unable to locate the propety entered..");
         }
         ShowAllTVShows();
    }

    private static void ShowAllTVShows()
    {
         System.out.println("****** TV Show management Program ******** ");
         System.out.println("Name Day Time");
         for(int i=0;i<ListTvShows.size();i++)
         {
            
             showTVShow((TVShowTemplate)ListTvShows.get(i));
         }
    }
}
class TVShowTemplate
{
    public String ShowName = "";
    public String Day = "";
    public String Time="";
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote