标题:日期和状态
只看楼主
博哥
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2016-11-8
结帖率:0
已结贴  问题点数:20 回复次数:6 
日期和状态

package DVD;
import java.text.SimpleDateFormat;
import java.util.*;


public class Dvd {


    private int xuhao;
    private String name;
    private Date date;
    private int state;
    private int zj;
    public Dvd(int xuhao, String name) {
        this.xuhao = xuhao;
        this.name = name;
        this.date = date;
        this.state=state;
        this.zj=zj;
   
    }



    public int getNum() {
        return xuhao;
    }
    public void setNum(int num) {
        this.xuhao = xuhao;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
   
    public Date getBirthday() {
        return date;
    }
   
    public void getState(){
        this.state=state;
    }
    public void getzj(){
        this.zj=zj;
    }
    public int getAge() {
        Calendar c = Calendar.getInstance();
        int year = c.get(Calendar.YEAR);
        c.setTime(date);        
        return year - c.get(Calendar.YEAR);
    }
    @Override
    public String toString() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        return String.format("序号:%d,状态:%d名称:%s,借出日期:%s",
                this.xuhao,this.state,this.name,this.date);
    }
}

package DVD;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

public class Dvd2 {


     String dstr1 =null;
    String dstr2 =null;
    Scanner sc =new Scanner(System.in);
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    Dvd[] emps = new Dvd[100];
    int empCount=0;
    public Dvd2() throws ParseException{
        emps[0] = new Dvd(1,"哪吒传奇");
        emps[1] = new Dvd(2,"黑猫警长");
        emps[5] = new Dvd(3,"猫和老鼠");
        empCount =3;
    }
    public void printAll(){
        for (Dvd e : emps) {
            if(e!=null)
                System.out.println(e);
        }
    }   
   
    int getEmptyIndex(){
        for (int i = 0; i < emps.length; i++) {
            if(emps[i]==null)
                return i;
        }
        return -1;
    }
    public void add() throws ParseException{        
        int i = getEmptyIndex();
        System.out.println("请输入新增DVD序号:");
        int xh = sc.nextInt();
        System.out.println("请输入新增DVD名称:");
        String n = sc.next();
        if(i>=0){
            emps[i] =new Dvd(xh, n);
            empCount++;
        }
        else
            System.out.println("数组已经没有空间存储新增DVD信息");
    }   
   
   
    int getEmpIndexByNum(int num){
        for (int i = 0; i < emps.length; i++) {
            if(emps[i] != null && emps[i].getNum() == num)
                return i;
        }
        return -1;
   
    }   
    public void delete(){
        System.out.println("请输入要删除的DVD序号:");
        int n = sc.nextInt();
        int index = getEmpIndexByNum(n);
        if(index>=0){
            emps[index]=null;
            empCount--;
        }
        else
            System.out.println(String.format("未找到序号为:%d 的DVD信息",n));   
    }   
    public void printgh(){
        System.out.println("请输入要归还的DVD名称:");
        String name= sc.next();
        System.out.println("请输入归还日期:");
        dstr2=sc.next();
      
   
        }
   
   
    public void jc() {
        System.out.println("请输入借出DVD的名称: ");
        String name=sc.next();  
        System.out.println("请输入借出DVD的状态:0可借,1借出");
        int state=sc.nextInt();
        System.out.println("请输入DVD借出日期");
         dstr1=sc.next();
         
        
    }
    public void zj() throws ParseException{
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Date d1=sdf.parse(dstr1);
        Date d2=sdf.parse(dstr2);
        long charge = (d2.getTime()-d1.getTime())/(24*60*60*1000);
        double zj=charge*2.5;
        System.out.println(zj);
   
}
}
package DVD;
import java.util.Scanner;
import java.text.ParseException;
import java.util.Date;

public class Test {
    public static void main(String[] args) throws ParseException {   
        Dvd2 manager = new Dvd2();
        System.out.println("欢迎使用迷你DVD管理器:");
        Object Dvd2 = null;
        menu(manager);        
        System.out.println("再见");
    }
    static void menu(Dvd2 em) throws ParseException{
        Scanner sc =new Scanner(System.in);
        int order = 0;
        do{
            System.out.println("0:退出  1:查看DVD 2:新增DVD 3:删除DVD 4:借出DVD 5:归还DVD 6:租金");
            order = sc.nextInt();
            switch(order){
            case 1:
                em.printAll();
                break;
            case 2:
                em.add();
                break;
            case 3:
                em.delete();
                break;
            case 4:
                em.jc();
                break;
            case 5:
                em.printgh();
                break;
                        
            case 6:
                em.zj();
                break;
            }
        }while(order !=0);
    }
}

请大神解答!日期和状态有点问题。
搜索更多相关主题的帖子: private package public return import 
2016-11-08 20:57
逐心者
Rank: 1
等 级:新手上路
帖 子:4
专家分:7
注 册:2016-11-5
得分:4 
新手路过
2016-11-08 22:51
kaosaier
Rank: 5Rank: 5
等 级:职业侠客
威 望:7
帖 子:124
专家分:303
注 册:2016-7-23
得分:4 
回复 楼主 博哥
啥问题?

minecraft,我的最爱!
2016-11-08 23:13
Magenasi
Rank: 1
等 级:新手上路
帖 子:1
专家分:4
注 册:2016-11-10
得分:4 
    public Dvd(int xuhao, String name) {
        this.xuhao = xuhao;
        this.name = name;
        this.date = date;
        this.state=state;
        this.zj=zj;
   
    }
这个构造函数不对吧,应该全要输入。你只输入两个变量,日期和状态你都没输入。所以有问题。
2016-11-11 00:12
不落夕阳
Rank: 2
等 级:论坛游民
帖 子:64
专家分:30
注 册:2016-10-13
得分:4 
牛B
2016-11-11 07:21
mooc
Rank: 1
等 级:新手上路
帖 子:1
专家分:4
注 册:2015-12-29
得分:4 
新人路过!!!

哈哈
2016-11-13 12:15
kaosaier
Rank: 5Rank: 5
等 级:职业侠客
威 望:7
帖 子:124
专家分:303
注 册:2016-7-23
得分:0 
回复 楼主 博哥
啥问题?

minecraft,我的最爱!
2016-11-13 17:47



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-470915-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.268333 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved