Class Dvdset { //define three properties string[] name = new STRING[50];//To ensure that the array is large enough string[] date = new string[50];//time to borrow books
int[] state = new INT[50]; The state of borrowing, 0 means lending, 1. Can borrow. int[] count = new INT[50];//number of borrowing books}
Import Java.util.*;import java.text.*;class dvdmgr {//Create a Dvdset object Dvdset DVD = new Dvdset (); 1. First method initializes three DVD data public void initial () {//Initialize three DVDs dvd.name[0]= "Roman Holiday"; dvd.state[0]=0; Dvd.count[0] = 30; Dvd.date[0]= "2016-11-18"; Dvd.name[1]= "jittery"; Dvd.state[1]=1; dvd.name[2]= "romantic Full House"; Dvd.state[2]=1; DVD.COUNT[2] = 10; }//2. Implement a menu toggle public void StartMenu () {System.out.println ("*********************************"); SYSTEM.OUT.PRINTLN ("****** Welcome to use Mini DVD manager ******"); SYSTEM.OUT.PRINTLN ("****** 1. Add DVD ******"); SYSTEM.OUT.PRINTLN ("****** 2. View DVD ******"); SYSTEM.OUT.PRINTLN ("****** 3. Delete dvd ******"); SYSTEM.OUT.PRINTLN ("****** 4. Loan DVD ******"); SYSTEM.OUT.PRINTLN ("****** 5. Return DVD ******"); SYSTEM.OUT.PRINTLN ("****** 6.DVD leaderboard ******"); SySTEM.OUT.PRINTLN ("****** 7. Exit ******"); System.out.println ("*********************************"); Scanner input = new Scanner (system.in); System.out.println ("Please enter your manipulation:"); int option = Input.nextint (); Switch (option) {case 1:adddvd (); Returnmenu (); Break Case 2:searchdvd (); Returnmenu (); Break Case 3:deletedvd (); Returnmenu (); Break Case 4:lenddvd (); Returnmenu (); Break Case 5:returndvd (); Returnmenu (); Break Case 6:list (); Returnmenu (); Break Case 7:SYSTEM.OUT.PRINTLN ("Thank you for using, welcome next time"); Break Default:system.oUT.PRINTLN ("Input exception, program has been scared of crashing, is rebooting ..."); Break }}//3. Return menu public void Returnmenu () {System.out.println ("Input 0 Returns:"); Scanner input = new Scanner (system.in); if (input.nextint () = = 0) {//Enter this menu to switch StartMenu (); }else {System.out.println ("input exception, please enter from:"); Returnmenu (); Recursive invocation. }}//4. View features public void Searchdvd () {System.out.println ("****** Welcome to view Page * * * * * * *"); \ t Tap System.out.println ("ordinal \ t name \t\t status \ t loan time \ T"); for (int i=0;i<dvd.name.length; i++) {if (dvd.name[i] = = null) {break; }else if (dvd.state[i] = = 0) {//represents already loaned System.out.println (i+1+ "\ T" + "<<" +dvd.name[ I]+ ">>\t has lent \ t" +dvd.date[i]); }else if (dvd.state[i] = = 1) {//Generation not lent System.out.println (i+1+ "\ T" + "<<" +dvd.name[i]+ " ;>\t can borrow \ t "); }} System.out.println ("**************************************"); }//5. Add dvd public void Adddvd () {System.out.println ("****** Welcome to add Page * * * * *"); System.out.println ("Please enter the DVD you want to add:"); Scanner input = new Scanner (system.in); String name = Input.next (); Put the new content to the last for (int i = 0;i<dvd.name.length;i++) {if (dvd.name[i] = = null) {//to the last. Dvd.name[i] = name; Dvd.state[i] = 1; System.out.println ("<<" +name+ ">>dvd add Success"); Break }}}//6. Remove the DVD public void Deletedvd () {System.out.println ("****** Welcome to the DELETE page * * * * * * *"); System.out.println ("Please enter the name of the DVD you want to delete:"); Scanner input = new Scanner (system.in); String name = Input.next (); 1. No find: Prompt not found please re-enter//2. Found://1. Has been borrowed: cannot delete//2. Not lent: Delete for (int i = 0;i<dvd.name.length;i++) {//Find out if there is an if (dvd.name[i]! = null) {if (Dvd.name[i].equalsignor Ecase (name)) {//has been found//has been lent out if (dvd.state[i] = = 0) {//Lent S Ystem.out.println ("+name+" has been Lent "); Break }else if (dvd.state[i] = = 1) {//No loan needed to delete//idea: 1. Replace the previous one with the latter. 2. Assign a value of NULL to the last superfluous place. for (int j = i; j<dvd.name.length;j++) {//Swap if (dvd.name[j +1]! = null) {Dvd.name[j] = dvd.name[j+1]; DVD.STATE[J] = dvd.state[j+1]; }else{//Empties last value dvd.name[j] = null; DVD.DATE[J] = null; Break }} System.out.println ("delete" +name+ "success"); Break }}}else {System.out.println ("No DVD you want to delete"); System.out.println ("***********************************************"); Break }}}//7. The function of borrowing DVD public void Lenddvd () {System.out.println ("******** Welcome to the Borrowing page ********"); System.out.println ("Please enter the name of the DVD you want to borrow:"); Scanner input = new Scanner (system.in); String name = Input.next (); 1. Determine if there is a DVD//1. Not being lent out. for (int i = 0;i<dvd.name.length;i++) {if (dvd.name[i]! = NULL) {//have DVD if (Dvd.name[i].equalsi Gnorecase (name) && Dvd.state[i] = = 1) {//have books and not be lent//borrow books 1. Modify the status Dvd.state[i] = 0; System.out.println ("Please enter the time of borrowing (year-month-day):"); Scanner inputdate = new Scanner (system.in); Dvd.date[i] = Inputdate.next (); System.out.println ("library success"); dvd.count[i]++; Break }else if (dvd.name[i].equalsignorecase (name) && Dvd.state[i] = = 0) {System.out.println ("I'm sorry this library has By being lent out "); Break }}else {//DVD System.out.println ("No DVD you are looking for"); Break }}}//8. Also DVD calculated price public void Returndvd () {System.out.println ("******** Welcome into also DVD page **************** **"); System.out.println ("Please enter also the name of the DVD:"); Scanner input = new Scanner (system.in); Double price = 0.0; String name = Input.next (); for (int i = 0;i<dvd.name.length;i++) {if (dvd.name[I]!=null) {//have if (dvd.name[i].equalsignorecase (name) && Dvd.state[i] = = 0) {//To be repaid on loan Dvd.state[i] = 1; System.out.println ("Please enter the time to return the book (year-month-day):"); Scanner inputdate = new Scanner (system.in); Gets the time difference long charge = charge (Dvd.date[i],inputdate.next ()); Price = charge * 1; System.out.println ("+dvd.name[i]+", "The Return of Success"); System.out.println ("You deal with" +price+ "Yuan"); Emptying time dvd.date[i] = null; Break }}else{System.out.println ("No matching information found"); Break }} System.out.println ("************************************************"); } Public long Charge (string date1,string date2) {//Make time difference//convert String to date for calculation Simpledateforma T sd = new SimpleDateFormat ("Yyyy-mm-dd");Long charge = 0; try{Date D1 = sd.parse (date1); Date D2 = Sd.parse (Date2); The time is also measured in milliseconds. Charge = (d2.gettime ()-d1.gettime ())/(1000*24*60*60); }catch (ParseException e) {System.out.println (e); } return charge; }//Leaderboard public void list () {System.out.println ("Welcome to DVD leaderboard"); Sort for (int i = 0; I <dvd.name.length-1;i++) {if (dvd.name[i]! = null) { for (int j = 0; j<dvd.name.length-1-i;j++) {if (dvd.name[j]! = null) {if (DVD . Count[j] < dvd.count[j+1]) {int temp = dvd.count[j]; DVD.COUNT[J] = dvd.count[j+1]; dvd.count[j+1]= temp; String name1 = Dvd.name[j]; DVD.NAME[J] = dvd.name[j+1]; DVD.NAME[J+1] = name1; String date1= Dvd.date[j]; DVD.DATE[J] = dvd.date[j+1]; DVD.DATE[J+1] = date1; int state1= Dvd.state[j]; DVD.STATE[J] = dvd.state[j+1]; DVD.STATE[J+1] = state1; }}else {break; }}}else{break; }} System.out.println ("ordinal \ t name \t\t State \ t loan time \ T"); for (int i=0;i<dvd.name.length; i++) {if (dvd.name[i] = = null) {break; }else if (dvd.state[i] = = 0) {//represents already loaned System.out.println (i+1+ "\ T" + "<<" +dvd.name[ I]+ ">>\t has lent \ t" +dvd.date[i]); }else if (dvd.state[i] = = 1) {//Generation not lent System.out.println (i+1+ "\ T" + "<<" +dvd.name[i]+ ">>\t can borrow \ t"); }} System.out.println ("**************************************"); } }
Class dvdmain{public static void Main (string[] args) { dvdmgr DVD = new Dvdmgr (); Initialize DVD dvd.initial (); Start into the Toggle menu dvd.startmenu ();} }
DVD Management System