Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think the sorting is not working because there are no elements present in the <code>ShowInfo[]</code> array to sort. </p> <p>You are initializing the <code>ShowInfo</code> array inside the <code>addShow</code> method:</p> <pre><code>//initialize counter int i = 0; arr = new showInfo[i]; </code></pre> <p>And you are creating a new <code>ShowInfo</code>:</p> <pre><code>ShowInfo temp = new showInfo(); </code></pre> <p>but this <code>temp</code> was never assigned to any array element. So, every time you are calling this method to add a new <code>show</code>, you are actually creating a new <code>ShowInfo[]</code> array of length 0 and an instance of <code>ShowInfo</code> which was never assigned to any array element.</p> <p>You need to initialize the array/counter only once, so separate the array/counter <code>initialization</code> code from their use (you should not keep these initialization statements inside any of your delete/modify/sort methods):</p> <pre><code>private static int i=0; private static ShowInfo[] arr=new ShowInfo[NO_OF_SHOWINFOS]; </code></pre> <p>With these, your <code>addShow</code> method will change into something like this:</p> <pre><code>public static void addShow() throws IOException { //initialize counter //int i = 0; //arr = new showInfo[i]; //showInfo temp = new showInfo(); //input information do { showInfo temp = new showInfo(); System.out.print("Enter the name of show: "); String showName = br.readLine(); temp.name = showName; System.out.print("Enter which day of the week a new episode premieres: "); String showDay = br.readLine(); temp.day = showDay; System.out.print("Enter time in 24-hour format (e.g. 2100, 1900): "); int showTime = Integer.valueOf(br.readLine()).intValue(); temp.time = showTime; //i++; arr[i++]=temp; System.out.print("Would you like to add another show? (y/n) "); } while((br.readLine().compareTo("n"))!=0); } </code></pre> <p>}</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload