Note that there are some explanatory texts on larger screens.

plurals
  1. POSorting with Strings and int in array
    primarykey
    data
    text
    <p>My assignment asks me to make a TV show program, where I can input shows, delete, modify and sort them. What I'm stuck on is the sorting part. The program prompts the user for the name of the show, day a new episode premieres, and time, which are stored in the array. It's sorts by the keys name, day, and time (alphabetically and numerically). </p> <p>The program prompts the user to input one of those keys, then the program needs to sort the shows by that key (sorting by day will sort alphabetically). </p> <p>I made a class and used an array to save the inputted shows. Here is the class: </p> <pre><code>public class showInfo { String name; String day; int time; } </code></pre> <p>I've inputted the shows 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 { 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++; System.out.print("Would you like to add another show? (y/n) "); } while((br.readLine().compareTo("n"))!=0); } </code></pre> <p>In order to sort by time, I've written the following method:</p> <pre><code>public static void timeSort() { int min; for (int i = 0; i &lt; arr.length; i++) { // Assume first element is min min = i; for (int j = i+1; j &lt; arr.length; j++) { if (arr[j].time &lt; arr[min].time) { min = j; } } if (min != i) { int temp = arr[i].time; arr[i].time = arr[min].time; arr[min].time = temp; } } System.out.println("TV Shows by Time"); for(int i = 0; i &lt; arr.length; i++) { System.out.println(arr[i].name + " - " + arr[i].day + " - " + arr[i].time + " hours"); } } </code></pre> <p>My problem is that when I call it and output it in the main, it only shows "TV Shows by Time" text, but not the shows. Why is this? (Should I show my full code?) </p> <p>I think my issue has something to do with the counter, but I'm not sure how I'd fix that since the user is supposed to input as many shows as they'd like and the amount of shows is modified and deleted in other methods.</p> <p>Any help would be great! Thanks in advance!</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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