标题:新手求教,在代码中调用当前时间方法。
只看楼主
smartice
Rank: 1
等 级:新手上路
帖 子:18
专家分:3
注 册:2011-7-23
结帖率:100%
已结贴  问题点数:5 回复次数:5 
新手求教,在代码中调用当前时间方法。
新手求教,如何在代码中调用当前系统时间,求详细写法。还有我写了一段代码目前出错,求高手指正。拜]谢!

package myshopping;
import java.util.Scanner;
/**
 * 购物系统菜单
 * @author Administrator
 *
 */
public class menu {
    Scanner input = new Scanner(System.in);
    int[] custNo = new int[50];
    int[] score = new int [50];
    String[] birthday = new String[50];
    String answer;

    /**
     * 一级菜单,进入或退出系统
     */
    public void logMenu(){
   
            System.out.println("\t欢迎使用我行我素购物管理系统");
            System.out.println("\n\t\t1.登录系统");
            System.out.println("\n\t\t2.退       出");
            System.out.println("***********************************");
            System.out.print("请选择:");
            int num = input.nextInt();//定义num用于选择项目
            switch(num){
                case 1:
                    signIn();//用户登录
                    break;
                case 2:
                    System.out.println("欢迎下次使用!");
                    break;
                default:
                    System.out.println("输入有误,请重新选择:");
            }
            
    }

    /**
     * 二级菜单,选择不同的工作项目
     */
    public void mainMenu(){
        System.out.println("***********************************");
        System.out.println("\n我行我素购物管理系统");
        System.out.println("\n\t1.客户信息管理");
        System.out.println("\t2.购物结算");
        System.out.println("\t3.真情回馈");
        System.out.println("\t4.注销");
        System.out.println("***********************************");
        System.out.print("请选择,按0返回上一层:");
        int num = input.nextInt();//定义num用于选择项目
        switch(num){
            case 0:
                logMenu();
                break;
            case 1:
                custMeager();//进入客户信息管理项目
                break;
            case 2:
                pay();
                break;
            case 3:
                lucky();
                break;
            case 4:
               
                signIn();
                break;
            default:
                System.out.println("输入有误,请重新选择:");
        }
    }
    /**
     * 客户信息管理
     * 目前在修改和查询客户信息处有问题。
     */
    public void custMeager(){
        do{
            System.out.println("***********************************");
            System.out.println("\n我行我素购物管理系统 > 客户信息管理");
            System.out.println("\n\t1.显示所有客户信息");
            System.out.println("\t2.添加客户信息");
            System.out.println("\t3.修改客户信息");
            System.out.println("\t4.查询客户信息");
            System.out.println("***********************************");
            System.out.print("请选择,按0返回上一层:");
            int num = input.nextInt();//定义num用于选择项目
            switch(num){
                case 0:
                    mainMenu();
                    break;
                case 1:
                    outPutCustInfo();
                    break;
                case 2:
                    addCustInfo();
                    break;
                case 3:
                    modifyInfo();
                    break;
                case 4://问题是break问题
                    queryInfo();
                    break;
                default:
                    System.out.println("输入有误,请重新选择:");
            }
                System.out.print("是否继续(y/n):");
                answer = input.next();
        }while(answer.equals("y"));
        
    }
    /**
     * 购物结算
     */
    public void pay(){
        double finalMoney;
        do{
            System.out.println("***********************************");
            System.out.println("\n我行我素购物管理系统 > 购物结算");
            System.out.println("\n\t1.会员结算");
            System.out.println("\t2.非会员结算");
            System.out.println("***********************************");
            System.out.print("请选择,或按0返回上一层:");
            int num = input.nextInt();
            switch(num){
                case 0:
                    mainMenu();
                    break;
                case 1:
                    System.out.println("***********************************");
                    System.out.println("\n我行我素购物管理系统 > 购物结算 > 会员结算");
                    System.out.print("请输入会员号:");
                    int no = input.nextInt();
                    for (int i = 0; i < custNo.length; i++) {
                        if(custNo[i] == no ){
                            System.out.print("请输入消费金额:");
                            double money = input.nextDouble();
                            if(money <= 100){
                                System.out.println("尊敬的"+custNo[i]+"号会员,您可享受的折扣是95折。");
                                finalMoney = money * 0.95;
                                System.out.println("您折后共计消费:"+finalMoney);
                            }else if(money >100  && money <= 300){
                                System.out.println("尊敬的"+custNo[i]+"号会员,您可享受的折扣是92折。");
                                finalMoney = money * 0.92;
                                System.out.println("您折后共计消费:"+finalMoney);
                            }else if(money >300  && money <= 500){
                                System.out.println("尊敬的"+custNo[i]+"号会员,您可享受的折扣是90折。");
                                finalMoney = money * 0.90;
                                System.out.println("您折后共计消费:"+finalMoney);
                            }else{
                                System.out.println("尊敬的"+custNo[i]+"号会员,您可享受的折扣是88折。");
                                finalMoney = money * 0.88;
                                System.out.println("您折后共计消费:"+finalMoney);
                            }   
                            System.out.print("收取金额:");
                            int getMoney = input.nextInt();
                            double returnMoney = getMoney - finalMoney;
                            System.out.print("找零:"+returnMoney+"\n");
                            int newScore = (int)(finalMoney * 3 / 10);
                            score[i]+=newScore;
                            System.out.println("尊敬的"+custNo[i]+"号会员,您本次消费积分为:"+newScore+",累计积分:"+score[i]);
                            System.out.println("谢谢惠顾!");
                            break;//此处不加break则按会员结算,结算之后显示下面else的内容.而且只能计算第一个会员的消费情况,第二个则不能
                        }else{
                            System.out.println("抱歉!您不是会员,请按非会员结算。");
                            break;
                        }
                    }
                    break;
                case 2:
                    System.out.println("***********************************");
                    System.out.println("\n我行我素购物管理系统 > 购物结算 > 非会员结算");
                    System.out.print("请输入消费金额:");
                    double money = input.nextDouble();
                    if(money <= 300){
                        System.out.println("尊敬的客户,您的消费不足以享受折扣。");
                        finalMoney = money * 1;
                        System.out.println("您共计消费:"+finalMoney);
                    }else if(money >300  && money <= 500){
                        System.out.println("尊敬的客户,您可享受的折扣是95折。");
                        finalMoney = money * 0.98;
                        System.out.println("您折后共计消费:"+finalMoney);
                    }else{
                        System.out.println("尊敬的客户,您可享受的折扣是95折。");
                        finalMoney = money * 0.95;
                        System.out.println("您折后共计消费:"+finalMoney);
                    }   
                    System.out.print("收取金额:");
                    int getMoney = input.nextInt();
                    double returnMoney = getMoney - finalMoney;
                    System.out.print("找零:"+returnMoney+"\n");
                    System.out.println("谢谢惠顾!");
                    break;
            }
            System.out.print("是否继续(y/n):");
            answer = input.next();
        }while(answer.equals("y"));
    }
    /**
     * 真情回馈
     */
    public void lucky(){
        do{
            System.out.println("***********************************");
            System.out.println("\n我行我素购物管理系统 > 真情回馈");
            System.out.println("\n\t1.幸运大抽奖");
            System.out.println("\t2.幸运抽奖");
            System.out.println("\t3.生日问候");
            System.out.println("***********************************");
            System.out.print("请选择,按0返回上一层:");
            int num = input.nextInt();//定义num用于选择项目
            switch(num){
                case 0:
                    mainMenu();
                    break;
                case 1:
                    System.out.println("\n我行我素购物管理系统 > 真情回馈 > 幸运大放送");
                    System.out.println("\t\t今日赠品:马克杯");
                    System.out.println("顾客可凭但是小品到服务台换购,每张小票限1次,50元起。");
                    System.out.print("请输入您消费的金额:");
                    int money = input.nextInt();
                    if(money< 50){
                        System.out.println("对不起,您的消费金额不足以参加此次换购活动。");
                    }else {
                        if(money >=50 && money < 100){
                            System.out.println("换购成功!您的换购金额是:"+(money+5));
                        }else if(money >= 100 && money <150){
                            System.out.println("换购成功!您的换购金额是:"+(money+2));
                        }else if(money >=150 && money <200){
                            System.out.println("换购成功!您的换购金额是:"+(money+1));
                        }else{
                            System.out.println("换购成功!您的换购金额是:"+(money+0));
                        }
                    }
                    
                    break;
                case 2:
                    System.out.println("\n我行我素购物管理系统 > 真情回馈 > 幸运抽奖");
                    System.out.println("请按确认键随机抽取一个两位数字:");
                    int luckyNo = (int)(Math.random() * 100);
                    System.out.println("尊敬的客户,您抽取的随机数字是"+luckyNo);
                    int gewei = luckyNo % 10;
                    int shiwei = luckyNo / 10;
                    int sum = gewei + shiwei ;
                    if(sum <=5){
                        System.out.println("恭喜!尊敬的客户您可获得由本超市提供的《高露洁盐白牙膏》一盒");
                    }else if(sum >5 && sum<=10 ){
                        System.out.println("恭喜!尊敬的客户您可获得由本超市提供的《可比克薯条》一包");
                    }else if(sum >10 && sum <=18){
                        System.out.println("恭喜!尊敬的客户您可获得由本超市提供的《营养快线》一瓶");
                    }
                    break;
                case 3:
                    System.out.println("\n我行我素购物管理系统 > 真情回馈 > 生日问候");
                    System.out.print("今日是:");
                    break;
                default :
                    System.out.print("输入有误,请重新选择:");
                    break;
            }
            System.out.print("是否继续(y/n):");
            answer = input.next();
        }while(answer.equals("y"));
    }
    /**
     * 用户登录
     */
    public void signIn(){
        for (int i = 0; i < 3; i++) {
            System.out.print("请输入用户名:");
            String userName = input.next();
            System.out.print("请输入密码:");
            int passWord = input.nextInt();
            if(userName.equals("ice")&& (passWord == 123456)){
                System.out.println("欢迎您!"+userName);
                mainMenu();//进入二级菜单选择不同的工作项目
            }else{
                System.out.println("第"+(i+1)+"次输入错误,请重新输入:");
                if((i+1)>=3){
                    System.out.println("三次输入错误,欢迎下次使用!");
                    System.out.println("");
                }
            }
        }
        
    }
    /**
     *显示所有客户信息
     */
    public void outPutCustInfo(){
        System.out.println("***********************************");
        System.out.println("\n我行我素购物管理系统 > 客户信息管理 > 显示所有客户信息");
        System.out.println("\n会员号\t积分\t生日");
        for (int i = 0; i < custNo.length; i++) {
            if(custNo[i] == 0){
                break;
            }else{
                System.out.println(custNo[i]+"\t"+score[i]+"\t"+birthday[i]);
            }
        }
    }
    /**
     * 添加客户信息
     */
    public void addCustInfo(){
        System.out.println("***********************************");
        System.out.println("\n我行我素购物管理系统 > 客户信息管理 > 添加客户信息");
        System.out.print("\n请输入客户名字:");
        String custName = input.next();
        System.out.print("请输入客户生日(月/日):");
        String custBirthday = input.next();
        System.out.println("添加客户信息成功,请牢记:");
        System.out.println("会员号\t积分\t生日");
        for (int i = 0; i < custNo.length; i++) {
            if(custNo[i] == 0){
                custNo[i] = (int)((Math.random()) * 10000);
                birthday[i] = custBirthday;
                score[i] = 0;
                System.out.println(custNo[i]+"\t"+score[i]+"\t"+birthday[i]);
                break;
            }
        }
    }
    /**
     * 修改客户信息
     */
    public void modifyInfo(){
        System.out.println("\n我行我素购物管理系统 > 客户信息管理 > 修改客户信息");
        System.out.print("\n请输入要修改的会员号:");
        int No = input.nextInt();
        for (int i = 0; i < custNo.length; i++) {
            if( custNo[i] == No){
                System.out.print("请选择要修改的项目:(1.积分2.生日):");
                int num = input.nextInt();
                switch(num){
                    case 1:
                        System.out.print("请输入新的积分:");
                        int newScore = input.nextInt();
                        score[i] = newScore;
                        System.out.println("修改成功");
                        break;
                    case 2:
                        System.out.print("请输入新的生日:");
                        String newBirthday = input.next();
                        birthday[i] = newBirthday;
                        System.out.println("修改成功");
                        break;
                    default:
                        System.out.println("输入有误,请重新输入:");   
                    }
                break;//此处不加break,则先显示"查无此信息!"在提示"请选择要修改的项目:(1.积分2.生日):"
            }else{
                System.out.println("查无此信息!");
                //break;//此处不加break,则循环输出"查无此信息!"
            }
        }
    }
    /**
     * 查询客户信息
     */
    public void queryInfo(){
        System.out.println("\n我行我素购物管理系统 > 客户信息管理 > 查询客户信息");
        System.out.print("\n请输入要查询的会员号:");
        int no = input.nextInt();
        for (int i = 0; i < custNo.length; i++) {
            if( no == custNo[i]){
                System.out.println("会员号\t积分\t生日");
                System.out.println(custNo[i]+"\t"+score[i]+"\t"+birthday[i]);
                //break;//此处不加break则先显示查询信息,然后显示"查无此信息!"
            }else{
                System.out.println("查无此信息!");
                break;//此处不加break循环显示"查无此信息!",加上则查询不到第二个会员号以后的信息
            }
        }
    }
}
搜索更多相关主题的帖子: class package public import 
2011-12-14 10:47
x4652660
Rank: 1
等 级:新手上路
帖 子:5
专家分:2
注 册:2011-12-15
得分:2 
有一个类是java.util.Calendar,自己去API上看
2011-12-15 19:25
linMop
Rank: 1
等 级:新手上路
帖 子:6
专家分:7
注 册:2011-12-9
得分:2 
Date 和 SimpleDateFormate
2011-12-15 22:24
lucky563591
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:小飞侠
威 望:4
帖 子:765
专家分:2103
注 册:2009-11-18
得分:2 
Date date=new Date();
2011-12-18 10:19
smartice
Rank: 1
等 级:新手上路
帖 子:18
专家分:3
注 册:2011-7-23
得分:0 
谢谢各位!我已经搞明白调用了。
现在在请教下:我调用当前系统的时间之后,需要把它赋给一个变量。如:
    System.out.print("请输入借出日期:");
    time();//调用当前系统时间的方法名
    System.out.println("《"+mydvd[i].name+"》借出成功!");
    mydvd[i].sate =0;//更改当前状态为借出
    mydvd[i].date ="" ;//此处需要把当前的系统时间赋给mydvd[i].date
    break;

这是一个简单的DVD管理器,主要功能是实现添加、查看、删除、借出、归还已经统计排行功能,北大青鸟的S1项目案例。求教!
2011-12-19 11:46
a5047
Rank: 2
等 级:论坛游民
帖 子:7
专家分:24
注 册:2011-12-22
得分:0 
自己去看API文档
2012-01-08 11:47



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




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

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