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

Java programming, thanks! Main topics: Menu driven programming Programmer define

ID: 3695493 • 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

public class organize {
private static int MaxOrganize = 128;
private static String[] titles;
private static int[] lengths;
//private static int numDVDs;
  
public organize(){
//numDVDs = 0;
MaxOrganize = 128;
titles = new String[MaxOrganize];
lengths = new int[MaxOrganize];
for (int i=0; i<MaxOrganize; i++){
titles[i] = "";
lengths[i] = 0;
}
}
  
// diplay menu to the screen
// prompt for and get String responce
// return responce
public static String menu(Scanner stdIn){
String responce="";
System.out.println("***************************");
System.out.println("A Add a DVD *");
System.out.println("T Search by Title *");
System.out.println("L Search by Length *");
System.out.println("Q Quit *");
System.out.println("***************************");
System.out.print("Please enter an option : ");
responce = stdIn.nextLine();
System.out.println("***************************");
  
return responce;
}
// prompt for and get a title and a length from user
// add to titles and lengths arrays at index numDVDs
// return numDVDs + 1
public static int addDVD(String[] titles, int[] lengths, int numDVDs, Scanner stdIn){
String s="";
if (numDVDs >= MaxOrganize){
System.out.println("DVD / Movie organizer is full");
return numDVDs;
}
System.out.print("Please enter DVD title : ");
titles[numDVDs] = stdIn.nextLine();
System.out.print("Please enter DVD length : ");
lengths[numDVDs] = stdIn.nextInt();
numDVDs = numDVDs + 1;
System.out.println();
System.out.println("successfully added!");
  
return numDVDs;
}
// prompt for and get title search string from user
// diplay all matching DVD / Movies and their length to the screen
public static void searchByTitle(String titles[], int lengths[], int numDVDs, Scanner stdIn){
String tSStr="";
System.out.print("Please enter DVD title (post * allowed) : ");
tSStr = stdIn.nextLine();
  
if (tSStr.indexOf('*', 0) < 0){
for (int i=0; i<=numDVDs; i++){
if (titles[i].compareTo(tSStr) == 0)
System.out.println(titles[i]+" "+lengths[i]+"min");
}
}else{
String s = tSStr.substring(0, tSStr.indexOf('*'));
for (int i=0; i<=numDVDs; i++){
if (titles[i].contains(s))
System.out.println(titles[i]+" "+lengths[i]+"min");
}
}
}
// prompt for and get title search string from user
// diplay all matching DVD / Movies and their length to the screen
public static void searchByLength(String titles[], int lengths[], int numDVDs, Scanner stdIn){
String tSStr="";
System.out.print("Please enter DVD length (pre < = > manditory) : ");
tSStr = stdIn.nextLine();
  
String s = tSStr.substring(tSStr.indexOf('*'));
int d = parseInt(s);
if (tSStr.charAt(0) == '<'){
for (int i=0; i<numDVDs; i++){
if (lengths[i]<d)
System.out.println(titles[i]+" "+lengths[i]+"min");
}
}else
if (tSStr.charAt(0) == '='){
for (int i=0; i<numDVDs; i++){
if (lengths[i]==d)
System.out.println(titles[i]+" "+lengths[i]+"min");
}
}else
if (tSStr.charAt(0) == '>'){
for (int i=0; i<numDVDs; i++){
if (lengths[i]>d)
System.out.println(titles[i]+" "+lengths[i]+"min");
}
}else{
System.out.println("Error, results were not found!!");
}
}
public void run(){
Scanner stdIn = new Scanner(System.in);
boolean b=true;
int numDVDs=0;
while(b){
switch (menu(stdIn)){
case "a":
case "A": numDVDs=addDVD(titles, lengths, numDVDs, stdIn); break;
case "t":
case "T": searchByTitle(titles, lengths, numDVDs, stdIn); break;
case "l":
case "L": searchByLength(titles, lengths, numDVDs, stdIn); break;
case "q":
case "Q": b=false; break;
default : break;
}
System.out.println(numDVDs);
}
}
  
  
  
public static void main(String[] args){
organize o1 = new organize();
o1.run();
}
  
}

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