JAVA basic code sharing-DVD management, java basic code-dvd

Source: Internet
Author: User

JAVA basic code sharing-DVD management, java basic code-dvd

Problem description

A mini DVD manager is developed for a video store, which can store a maximum of six DVDs for disk management.

The manager has the following functions:

1. view the DVD information.

Select view from the menu to display information about the DVD.

 

2. New DVD information

 

Select the Add function, enter the new DVD name as prompted, and add it to the inventory. If the DVD shelf is full, that is, six new DVDs are displayed, an error is displayed.

 

3. Delete the DVD information

 

Run the DELETE command and enter the name of the DVD to be deleted. If the DVD is in the lending status, deletion is not allowed. If the DVD information is not found, the system prompts "no matching information is found ";

 

4. Borrow a DVD

 

If the DVD has been lent, the system prompts "XX has been lent ". If no matching information is found, the system prompts "no matching information is found !". In addition, the default value is 31 days for a month. If the input lending date is a number greater than 31, the system will prompt that "a number greater than or equal to 1 and less than or equal to 31 must be entered, enter "again ".

 

5. Return the DVD

 

Calculate the rent, 1 day, 1 yuan. If the returned DVD has not been lent out, the system prompts "the DVD has not been lent out and cannot be returned. If the returned DVD does not match the DVD in the list, the system prompts "no matching information found "., If the return time is less than the lending time, or a number greater than 31, the system prompts "The return date cannot be less than the lending date. Please enter it again, and the month is only 31 days. Please enter it again."

 

6. End the program when the user executes the exit command.

Code sharing

 

 

Public class ManagerDVD {private static String [] [] dvdstr = new String [6] [5]; private static int n = 0; // The Operation Command private static variable in entered by the user; // enter the number private static variable input; // enter the private static String name = null for Chinese characters; // DVD name public static void main (String [] args) {System. out. println ("-------------------- welcome to the DVD Management System ------------------"); System. out. println ("System Operation Command: \ n1, add DVD \ n2, delete DVD \ n3, view DVD \ n 4. Borrow a DVD \ n5, return the DVD \ n0, and log out. "); in = new versions (System. in); for (int I = 0; I <6; I ++) {dvdstr [I] [0] = "" + (I + 1 ); dvdstr [I] [4] = "0";} do {System. out. print ("Enter the operation command:"); n = in. nextInt (); if (n! = 0) {setManager (n) ;}} while (n! = 0);} private static void setManager (int n) {switch (n) {case 1: System. out. println ("add a DVD"); if (dvdstr [5] [2]! = Null) {System. out. println ("the DVD inventory is full and cannot be added"); break;} System. out. print ("Enter the DVD name:"); input = new release (System. in); name = input. nextLine (); boolean boo = true; for (int I = 0; I <6; I ++) {if (dvdstr [I] [2]! = Null & name. equals (dvdstr [I] [2]) {boo = false; break ;}} if (boo) {for (int I = 0; I <6; I ++) {if (dvdstr [I] [2] = null) {dvdstr [I] [1] = "not lent"; dvdstr [I] [2] = name; System. out. println ("added successfully"); break ;}} else {System. out. println ("this DVD already exists");} break; case 2: System. out. println ("delete DVD"); if (dvdstr [0] [2] = null) {System. out. println ("the inventory has no DVDs and cannot be deleted"); break;} System. out. print ("Enter the DVD name:"); input = new Using (System. in); name = input. nextLine (); boolean bo = false; for (int I = 0; I <6; I ++) {if (dvdstr [I] [2]! = Null & name. equals (dvdstr [I] [2]) {for (int j = I; j <5; j ++) {dvdstr [j] [1] = dvdstr [j + 1] [1]; dvdstr [j] [2] = dvdstr [j + 1] [2]; dvdstr [j] [3] = dvdstr [j + 1] [3]; dvdstr [j] [4] = dvdstr [j + 1] [4];} dvdstr [5] [1] = null; dvdstr [5] [2] = null; dvdstr [5] [3] = null; dvdstr [5] [4] = null; bo = true; break;} if (bo) {System. out. println ("deletion successful");} else {System. out. println ("this item not found");} break; case 3: System. out. println ("View DVD"); System. out. println ("No. \ t status \ t name \ t lending date \ t lending times"); for (int I = 0; I <6; I ++) {if (dvdstr [I] [2] = null) {break;} System. out. println (dvdstr [I] [0] + "\ t" + dvdstr [I] [1] + "\ t" + dvdstr [I] [2] + "\ t \ t "+ dvdstr [I] [3] +" \ t "+ dvdstr [I] [4]);} break; case 4: System. out. println ("borrow a DVD"); if (dvdstr [0] [2] = null) {System. out. println ("the inventory does not have a DVD and you cannot borrow it"); break;} System. out. print ("enter the name of the DVD:"); name = input. nextLine (); Boolean B = false; for (int I = 0; I <6; I ++) {if (dvdstr [I] [2]! = Null & name. equals (dvdstr [I] [2]) {if ("not lent ". equals (dvdstr [I] [1]) {System. out. print ("Enter the lending date:"); int date = 0; do {date = in. nextInt () ;}while (date> 31 & date <= 0); dvdstr [I] [1] = "Lent "; dvdstr [I] [3] = "" + date; dvdstr [I] [4] = "" + (Integer. parseInt (dvdstr [I] [4]) + 1); System. out. println ("lending operation completed");} else {System. out. println ("this DVD has been lent out");} B = true; break ;}} if (! B) {System. out. println ("this DVD does not exist");} break; case 5: System. out. println ("Return DVD"); if (dvdstr [0] [2] = null) {System. out. println ("the inventory has no DVDs and cannot be returned"); break;} System. out. print ("enter the name of the DVD:"); name = input. nextLine (); boolean flag = false; for (int I = 0; I <6; I ++) {if (dvdstr [I] [2]! = Null & name. equals (dvdstr [I] [2]) {if ("Lent ". equals (dvdstr [I] [1]) {System. out. print ("Enter return date:"); int date = 0; int lend = Integer. parseInt (dvdstr [I] [3]); do {date = in. nextInt () ;}while (date> 31 & date <= 0 & date> = lend); dvdstr [I] [1] = "not lent "; dvdstr [I] [3] = null; System. out. println ("return operation completed"); System. out. println ("lending date:" + lend); System. out. println ("return date:" + date); System. out. println ("you need to pay the total rent:" + (date- Lend) * 5) + "Yuan");} else {System. out. println ("this DVD has been lent");} flag = true; break;} if (! Flag) {System. out. println ("this DVD does not exist");} break; default: System. out. println ("the command you entered is invalid! "); Break ;}}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.