Mini DVD Manager

Source: Internet
Author: User

Create a new package first class

Package DVD;

public class Dvdset {
String[] Name=new string[50];
Boolean[] State =new boolean[50];
String[] Date=new string[50];
Int[] Count=new int[50];


}

A second class

Package DVD;

Import java.text.ParseException;
Import Java.text.SimpleDateFormat;
Import java.util.*;

public class Dvdmgr {
Scanner input= New Scanner (system.in);
Dvdset dvd=new Dvdset ();//Initialize Object
Boolean isjiechu=true;
public void initial () {
dvd.name[0]= "Roman Holidays";
Dvd.state[0]=true;
Dvd.date[0]= "2015-12-31";

Dvd.name[1]= "jittery";
Dvd.state[1]=false;
dvd.name[2]= "romantic Full House";
Dvd.state[2]=false;
}
public void Rentrnmain () {
SYSTEM.OUT.PRINTLN ("Input 0 return");
if (Input.nextint () ==0) {
StartMenu ();
}
}
public void StartMenu () {
SYSTEM.OUT.PRINTLN ("\t\t\t welcome into the Mini DVD manager");
System.out.println ("------------------------------------------------------------------------------------------" );
System.out.println ("\t\t0. Loan leaderboard");
System.out.println ("\t\t1. New DVD");
System.out.println ("\t\t2. View DVD");
System.out.println ("\t\t3. Delete DVD");
System.out.println ("\t\t4. Loan DVD");
System.out.println ("\t\t5. return DVD");
System.out.println ("\t\t6. Exit");
System.out.println ("------------------------------------------------------------------------------------------" );
SYSTEM.OUT.PRINTLN ("Please select");
int Choice=input.nextint ();
Switch (choice) {
Case 0:
List ();
Break
Case 1:
Add ();
Break
Case 2:
CK ();//View DVD
Break
Case 3:
Del ();
Break
Case 4:
Lend ();
Break
Case 5:
GH ();
break;//return DVD
Case 6:
SYSTEM.OUT.PRINTLN ("Thank you for using");
Break
Default
SYSTEM.OUT.PRINTLN ("Please re-enter" If you enter it incorrectly);
Returnmain ();
}
}



public void Returnmain () {
SYSTEM.OUT.PRINTLN ("Input 0 return");
if (Input.nextint () ==0) {
StartMenu ();
}
}
/*
* Leaderboard
*/


public void list () {
string[] newname=new string[50];
int[] Newcount=new int [50];
for (int i=0;i<dvd.name.length;i++) {
Newname[i]=dvd.name[i];
Newcount[i]=dvd.count[i];
}
for (int i=0;i<newname.length;i++) {
for (int j=i+1;j<newname.length;j++) {
if (newcount[i]> Newcount[j]) {
int TEMP=NEWCOUNT[I];//2 interchange implementation number and first name substitution
Newcount[i]=newcount[j];
Newcount[j]=temp;
String Temp1=newname[i];
Newname[i]=newname[j];
Newname[j]=temp1;
}
}
}
System.out.println ("-----< Next >-----");
System.out.println ("------------------------------------------------------------------------------------------" );
System.out.println ("the number \ t name");
/*
* Reverse Print ranking
*/
for (int i=newname.length-1;i>=0;i--) {
if (newname[i]!=null) {
System.out.println (newcount[i]+ "\ T" "+newname[i]+" ");
}
}
System.out.println ("----------------------------------------------------------------------------- -------------");
Returnmain ();
}

/* NEW DVD
*
*/

public void Add () {
System.out.println ("new DVD");
System.out.println ("Please enter the DVD name");
String Name=input.next ();
for (int i=0;i<dvd.name.length;i++) {
/*
* Determines whether the array of name positions is empty
*/
if (dvd.name[i]==null) {
Dvd.name[i]=name;
dvd.state[i]=false;//newly added is no contact.
System.out.println ("New +name+" "Success");
Break
}
}
System.out.println ("------------------------------------------------------------------------------------------" );
Returnmain ();

}

/*
* View DVD
*/
public void ck () {
System.out.println ("View DVD");
System.out.println ("ordinal \ t status \ t name \t\t loan Date");
for (int i = 0; i < dvd.name.length; i++) {
if (dvd.name[i] = = null) {
Break
} else if (dvd.state[i] = = True) {
System.out.println ((i + 1) + "\ t has lent \ t" + dvd.name[i] + "" + "\ T" + dvd.date[i]);
} else if (dvd.state[i] = = False) {
System.out.println ((i + 1) + "\ t can borrow \ T" + dvd.name[i] + "" ");
}
}
System.out.println ("------------------------------------------------------------------------------------------" );
Returnmain ();
}


/*
* Delete DVD
*/

public void Del () {
System.out.println ("delete DVD");
System.out.println ("Please enter the name of the DVD to be deleted");
String name =input.next ();
Boolean flag=false;
for (int i=0;i<dvd.name[i].length (); i++) {
if (dvd.name[i]!=null&&dvd.name[i].equalsignorecase (name) &&dvd.state[i]==false) {
int j=i;
while (Dvd.name[j+1]!=null) {
DVD.NAME[J]=DVD.NAME[J+1];
DVD.DATE[J]=DVD.DATE[J+1];
j + +;
}
Dvd.name[j]=null;
Dvd.date[j]=null;
SYSTEM.OUT.PRINTLN ("Successful deletion of" +name+ "");
flag=true;//Marking Bits
Break
}
else if (dvd.name[i]!=null&&dvd.name[i].equalsignorecase (name) &&dvd.state[i]==true) {
System.out.println ("This DVD is out of loan status, cannot be deleted");
Flag=true;
Break

}
if (flag==true) {
SYSTEM.OUT.PRINTLN ("No information found, please verify");
}
}
System.out.println ("------------------------------------------------------------------------------------------" );
Returnmain ();
}

/*
* Lend out
*/

public void lend () {
System.out.println ("Loan DVD");
System.out.println ("Please enter the name of the loan DVD");
String name =input.next ();
for (int i=0;i<dvd.name.length;i++) {
if (dvd.name[i]==null) {
System.out.println ("No matching information found");
Break
}
Else if (dvd.name[i].equals (name) &&dvd.state[i]==false) {
System.out.println ("Please enter a loan date (year-month-day)" );
Dvd.date[i]=input.next ();
System.out.println ("+name+", "the success of the loan");
Dvd.state[i]=true;
dvd.count[i]++;
break;
}
Else if (dvd.name[i].equals (name) &&dvd.state[i]==true) {
System.out.println ("Sorry" +name+ " Already lent ");
break;

}
}
System.out.println ("------------------------------------------------------------------------- -----------------");
Returnmain ();
}
//gh

public void gh () {
System.out.println ("return DVD");
System.out.println ("Please enter the DVD name");
String Name=input.next ();
Long loan=0;//rent
for (int i=0;i<dvd.name.length;i++) {
if (dvd.name[i]==null) {
System.out.println (" No matching information found ");
break;
}
Else if (dvd.name[i].equals (name) &&dvd.state[i]==true) {
System.out.println ("Please enter return date (year-month-day)") ;
String Redate=input.next ();
Loan=charge (dvd.date[i],redate);
System.out.println ("Return" +name+ "success");
Dvd.state[i]=false;
System.out.println ("Loan date is" +dvd.date[i]);
System.out.println ("Return date is" +redate);
System.out.println ("Rent payable (Yuan):" +loan);
break;
}
Else if (dvd.name[i].equals (name) &&dvd.state[i]==false) {
System.out.println ("+name+" is not loaned , please verify ");
break;
}
}
System.out.println ("----------------------------------------------------------------------------- -------------");
Returnmain ();
}
/*
* Billing class
*/

Public long Charge (String dstr1,string dstr2) {
Long charge=0;
SimpleDateFormat sd=new SimpleDateFormat ("Yyyy-mm-dd");
try{
Date D1=sd.parse (DSTR1);
Date D2=sd.parse (DSTR2);
Charge= (D2.gettime ()-d1.gettime ())/(24*30*30*1000);
}catch (ParseException e) {
E.printstacktrace ();
}
return charge;
}

}

Third class//test

Package DVD;

public class Test {

/**
* @param args
*/
public static void Main (string[] args) {
TODO auto-generated Method Stub
Dvdmgr test=new dvdmgr ();
Test.initial ();
Test.startmenu ();
}

}

Mini DVD Manager

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.