精华内容
下载资源
问答
  • 迷你DVD管理器

    2014-03-18 23:25:42
    迷你DVD管理器源代码,压缩文档,测试通过,无bug
  • 迷你 DVD管理器

    2017-02-07 08:55:04
    为音像店开发一个迷你 DVD管理器,实现DVD碟片的管理,包括如下功能:  新增 DVD  查看 DVD  删除 DVD  借出 DVD  归还 DVD 代码: import java.util.Scanner; import java.text.Parse...

    为音像店开发一个迷你 DVD管理器,实现DVD碟片的管理,包括如下功能: 

    新增 DVD 

    查看 DVD 

    删除 DVD 

    借出 DVD 

    归还 DVD


    代码:

    import java.util.Scanner;
    import java.text.ParseException;
    import java.text.SimpleDateFormat;
    import java.util.Date;
    
    
    public class DVDMgr {
    	int num1,i;
    	DVD dvds = new DVD();
    	
    	Scanner input = new Scanner(System.in);
    	
    	public void inital(){
    		dvds.name[0] = "罗马假日";
    		dvds.state[0] = "0";
    		dvds.date[0] = "2013-7-1";
    		
    		dvds.name[1] = "风声鹤唳";
    		dvds.state[1] = "1";
    
    		dvds.name[2] = "浪漫满屋";
    		dvds.state[2] = "1";
    
    		
    	}
    	
    	/*
    	 * 新增DVD
    	 */
    	public void add(){
    		System.out.println("---> 新增DVD");
    		System.out.println("请输入DVD名称:");
    		String name = input.next();
    		for(int i= 0;i 查看DVD\n");
    		System.out.println("序号\t\t状态\t\t名称\t\t\t借出日期");
    		for(int i=0;i 删除DVD\n");
    		System.out.println("请输入DVD名称:");
    		String name = input.next();
    		
    		for(int i = 0;i 借出DVD\n");
    		System.out.println("请输入DVD名称:");
    		String name = input.next();
    		
    		
    		for(int i = 0;i 归还DVD\n");
    		System.out.println("请输入DVD名称:");
    		String name = input.next();
    		
    		int price = 0;
    		for(int i = 0;i


    测试类:
    public class DVD {
    	String[] name = new String[100];
    	String[] state = new String[100];
    	String[] date = new String[100];
    	String[] date2 = new String[100];
    	
    	public static void main(String[] args) {
    		DVDMgr list = new DVDMgr();
    		list.inital();
    		list.show();
    	}
    }

    展开全文
  • [迷你DVD管理器java] 迷你dvd管理器代码 实 验 报 告 课程名称面向对象信息系统开发 实 验期中大作业 班 级02 学生姓名李康 序 号34 学 号20XX1060261 专 业电子信息工程 指导教师高莲 学 期20XX-2020学年春季学期 ...
  • 迷你DVD管理器.7z

    2019-06-14 21:51:04
    北大青鸟 ACCP8.0《java实现数据库编程》试卷 使用 IntelliJ IDEA 实现-迷你DVD管理器
  • 迷你 DVD 管理器

    2016-11-20 21:50:38
    import java.text.*; import java.util.*; class MiniDvd { public static void main(String[] args) { DVDMgr a = new DVDMgr(); a.inital(); a.startMenu(); } ... //声明DVD名,属性等
    0import java.text.*;
    import java.util.*;
    class  MiniDvd
    {
    	public static void main(String[] args) 
    	{
    		DVDMgr a = new DVDMgr();
    		a.inital();
            a.startMenu();
    	}
    }
    
    class DVDSet 
    {
    	//声明DVD名,属性等状态
    	String[] name = new String[99];		//定义DVD数组
    	boolean[] state = new boolean[99];	//定义DVD借出的状态:true借出;false可借
    	String[] date = new String[99];		//定义借出日期
    	int[] count = new int[99];			//定义借出次数
    }
    
    
     class DVDMgr 
    {
    	Scanner input = new Scanner(System.in);
    	DVDSet dvd = new DVDSet();	//初始化对象
    	boolean islend = false;		//已借出是true,可借是false
    
    	//初始化三张DVD信息
    	public void inital(){
    		dvd.name[0] = "罗马假日";
    		dvd.state[0] = true;	//已借出
    		dvd.date[0] = "2013-7-1";
    		dvd.name[1] = "风声鹤唳";
    		dvd.state[1] = false;	//可借
    		dvd.name[2] = "浪漫满屋";
    		dvd.state[2] = false;	//可借
    	}
    
    	public void startMenu(){
    		System.out.println("欢迎使用迷你DVD管理器");
    		System.out.println("---------------------");
    		System.out.println("0.查看DVD排行版");
    		System.out.println("1.新增DVD");
    		System.out.println("2.查看DVD");
    		System.out.println("3.删除DVD");
    		System.out.println("4.借出DVD");
    		System.out.println("5.归还DVD");
    		System.out.println("6.退出");
    		System.out.println("---------------------");
    		System.out.println("请选择");
    		int choice = input.nextInt();	//定义要选择的菜单
    		switch (choice)
    		{
    		case 0:
    			list();		//查看DVD排行版
    			break;
    		case 1:
    			add();		//新增DVD
    			break;
    		case 2:
    			search();	//查看DVD	
    			break;
    		case 3:
    			delete();	// 删除DVD
                break;
    		case 4:
    			lend();		// 借出DVD
                break;
    		case 5:
    			returnDvd(); // 归还DVD
                break;
    		case 6:
    			System.out.println("谢谢使用!");
                break;
    		default:
    			System.out.println("对不起,你的输入有误,请重新输入!");
    		}
    	}
    
    	public void returnMain(){
    		for (; ; )
    		{
    		System.out.println("输入0返回:");
    		if (input.nextInt() == 0 )
    		{
    			startMenu();
    		}else{
    			 System.out.println("输入错误!");
    		}
    		}
    	}
    
    	public void list(){
    		String[] newname = new String[99];	//定义新数组 显示DVD名称
    		int[] newcount = new int[99];		//定义新数组 显示借出次数
    		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++ )		//2层循环控制位置
    		{
    			for (int j = i + 1; j < newname.length; j++ )
    			{
    				if (newcount[i] > newcount[j])
    				{
    					int temp = newcount[i];	//2次交换实现次数和名字的替换
    					newcount[i] = newcount[j];
    					newcount[j] = temp;
    					String temp1 = newname[i];
    					newname[i] = newname[j];
    					newname[j] = temp1;
    				}
    			}
    		}
    		System.out.println("次数\t名称");
    
    		for (int i = dvd.name.length - 1; i >= 0; i--) {
    			if (newname[i] != null) {
    				System.out.println(newcount[i] + "次" + "\t" + newname[i]);
    			}
    		}
    		System.out.println("----------------------------");
    		returnMain();
    	}
    	
    	//新增DVD
    	public void add(){
    		System.out.println("--->新增DVD\n");
            System.out.print("请输入DVD的名称:");
    		String name = input.next();
    		for (int i = 0 ; i < dvd.name.length ; i++ )
    		{
    			if (dvd.name[i] == null)	//判断位置是否为空
    			{
    				dvd.name[i] = name;
    				dvd.state[i] = false;
    				System.out.println("新增《" + name + "》");
    				break;
    			}
    		}
    		System.out.println("----------------------------");
    		 returnMain();
    	}
    
    	//查看DVD
    	public void search(){
    		System.out.println("--->查看DVD\n");
    		System.out.println("序号\t状态\t名称\t\t借出日期");
    		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已借出\t《" + dvd.name[i] + "》\t" + dvd.date[i]);
    			}else if (dvd.state[i] == false)
    			{
    				System.out.println((i + 1) + "\t可  借\t《" + dvd.name[i] + "》");
    			}
    		}
    		System.out.println("----------------------------");
    		returnMain();
    	}
    
    	//删除DVD
    	public void delete(){
    		System.out.println("--->删除DVD\n");
            System.out.print("请输入DVD的名称:");
    		String name = input.next();
    		boolean flag = false;
    		for (int i = 0 ;i < dvd.name.length ; i++ )
    		{
    			if (dvd.name[i] != null && dvd.name[i].equalsIgnoreCase(name)
                    && dvd.state[i] == false)
    			{
    				int j = i ;
    				while (dvd.name[j] != null)
    				{
    					dvd.name[j] = dvd.name[j + 1]; // 删除元素,元素前移
    					dvd.state[j] = dvd.state[j + 1];
    					dvd.date[j] = dvd.date[j + 1];
    					 j++;
    				}
    				//最后一个不为空的元素置空
    				dvd.name[j] = null;
    				dvd.date[j] = null;
    				System.out.println("删除《" + name + " 》成功!");
    				flag = true;	//标识位
    				break;
    			}else if (dvd.name[i] != null
                          && dvd.name[i].equalsIgnoreCase(name)
                          && dvd.state[i] == true)
    			{
    				System.out.println("《" + name + "》为借出状态,不能删除!");
    				flag = true;
    				break;
    			}
    			if (flag)
    			{
    				System.out.println("没有找到匹配信息");
    			}
    		}
    		System.out.println("----------------------------");
    		returnMain();
    	}
    
    	//借出DVD
    	public void lend(){
    		System.out.println("--->借出DVD\n");
    		System.out.print("请输入DVD的名称:");
    		String name = input.next();
    		for (int i = 0 ; i < dvd.name.length ; i++ )
    		{
    			if (dvd.name == null)
    			{
    				System.out.println("没有找到匹配信息");
    				break;
    			}else if (dvd.name[i].equals(name) && dvd.state[i] == false)
    			{
    				System.out.println("请输入借出日期(年-月-日):");
    				dvd.date[i] = input.next();
    				System.out.println("《" + name + "》借出成功");
    				dvd.state[i] = true;
    				dvd.count[i]++;
    				break;
    			}else if (dvd.name[i].equals(name) && dvd.state[i] == true)
    			{
    				System.out.println("不好意思,《" + name + "》已被借出!");
    				break;
    			}
    		}
    		System.out.println("----------------------------");
    		returnMain();
    	}
    
    	//归还DVD
    	public void returnDvd(){
    		System.out.println("--->归还DVD\n");
            System.out.print("请输入DVD名称:");
            String name = input.next();
            long loan = 0; // 租用天数
            for (int i = 0; i < dvd.name.length; i++) 
    		{
    			if (dvd.name[i] == null) 
    			{
    				System.out.println("没有找到匹配信息!");
    				break;
    			}else if (dvd.name[i].equals(name) && dvd.state[i] == true) 
    			{
    				System.out.print("请输入归还日期(年-月-日):");
    				String redate = input.next();
    				loan = charge(dvd.date[i], redate);
    				System.out.println("\n《" + name + "》归还成功");
    				dvd.state[i] = false;
    				System.out.println("借出日期为:" + dvd.date[i]);
                    System.out.println("归还日期为:" + redate);
                    System.out.println("租用天数:" + loan);
    				break;
    			}else if (dvd.name[i].equals(name) && dvd.state[i] == false) {
    				System.out.println("《" + name + "》没有被借出,无法进行归还操作!");
    				break;
    			}
    		}
    		System.out.println("----------------------------");
    		returnMain();
    	}
    
    	// 计算日期差
    	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 * 60 * 60 * 1000);
            }catch (ParseException e) {                        
    			e.printStackTrace();
    		}
    		return charge; 
    	}
    
          
    }
    
    
    
    


    展开全文
  • 迷你dvd管理器

    2016-07-14 15:59:00
    1.DvdDao import java.sql.Connection;import java.sql.DriverManager;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;...

    1.DvdDao

    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;

    import javax.naming.spi.DirStateFactory.Result;

    import com.minidvd.entity.DvdEntity;

    public class DvdDao {

    final static String URL = "jdbc:sqlserver://localhost:1433;DatabaseName=minidvd";
    final static String USER = "sa";
    final static String PASSWORD = "123";
    final static String SQLSERVER_CLASS_NAME = "sun.jdbc.odbc.JdbcOdbcDriver";
    private Connection conn;
    private Statement state;
    private ResultSet resultSet;

    public DvdDao() {
    try {
    Class.forName(SQLSERVER_CLASS_NAME);
    } catch (ClassNotFoundException e) {
    System.out.println("没加载sqlserver的jar包");
    }
    try {
    conn = DriverManager.getConnection(URL, USER, PASSWORD);
    } catch (SQLException e) {
    System.out.println("数据库连接失败");
    }
    try {
    state = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
    ResultSet.CONCUR_READ_ONLY);
    } catch (SQLException e) {
    e.printStackTrace();
    }

    }

    public int add(String addsql) {
    int rows = 0;
    try {
    rows = state.executeUpdate(addsql);
    } catch (SQLException e) {
    System.out.println("异常错误,添加失败");
    }
    return rows;
    }

    public int update(String updatesql) {
    int rows = 0;
    try {
    rows = state.executeUpdate(updatesql);
    } catch (SQLException e) {
    System.out.println("异常错误,更新失败");
    }
    return rows;
    }

    public int delete(String deletesql) {
    int rows = 0;
    try {
    rows = state.executeUpdate(deletesql);
    } catch (SQLException e) {
    System.out.println("异常错误,删除失败");
    }
    return rows;

    }

    public ResultSet find(String findsql) {
    resultSet = null;
    try {
    resultSet = state.executeQuery(findsql);
    } catch (SQLException e) {
    System.out.println("异常出错,查询失败");
    }
    return resultSet;
    }

    public void close() {
    try {
    if (resultSet != null)
    resultSet.close();
    } catch (SQLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } finally {
    try {
    if (state != null)
    state.close();
    } catch (SQLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } finally {

    try {
    if (conn != null)
    conn.close();
    } catch (SQLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }

    }
    }
    }

    }

    2.DvdEntity

    package com.minidvd.entity;


    public class DvdEntity {

    private int id;
    private String name;
    private int state;
    private String date;
    private int count;
    /**
    * 取得 name
    * @return the name
    */
    public DvdEntity(){

    }
    public DvdEntity(int id,String name, int state,String date,int count){
    this.id=id;
    this.name=name;
    this.state=state;
    this.date=date;
    this.count=count;
    }

    /**
    * 取得 id
    * @return the id
    */
    public int getId() {
    return id;
    }
    /**
    *设置 id
    * @param id the id to set
    */
    public void setId(int id) {
    this.id = id;
    }
    /**
    * 获得名字
    * @return name
    */
    public String getName() {
    return name;
    }
    /**
    *设置 name
    * @param name the name to set
    */
    public void setName(String name) {
    this.name = name;
    }
    /**
    * 取得 state
    * @return the state
    */
    public int getState() {
    return state;
    }
    /**
    *设置 state
    * @param state the state to set
    */
    public void setState(int state) {
    this.state = state;
    }
    /**
    * 取得 date
    * @return the date
    */
    public String getDate() {
    return date;
    }
    /**
    *设置 date
    * @param date the date to set
    */
    public void setDate(String date) {
    this.date = date;
    }
    /**
    * 取得 count
    * @return the count
    */
    public int getCount() {
    return count;
    }
    /**
    *设置 count
    * @param count the count to set
    */
    public void setCount(int count) {
    this.count = count;
    }


    }

     3.DvdManage

    package com.minidvd.manage;

    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.text.ParseException;
    import java.text.SimpleDateFormat;
    import java.util.Arrays;
    import java.util.Date;
    import java.util.Scanner;

    import com.minidvd.data.DvdDao;
    import com.minidvd.entity.DvdEntity;

    public class DvdManage {
    public DvdEntity[] rankingList() throws SQLException{

    DvdEntity[] de=bublleSort(dvdlist());
    return de ;
    }
    public int addDvd(DvdEntity dvdEntity){
    DvdDao d = new DvdDao();
    String name=dvdEntity.getName();
    String addsql="insert dvdlist (name) values('"+name+"')";
    System.out.println(addsql);
    int sc=d.add(addsql)==1?1:0;
    d.close();
    return sc;
    }
    public DvdEntity[] dvdlist() throws SQLException{
    DvdDao d = new DvdDao();
    String findsql="select * from dvdlist";
    ResultSet rs=d.find(findsql);
    int index=getResultRows(rs);
    DvdEntity[] de=new DvdEntity[index];
    rs.beforeFirst();
    int count=0;
    while(rs.next()){
    DvdEntity Entity = new DvdEntity();
    Entity.setId(rs.getInt("id"));
    Entity.setCount(rs.getInt("count"));
    Entity.setDate(rs.getString("date"));
    Entity.setState(rs.getInt("state")==1?1:0);
    Entity.setName(rs.getString("name"));
    de[count]=Entity;
    count++;

    }
    d.close();
    return de;

    }
    public int delDvd(DvdEntity dvdEntity) throws SQLException{
    DvdDao d = new DvdDao();
    String name=dvdEntity.getName();
    String findsql="select state, name from dvdlist where name='"+name+"'";
    ResultSet a=d.find(findsql);
    int state=0;
    String name1=null;
    a.beforeFirst();
    while(a.next()){
    state=a.getInt("state");
    name1=a.getString("name");
    }

    String delsql="delete dvdlist where name='"+name+"'";
    if(!name.equals(name1)){
    return 0;
    }else if (state==1){
    return 1;
    }else{
    d.delete(delsql);
    d.close();
    return 2;
    }
    }
    public int borrowDvd(DvdEntity dvdEntity) throws SQLException{
    DvdDao d = new DvdDao();
    String name=dvdEntity.getName();
    String date=dvdEntity.getDate();
    int count=0;
    String findsql="select name, state, count from dvdlist where name='"+name+"'";
    ResultSet a=d.find(findsql);
    String name1=null;
    int state=0;
    int g=0;
    while(a.next()){
    name1=a.getString("name");
    state=a.getInt("state");
    count=a.getInt("count");
    }
    if(!name.equals(name1)){
    return 0;
    }else if( state==1){
    return 1;
    }else{
    count++;
    String update ="update dvdlist set state="+1+",date='"+date+"',count="+count+++" where name='"+name+"'";
    d.update(update);
    d.close();
    return 2;
    }

    }
    public String[] returnDvd(DvdEntity dvdEntity) throws SQLException{
    DvdDao d =new DvdDao();
    String name=dvdEntity.getName();
    String findsql ="select name, state ,date from dvdlist where name='"+name+"'";
    String date1=dvdEntity.getDate();
    String date=null;
    String name1=null;
    int state=0;
    ResultSet a=d.find(findsql);
    String[] s =new String[4];
    int index;
    long money=0;
    while(a.next()){
    date = a.getString("date");
    name1=a.getString("name");
    state=a.getInt("state");
    }
    if(date==null &&date1==null){
    index=0;
    }else if(!name.equals(name1)){
    index=1;
    }else if(state==0){
    index=2;
    }else{
    String update="update dvdlist set state="+0+",date="+null;
    d.update(update);
    index=3;
    money=0;
    money=charge(date,date1);
    }
    s[0]=date;
    s[1]=date1;
    s[2]=money+"";
    s[3]=String.valueOf(index);
    d.close();
    return s;



    }
    private DvdEntity[] bublleSort(DvdEntity[] dvdEntity) throws SQLException{
    for(int x=0;x<dvdEntity.length-1;x++){
    for(int y=0;y<dvdEntity.length-x-1;y++){
    if(dvdEntity[y].getCount()<dvdEntity[y+1].getCount()){


    String temp=dvdEntity[y].getName();
    dvdEntity[y].setName(dvdEntity[y+1].getName());
    dvdEntity[y+1].setName(temp);

    int a=dvdEntity[y].getCount();
    dvdEntity[y].setCount((dvdEntity[y+1].getCount()));
    dvdEntity[y+1].setCount(a);
    }
    }
    }
    return dvdEntity;
    }
    private int getResultRows(ResultSet resultSet) throws SQLException{
    int rows=0;
    while(resultSet.next()){
    rows++;
    }
    return rows;

    }
    private long charge(String dstr1 ,String dstr2){
    SimpleDateFormat sd=new SimpleDateFormat("yyyy-MM-dd");
    Date d1=null;
    Date d2=null;
    try {
    d1 = sd.parse(dstr1);
    d2 = sd.parse(dstr2);
    } catch (ParseException e) {
    // TODO Auto-generated catch block
    System.out.println("格式书写错误");

    }
    long charge;
    charge=(d2.getTime()-d1.getTime())/(24*60*60*1000);
    return charge;

    }
    }

    4.Main

    package com.minidvd.start;

    import java.sql.SQLException;
    import java.text.ParseException;
    import java.util.Scanner;

    import com.minidvd.data.DvdDao;
    import com.minidvd.entity.DvdEntity;
    import com.minidvd.manage.DvdManage;

    public class Main {


    public static void main(String[] args) throws SQLException {
    startMenu();
    }

    public static void startMenu() throws SQLException{
    Scanner in = new Scanner(System.in);

    do {

    System.out.println("欢迎使用迷你DVD管理器");
    System.out.println(" ");
    System.out.println(" 0.借出排行榜 ");
    System.out.println(" 1.新增DVD ");
    System.out.println(" 2.查看DVD ");
    System.out.println(" 3.删除DVD ");
    System.out.println(" 4.借出DVD ");
    System.out.println(" 5.归还DVD ");
    System.out.println(" 6.退 出 ");
    System.out.println(" ");
    System.out.print("请选择:");
    String num = in.next();
    switch (num) {
    case "0":
    System.out.println("---->排行榜\n\n");
    System.out.println("**************************");
    ranking();
    break;
    case "1":
    System.out.println("---->新增DvD");
    System.out.print("请输入DvD的名称:");
    addNewDvd();
    break;
    case "2":
    System.out.println("------>查看DvD\n");
    System.out.println("序号\t状态\t名称\t借出日期");
    showDvdlist();
    break;
    case "3":
    System.out.print("---->删除DVD");
    System.out.print("请输入DVD名称:");
    deleteDvd();
    break;
    case "4":
    System.out.println("---->借出DVD\n");
    System.out.print("请输入DVD的名称:");
    borrowDvd();
    break;
    case "5":
    System.out.println("--->归还\n");
    System.out.print("请输入DvD的名称:");
    returnDvd();
    break;
    case "6":
    System.out.println("谢谢使用");
    returnStartMenu();
    return;
    default:
    System.out.println("请输入正确的数字");

    }
    System.out.println("************");
    System.out.print("输入零返回:");
    num = in.next();
    if (!num.equals("0")) {
    System.out.println("输入错误,异常终止");
    return;
    }
    } while (true);

     

    }

    public static void ranking(){
    Scanner in = new Scanner(System.in);
    DvdEntity[] dvdEntity;
    DvdManage dm =new DvdManage();
    try {
    dvdEntity =dm.rankingList();
    System.out.println("书名"+"\t"+"借出的次数");
    for(int i=0;i<dvdEntity.length;i++){

    System.out.println(dvdEntity[i].getName()+"\t "+dvdEntity[i].getCount());
    }
    } catch (SQLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    }
    public static void addNewDvd(){
    Scanner in = new Scanner(System.in);

    DvdManage dm =new DvdManage();
    DvdEntity dvdentity = new DvdEntity();
    String name=in.next();
    dvdentity.setName(name);
    int a=dm.addDvd(dvdentity);
    if(a==1){
    System.out.println("添加成功");
    }else{
    System.out.println("添加失败,不能添加重名dvd");
    }
    }
    public static void showDvdlist() throws SQLException{
    Scanner in = new Scanner(System.in);
    DvdManage dm = new DvdManage();
    DvdEntity[] dvdEntity;
    dvdEntity=dm.dvdlist();
    for(int i=0;i<dvdEntity.length;i++){
    String state=dvdEntity[i].getState()==1?"不可借":"可借";
    System.out.println(dvdEntity[i].getId()+"\t"+state+"\t"+dvdEntity[i].getName()+"\t"+dvdEntity[i].getDate());

    }
    }
    public static void deleteDvd() throws SQLException{
    Scanner in = new Scanner(System.in);
    DvdManage dm =new DvdManage();
    DvdEntity dvdentity = new DvdEntity();
    String name=in.next();
    dvdentity.setName(name);
    int a=dm.delDvd(dvdentity);
    if(a==0){
    System.out.println("没找到该dvd");
    }else if(a==1){
    System.out.println("为借出状态,不能删除");
    }else{
    System.out.println("删除成功");
    }
    }
    public static void borrowDvd() throws SQLException{
    Scanner in = new Scanner(System.in);
    DvdManage dm =new DvdManage();
    DvdEntity dvdentity = new DvdEntity();
    String name=in.next();
    dvdentity.setName(name);
    System.out.print("请输入借出的日期(年-月-日):");
    String date =in.next();
    dvdentity.setDate(date);
    int a=dm.borrowDvd(dvdentity);
    if(a==2){
    System.out.println("借出成功");
    }else if(a==0){
    System.out.println("没找到该dvd");
    }else{
    System.out.println("为借出状态,不能借出");
    }
    }
    public static void returnDvd() throws SQLException{
    Scanner in = new Scanner(System.in);
    DvdManage dm =new DvdManage();
    DvdEntity dvdentity = new DvdEntity();
    String name=in.next();
    System.out.print("请输入归还的日期(年-月-日):");
    String date=in.next();
    dvdentity.setName(name);
    dvdentity.setDate(date);
    String [] d=dm.returnDvd(dvdentity);

    int a= Integer.parseInt(d[3]);

    if(a==0){
    System.out.println("归还日期格式错误");
    }else if(a==1){
    System.out.println("找不到对应的dvd");
    }else if(a==2){
    System.out.println("借出状态,为未借出状,归还失败");
    }else{
    System.out.println("借出日期\t\t归还日期\t 需要支付:");
    for(int i=0; i<d.length-1;i++){
    System.out.print(d[i]+"\t");
    if(i==d.length-2){
    System.out.println();
    System.out.println("");
    }

    }
    }

    }
    public static void returnStartMenu(){
    System.exit(0);
    }

    }

    转载于:https://www.cnblogs.com/qi1250/p/5670723.html

    展开全文
  • ACCP 迷你DVD管理器

    2013-07-26 21:52:51
    ACCP6.0 S1 迷你DVD管理器
  • 迷你DVD管理器源码

    2011-11-02 23:41:49
    学校要求写个迷你DVD管理器 呵呵把源码给大家分享
  • 为青鸟音像店开发一个迷你DVD管理器,实现DVD碟片的管理,包括如下功能: 新增DVD 查看DVD 删除DVD 借出DVD 归还DVD 以上是这款游戏的功能,非常好用的代码,值得拥有,放心下载吧
  • 开发迷你DVD管理器(MiniDVD Mgr 1.0) 实现:1 查询DVD信息 2 管理DVD借出 3 添加DVD信息
  • JAVA之迷你DVD管理器

    千次阅读 2017-01-23 11:11:31
    JAVA之迷你DVD管理器
    1、JAVA之迷你DVD管理器。
    1>打开记事本,写如下一段代码:
    import java.text.ParseException;
    import java.text.SimpleDateFormat;
    import java.util.*;
    public class DVDMgr {
        /**
        * 创建DVD对象
        */
        DVDSet dvd = new DVDSet();
        /**
        * 初始三个DVD 
        */
        public void initial() {
        
            dvd.name[0] = "少年奇幻漂流记";
            dvd.state[0] = 0; 
            dvd.date[0]="2013-2-15";
            dvd.count[0]=15;
            
            dvd.name[1] = "兵临城下";
            dvd.state[1] = 1;  
            dvd.count[1]=12;
            
            dvd.name[2] = "人在囧途";
            dvd.state[2] = 1;
            dvd.count[2]=30;
        }
        
        /**
        * 开始菜单
        */
        public void startMenu(){
        System.out.println("欢 迎 使 用 迷 你 DVD 管 理 器");
           System.out.println("-------------------------------------");
           System.out.println("0. 借出排行榜");
           System.out.println("1. 新 增 DVD");
           System.out.println("2. 查 看 DVD");
           System.out.println("3. 删 除 DVD");
           System.out.println("4. 借 出 DVD");
            System.out.println("5. 归 还 DVD");     
           System.out.println("6. 退         出 ");
           
           System.out.print("--------------------------------------\n");
           System.out.print("请选择: ");
           Scanner input = new Scanner(System.in);
           int choice = input.nextInt();
               switch(choice){
                   case 0:
                      list();
                      break;
                   case 1:
                      add();
                      break;
                      case 2: 
                      search();
                      break;
                      case 3:
                      delete();
                      break;
                      case 4:
                      lend();
                      break;
                      case 5:
                      returnDvd();
                      break;
                      case 6:
                      System.out.println("\n谢谢 使 用!");
                      break;
               }
        }
        
        /**
         * 返回主菜单
         */
        public void returnMain(){
            Scanner input = new Scanner(System.in); 
            System.out.print("输入0返回:");
            if(input.nextInt() == 0){
                startMenu();
            }else{
                System.out.println("输入错误, 异常终止!");
            }
        }
        /**
         * 查看DVD
         */
        public void search(){
            System.out.println("---> 查看DVD\n");
            System.out.println("序号\t状 态\t名称\t\t借出日期");
            for(int i = 0 ; i < dvd.name.length; i++){
               if(dvd.name[i]==null){
                    break;
               }else if(dvd.state[i] == 0){
                    System.out.println((i+1)+"\t已借出\t"+"<<"+ dvd.name[i]+ ">>\t" + dvd.date[i]);
               }else if(dvd.state[i] == 1){
                    System.out.println((i+1)+"\t可 借\t"+"<<"+dvd.name[i]+">>");
               }
            }
            System.out.println("**************************");
            returnMain();  
        }
        
        /**
         * 新增DVD
         */
        public void add(){
            Scanner input = new Scanner(System.in);
            System.out.println("---> 新增DVD\n");    
            System.out.print("请输入DVD名称: ");
            String name = input.next();  
            for(int i = 0; i < dvd.name.length; i++){    
                if(dvd.name[i] == null){    //查询最后一个空位置插入
                    dvd.name[i]=name;
                    dvd.state[i]=1;//置新增的DVD可借状态
                    System.out.println("新增《"+name+"》成功!");
                    break;
                }
            }
            System.out.println("**************************");
            returnMain();   
        } 
           
        /**
         * 删除DVD
         */
        public void delete(){
            Scanner input = new Scanner(System.in);
            boolean flag=false;//标识删除成功与否
            System.out.println("---> 删除DVD\n");
            System.out.print("请输入DVD名称: ");
            String name = input.next();  
            //遍历数组,查找匹配信息
            for(int i = 0 ; i < dvd.name.length; i++){
                //查找到,每个元素前移一位
                if(dvd.name[i]!=null &&dvd.name[i].equalsIgnoreCase(name)&&dvd.state[i]==1){
                    int j=i;
                    while(dvd.name[j+1]!=null){
                    dvd.name[j]=dvd.name[j+1];
                    dvd.state[j]=dvd.state[j+1];
                    dvd.date[j]=dvd.date[j+1];
                    j++;
                    }
                    //最后一个不为空的元素置空
                    dvd.name[j]=null;  
                    dvd.date[j]=null; 
                    System.out.println("删除《"+name+"》成功!");
                    flag=true;//置位,表示删除成功
                    break;
                }else if(dvd.name[i]!=null &&dvd.name[i].equalsIgnoreCase(name)&&dvd.state[i]==0){
                    System.out.println("《"+name+"》为借出状态,不能删除!"); 
                    flag=true;//置位
                    break;
                }
            }
            if(!flag){
                System.out.println("没有找到匹配信息!");
            }
            System.out.println("**************************");
            returnMain();  
        }
        /**
         * 借出DVD
         */
        public void lend(){
            System.out.println("---> 借出DVD\n"); 
            Scanner input = new Scanner(System.in);
            System.out.print("请输入DVD名称: ");
            String want = input.next();  //要借出的DVD名称 
            for(int i = 0; i < dvd.name.length; i++){    
                if(dvd.name[i] == null){    //无匹配
                    System.out.println("没有找到匹配信息!");
                    break;
                }else if(dvd.name[i].equals(want)&& dvd.state[i]==1){  //找到匹配可借 
                    dvd.state[i] = 0;
                    System.out.print("请输入借出日期(年-月-日):");
                    dvd.date[i]=input.next();
                    System.out.println("借出《"+want+"》成功!");  
                    dvd.count[i]++;
                    break;
                }else if(dvd.name[i].equals(want)&& dvd.state[i]==0){  //找到匹配已被借出
                    System.out.println("《"+want+"》已被借出!");
                    break;
                }    
            }
            System.out.println("**************************");
            returnMain();
        }
        
        /**
         * 归还DVD并计算租金
         */
        public void returnDvd(){
            System.out.println("---> 归还DVD\n");
            Scanner input = new Scanner(System.in);
            long loan=0;//租金
            System.out.print("请输入DVD名称: ");
            String want = input.next();
            for(int i = 0; i < dvd.name.length; i++){    
                if(dvd.name[i] == null){    //无匹配
                    System.out.println("没有找到匹配信息!");
                    break;
                }else if(dvd.name[i].equals(want) && dvd.state[i]==0){  //找到匹配 
                    dvd.state[i] = 1;
                    System.out.print("请输入归还日期(年-月-日):");
                    String redate=input.next();
                    //计算租金
                    loan=charge(dvd.date[i],redate);
                    System.out.println("\n归还《"+want+"》成功!");
                    System.out.println("借出日期为:"+dvd.date[i]);
                    System.out.println("归还日期为:"+redate);
                    System.out.println("应付租金(元):"+loan);
                    break;
                }else if(dvd.name[i].equals(want) && dvd.state[i]==1){ //找到匹配但没有借出
                    System.out.println("该DVD没有被借出!无法进行归还操作。");
                    break;
                }
            }
            System.out.println("**************************");
            returnMain();
        }
        
        /**
         * 计算日期差
         * @param dstr1 第一个日期
         * @param dstr2 第二个日期
         * 
         */
        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*60*60*1000);
            } catch (ParseException e) {
                e.printStackTrace();
            }    
            return charge;
        }
        /**
         * 借出排行榜
         */
        public void list(){
            //定义新数组,用来存放排序后DVD信息
            String[] newname = new String[50];        
            int[] newcount=new int[50];  
            for(int k=0;k<dvd.name .length;k++){
                newname[k]=dvd.name[k];
                newcount[k]=dvd.count[k];
            }
             
            //利用冒泡排序算法进行排序
            for(int i=0;i<newname.length;i++){
                for(int j=i+1;j<newname.length;j++){
                    if(newcount[i]>newcount[j]){
                        int tempc=newcount[i];
                        newcount[i]=newcount[j];
                        newcount[j]=tempc;
                        String tempn=newname[i];
                        newname[i]=newname[j];
                        newname[j]=tempn;
                    }    
                }    
            }
            System.out.println("---> 排行榜\n");
            System.out.println("**************************");
            System.out.println("次数\t名称");
            //显示排行榜信息
            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();
        }
    }
    保存为DVDMgr.java【同上节,我还是把他放在了D盘下InputTest文件夹内】 

    2>打开记事本,写如下一段代码:

    public class DVDSet {
        String[] name = new String[50];   //数组1存储DVD名称数组
        int[] state = new int[50];        //数组2存储DVD借出状态:0已借出/1可借
        String[] date=new String[50];     //数组3存储DVD借出日期
        int[] count=new int[50];         //借出次数
    }
    保存为DVDSet.java【同上节,我还是把他放在了D盘下InputTest文件夹内】   3>打开记事本,写如下一段代码: 
    public class Start {
        /**
        * @param args
        */
        public static void main(String[] args) {
            DVDMgr dm=new DVDMgr();
            dm.initial();
            dm.startMenu();
        }
    }
    保存为Start.java【同上节,我还是把他放在了D盘下InputTest文件夹内】 
    打开dos运行窗口,输入d:转到D盘,接下来输入cd InputTest转到InputTest目录下:
    输入Javac Start.java 回车 java Start。

    我们依次选择0,1,2,3,4,5,6;结果如下图: 






    展开全文
  • 完整版:迷你DVD管理器

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 1,017
精华内容 406
关键字:

迷你dvd管理器