Question
DebugNine2.java import java.util.*; public class DebugNine2 { public static void main(String[] args) { Scanner input = new Scanner(System.in); Movie[] movies = new Movie[8]; int i;
DebugNine2.java
import java.util.*;
public class DebugNine2
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
Movie[] movies = new Movie[8];
int i;
String message, entry;
movies[0] = new Movie("The Godfather", 1972);
movies[0] = new Movie("The Good, the Bad, and the Ugly", 1966);
movies[0] = new Movie("Pulp Fiction", 1994);
movies[0] = new Movie("Shindler's List", 1993);
movies[4] = new Movie("Casablanca", 1942);
movies[5] = new Movie("Wizard of Oz", 1939);
movies[6] = new Movie("Citizen Kane", 1941);
movies[7] = new Movie("Some Like It Hot", 1959);
System.out.println( "Sort Movies by (N)ame, or (Y)ear");
entry = input.next();
if(entry.charAt(0) == 'Y')
{
nameSort(movies);
message = "Sorted by Name ";
}
else
{
yearSort(movies);
message = "Sorted by Year ";
}
display(movies, message);
}
public static void nameSort(Movie[] array)
{
int a, b;
Movie temp;
int highSub = array.length;
for(a = 0; a
{
for(b = 0; b
{
String first = array[b].getName();
String second = array[b + 1].getName();
if(first.compareTo(second > 0)
{
temp = array[b];
array[b] = array[b];
array[b + 1] = tem;
}
}
}
}
public static void yearSort(Movie[] array)
{
int a, b;
Movie temp;
int highSub = array.length - 1;
for (a = 0; a
{
for (b = 0; b
if (array[b].getYear() > array[b + 1].getYear())
{
temp = array[b];
array[b] = array[b + 1];
array[b + 1] = temp;
}
}
}
public static void display(Movie[] s, String msg)
{
int len = s.length;
for (int i = 0; i
msg = msg + s[i].getName() + ", " + s[i].getYear() + " ";
System.out.println(msg);
}
}
--------------------------------------------------------------------------------------------------------
Movie.Java
public class Movie { private String name; private int year; Movie(String s, int y) { name = s; year = y; } public String getName() { return name; } public int getYear() { return year; } }
Debugging Exercise 9-2 Settings DebugNine2.java Movie.java.,+ 1 import java.util.*; 2 public class DebugNine2 Theme ul public static void main(String] args) Light Scanner input new Scanner (System.in); Movie[] movies new Movie[8]; int i String message, entry; movies[0]-new Movie("The Godfather", 1972); movies[0]-new Movie("The Good, the Bad, and the Ugly", 1966); movies[]new Movie( "Pulp Fiction", 1994); movies[]new Movie( "Shindler's List", 1993) movies [4]new Movie( "Casablanca", 1942); movies[5]new Movie( "Wizard of 0z", 1939); movies[6]new Movie( "Citizen Kane", 1941); movies[7]-new Movie( Sone Like It Hot", 1959); System.out.println "Sort Movies by n(N)ame, or (Y)ear") entry -input.next); if(entry.charAt(e)'Y' Keymap Default 10 Download 12 13 14 15 16 17 18 19 20 21 Click Here o Share Click Here A Reset Files Click Here naneSort(movies); message-"Sorted by Name n" 23 24 25 26 27 28 29 30 else yearSort(novies) message-"Sorted by YearIn" display(novies, message)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started