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

Please help! This is java programming. Main topics: Menu driven programming Prog

ID: 3697340 • Letter: P

Question

Please help! This is java programming.

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;

/**
* @author
*
*/
public class MovieCollection {

   /**
   * @param args
   */
   public static void main(String[] args) {
       // TODO Auto-generated method stub
       Scanner stdIn = null;
       Scanner stdIn1 = null;
       try {
           stdIn = new Scanner(System.in);
           stdIn1 = new Scanner(System.in);

           String titles[] = new String[128];
           int lengths[] = new int[128];
           int numDVDs = 0;

           while (true) {

               String choice = menu(stdIn);
               if (choice.equalsIgnoreCase("q")) {
                   break;
               } else if (choice.equalsIgnoreCase("a")) {

                   if (numDVDs == 128) {
                       System.out
                               .println("the DVD / Movie Organizer is already full");
                   } else {
                       System.out.print("Please enter DVD title :");
                       String title = stdIn1.nextLine();
                       System.out.print("Please enter DVD length :");
                       int length = stdIn.nextInt();

                       titles[numDVDs] = title;
                       lengths[numDVDs] = length;
                       numDVDs++;
                   }

               } else if (choice.equalsIgnoreCase("t")) {

                   searchByTitle(titles, lengths, numDVDs, stdIn);
               } else if (choice.equalsIgnoreCase("l")) {

                   searchByLength(titles, lengths, numDVDs, stdIn);
               } else {
                   System.out.println("Invalid Choice");
               }

           }
       } catch (Exception e) {
           // TODO: handle exception
           e.printStackTrace();
       }
   }

   // diplay menu to the screen
   // prompt for and get String responce
   // return responce
   public static String menu(Scanner stdIn) {

       String choice = "";

       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 : ");
       choice = stdIn.next();
       System.out.println("***************************");
       return choice;
   }

   // 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) {

       return 0;
   }

   // 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) {
       System.out.print("Please enter DVD title (post * allowed) :");
       String tSStr = stdIn.next();
       if (!tSStr.contains("*")) {
           for (int i = 0; i < numDVDs; i++) {
               if (titles[i].equals(tSStr)) {
                   System.out.println(titles[i] + " " + lengths[i] + " min");
               }
           }

       } else {
           tSStr = tSStr.substring(0, tSStr.length() - 1);
           for (int i = 0; i < numDVDs; i++) {
               boolean flag = titles[i].substring(0, tSStr.length()).equals(
                       tSStr);
               if (flag) {
                   System.out.println(titles[i] + " " + lengths[i] + " min");
               }
           }

       }

   }

   // prompt for and get length 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) {

       try {

           System.out.print("Please enter DVD length (pre < = > manditory) :");
           String lSStr = stdIn.next();

           char condition = lSStr.charAt(0);
           int length = Integer.parseInt(lSStr.substring(1, lSStr.length()));
           switch (condition) {
           case '<':
               for (int i = 0; i < numDVDs; i++) {
                   if (lengths[i] < length)
                       System.out.println(titles[i] + " " + lengths[i]
                               + " min");
               }
               break;
           case '>':
               for (int i = 0; i < numDVDs; i++) {
                   if (lengths[i] > length)
                       System.out.println(titles[i] + " " + lengths[i]
                               + " min");
               }
               break;
           case '=':
               for (int i = 0; i < numDVDs; i++) {
                   if (lengths[i] == length)
                       System.out.println(titles[i] + " " + lengths[i]
                               + " min");
               }
               break;
           default:
               break;
           }

       } catch (Exception e) {
           // TODO: handle exception
           System.out.println("Invalid choice");
       }

   }

}

OUTPUT:
***************************
A Add a 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 a 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 a 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 a DVD *
T Search by Title *
L Search by Length *
Q Quit *
***************************
Please enter an option : t
***************************
Please enter DVD title (post * allowed) :The*
The Fly 124 min
The Wizard of Oz 167 min
***************************
A Add a DVD *
T Search by Title *
L Search by Length *
Q Quit *
***************************
Please enter an option : l
***************************
Please enter DVD length (pre < = > manditory) :<100
How to Fly Fish 30 min
***************************
A Add a DVD *
T Search by Title *
L Search by Length *
Q Quit *
***************************
Please enter an option : =124
***************************
Invalid Choice
***************************
A Add a DVD *
T Search by Title *
L Search by Length *
Q Quit *
***************************
Please enter an option : l
***************************
Please enter DVD length (pre < = > manditory) :=124
The Fly 124 min
***************************
A Add a DVD *
T Search by Title *
L Search by Length *
Q Quit *
***************************
Please enter an option : l
***************************
Please enter DVD length (pre < = > manditory) :>124
The Wizard of Oz 167 min
***************************
A Add a DVD *
T Search by Title *
L Search by Length *
Q Quit *
***************************
Please enter an option : q
***************************

NOTE: I cannot able to add the code to addDVD() method, we cannot return title ,length and numDVDs,
there is conflict in the method signature, please check