Java programming, thanks! Main topics: Menu driven programming Programmer define
ID: 3697867 • Letter: J
Question
Java programming, thanks!
Main topics: Menu driven programming Programmer defined methods, Arrays, Parallel Arrays
Program Specification:
You are someone who has decided that they need to organize their DVD / Movie collection. To do so, you have decided to write a program suited to this task. For each DVD / Movie you will store and maintain its Title, and its running Length (in minutes).
• title (a character string)
• length (a positive Integer)
The program will allow its user to add a DVD / Movie title and its running length and to display the results of various searches, in some reasonable format.
Rules and Requirements:
Each piece of a DVD / Movie’s information must be stored in an appropriately typed array. This means you will have two parallel arrays.
Your DVD / Movie organizer must be able to accommodate up to 128 DVD / Movies.
Your program will work off of a main menu that, repeatedly, allows it user to select from the following options:
1. (Add a DVD / Movie to the DVD / Movie Organizer)
(a) Check if the DVD / Movie Organizer is already full, if so display an appropriate message and stop here.
(b) Prompt for and read a title from the user.
(c) Prompt for and read a length from the user.
(d) Store this information into the appropriate arrays, at the appropriate location.
2. (Title Search the DVD / Movie Organizer)
(a) Prompt for and read a title search string from the user: tSStr.
(b) If tSStr does not end with the character ’*’ then you display to the screen, all of the DVD
/ Movie (titles and lengths) in the Organizer whose title exactly matches the string tSStr.
(c) If tSStr does with the character ’*’ then you display to the screen, all of the DVD / Movie (titles and lengths) in the Organizer whose title exactly matches the string tSStr up to,
but not including the index of the ’*’ in tSStr. Hint: subString()
3. (Length Search the DVD / Movie Organizer)
(a) Prompt for and read a length search string from the user: lSStr.
(b) If lSStr starts with the character ’<’ then you display to the screen, all of the DVD / Movie (titles and lengths) in the Organizer whose length is less than that specified by remaining characters of lSStr. Hint: subString(), ParseInt()
(c) If lSStr starts with the character ’=’ then you display to the screen, all of the DVD / Movie (titles and lengths) in the Organizer whose length is equal to that specified by remaining characters of lSStr. Hint: subString(), ParseInt()
(d) If lSStr starts with the character ’>’ then you display to the screen, all of the DVD / Movie (titles and lengths) in the Organizer whose length is greater than that specified by remaining characters of lSStr. Hint: subString(), ParseInt()
(e) If lSStr does not match one of the above three cases, then an appropriate error message is displayed.
4. (Quit the DVD / Movie Organizer Program)
When and only when selected, your program terminates.
• You must use implement the following method headings (with no modifications) and use each method in your program:
Notes and Hints:
• The effective use of additional methods may help to simplify the understanding as well as implemen- tation of this assignment.
Sample run(s):
***************************
A Add a DVD *
T Search by Title *
L Search by Length *
Q Quit *
***************************
Please enter an option : a
***************************
***************************
A Add a DVD *
T Search by Title *
L Search by Length *
Q Quit *
***************************
Please enter an option : a
***************************
***************************
A Add a DVD *
T Search by Title *
L Search by Length *
Q Quit *
***************************
Please enter an option : a
***************************
***************************
A Add a DVD *
T Search by Title *
L Search by Length *
Q Quit *
***************************
Please enter an option : t
***************************
***************************
A Add a DVD *
T Search by Title *
L Search by Length *
Q Quit *
***************************
***************************
A Add a DVD *
T Search by Title *
L Search by Length *
Q Quit *
***************************
Please enter an option : l
***************************
***************************
A Add a DVD *
T Search by Title *
L Search by Length *
Q Quit *
***************************
Please enter an option : l
***************************
***************************
A Add a DVD *
T Search by Title *
L Search by Length *
Q Quit *
***************************
***************************
A Add a DVD *
T Search by Title *
L Search by Length *
Q Quit *
***************************
Please enter an option : q
***************************
Explanation / Answer
import java.util.Scanner;
public class DVDOrganizer {
public static void main(String[] args) {
int size = 128;
String titles[] = new String[size];
int lengths[] = new int[size];
int numDVDs = 0;
Scanner stdIn = new Scanner(System.in);
do {
String menuOption = menu(stdIn);
switch (menuOption) {
case "A":
numDVDs = addDVD(titles, lengths, numDVDs, stdIn);
break;
case "T":
searchByTitle(titles, lengths, numDVDs, stdIn);
break;
case "L":
searchByLength(titles, lengths, numDVDs, stdIn);
break;
case "Q":
stdIn.close();
System.exit(0);
break;
}
} while (true);
}
public static String menu(Scanner stdIn) {
// diplay menu to the screen
System.out.println("****************************");
System.out.println("A Add DVD*");
System.out.println("T Search By Title*");
System.out.println("L Search By Length*");
System.out.println("Q Quit*");
System.out.println("****************************");
// prompt for and get String responce
System.out.print("Please Enter an option: ");
String s = stdIn.nextLine();
System.out.println("****************************");
String menuOption = s.trim().toUpperCase();
// return responce
return menuOption;
}
public static int addDVD(String[] titles, int[] lengths, int numDVDs, Scanner stdIn) {
// our DVD / Movie organizer must be able to accommodate up to 128 DVD / Movies
if (numDVDs < 128) {
// prompt for and get a title and a length from user
System.out.print("Please enter DVD title: ");
titles[numDVDs] = stdIn.nextLine().trim();
// add to titles and lengths arrays at index numDVDs
System.out.print("Please enter DVD length: ");
lengths[numDVDs] = Integer.parseInt(stdIn.nextLine().trim());
return numDVDs + 1;
} else {
System.out.println("DVD / Movie organizer is full. Unable to accommodate new DVD / Movie");
return numDVDs;
}
}
public static void searchByTitle(String titles[], int lengths[], int numDVDs, Scanner stdIn) {
// prompt for and get title search string from user
System.out.print("Please enter DVD title (post * allowed): ");
String tSStr = stdIn.nextLine().trim();
// diplay all matching DVD / Movies and their length to the screen
System.out.println("Titles Lengths");
System.out.println("--------------------------------");
String title = tSStr.substring(0, tSStr.length()-1);
boolean foundResults = false;
for (int i = 0; i < numDVDs; i++) {
if (tSStr.endsWith("*") && titles[i].contains(title) ||
titles[i].equalsIgnoreCase(tSStr)) {
System.out.println(titles[i] + " " + lengths[i]+"min");
foundResults = true;
}
}
if(!foundResults){
System.out.println("No results found with the search title: "+tSStr);
}
}
public static void searchByLength(String[] titles, int[] lengths, int numDVDs, Scanner stdIn) {
// prompt for and get length search string from user
System.out.print("Please enter DVD length (pre < = > manditory): ");
String lSStr = stdIn.nextLine().trim();
// diplay all matching DVD / Movies and their length to the screen
System.out.println("Titles Lengths");
System.out.println("--------------------------------");
int length = Integer.parseInt(lSStr.substring(1));
boolean foundResults = false;
for (int i = 0; i < numDVDs; i++) {
if (lSStr.startsWith("<") && lengths[i] < length ||
lSStr.startsWith(">") && lengths[i] > length ||
lSStr.startsWith("=") && lengths[i] == length) {
System.out.println(titles[i] + " " + lengths[i]+"min");
foundResults = true;
}
}
if(!foundResults){
System.out.println("No results found with the search length: "+lSStr);
}
}
}
Output:
****************************
A Add DVD*
T Search By Title*
L Search By Length*
Q Quit*
****************************
Please Enter an option: a
****************************
Please enter DVD title: The Fly
Please enter DVD length: 124
****************************
A Add DVD*
T Search By Title*
L Search By Length*
Q Quit*
****************************
Please Enter an option: a
****************************
Please enter DVD title: The Wizard of Oz
Please enter DVD length: 167
****************************
A Add DVD*
T Search By Title*
L Search By Length*
Q Quit*
****************************
Please Enter an option: a
****************************
Please enter DVD title: How to Fly Fish
Please enter DVD length: 30
****************************
A Add DVD*
T Search By Title*
L Search By Length*
Q Quit*
****************************
Please Enter an option: t
****************************
Please enter DVD title (post * allowed): The
Titles Lengths
--------------------------------
No results found with the search title: The
****************************
A Add DVD*
T Search By Title*
L Search By Length*
Q Quit*
****************************
Please Enter an option: t
****************************
Please enter DVD title (post * allowed): The*
Titles Lengths
--------------------------------
The Fly 124min
The Wizard of Oz 167min
****************************
A Add DVD*
T Search By Title*
L Search By Length*
Q Quit*
****************************
Please Enter an option: l
****************************
Please enter DVD length (pre < = > manditory): <100
Titles Lengths
--------------------------------
How to Fly Fish 30min
****************************
A Add DVD*
T Search By Title*
L Search By Length*
Q Quit*
****************************
Please Enter an option: l
****************************
Please enter DVD length (pre < = > manditory): =124
Titles Lengths
--------------------------------
The Fly 124min
****************************
A Add DVD*
T Search By Title*
L Search By Length*
Q Quit*
****************************
Please Enter an option: l
****************************
Please enter DVD length (pre < = > manditory): >124
Titles Lengths
--------------------------------
The Wizard of Oz 167min
****************************
A Add DVD*
T Search By Title*
L Search By Length*
Q Quit*
****************************
Please Enter an option: q
****************************
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.