哪位高手能帮我解决一下,这个问题,急死我了

jay0518 2005-10-18 07:21:58
由于刚刚学java程序刚刚写了一半就有一个小问题都搞不定,请高手帮帮我.
代码:
import java.io.*;
import java.awt.*;
public class campusecard
{
public static void main(String args[])
{
card mycard=new card();
int choice=0;
while(true)
{
choice=mycard.menu();
switch(choice)
{
case 1:
mycard.changepassword();
break;
case 2:
mycard.cardconsume();
break;
case 3:
mycard.searchrecord();
break;
case 4:
System.out.println("你的校园卡中剩余的金额为:"+mycard.showleftmoney());
break;
case 5:
mycard.testsignup();
break;
case 6:
mycard.borrowbooks();
break;
case 7:
return;
}
}
}
}
class card
{
static final long number=1103101134;
long password=123456;
float leftmoney;
boolean connected;
int bookcount;
card()
{
leftmoney=50;
connected=false;
}
int menu()
{
System.out.println("校园卡信息管理系统");
System.out.println("===================");
System.out.println("1.修改密码");
System.out.println("2.消费");
System.out.println("3.查询消费明细");
System.out.println("4.余额查询");
System.out.println("5.等级考试报名");
System.out.println("6.图书借阅");
System.out.println("7.退出");
System.out.println("===================");
System.out.println("请选择你的操作:");
char c='A';
try{
c=(char)System.in.read();
}
catch(IOException e)
{
System.err.println(e.toString());
}
int choice=c-'0';
int count=0;
while(choice>7||choice<1)
{
count++;
if(count==3)
{
System.out.println("小样,你在捣蛋。");
System.exit(0);
}
System.out.println("小样,操作错误,请重新选择:");
try{
c=(char)System.in.read();
}catch(IOException e){};
choice=c-'0';
}
return choice;
}
void changepassword()//输入内容没有限制,需要改进
{
String s2=new String();
String s1=new String();
int count=0;
long number=0,number1=0,number2=0;
System.out.println("请输入卡的当前密码:");
try{
InputStreamReader br=new InputStreamReader(System.in);
BufferedReader in=new BufferedReader(br);
L0:
while(true)
{
try{
s1=in.readLine();
number=Long.parseLong(s1);
if(number!=password)
{
System.out.println("密码错误,请重新输入.");
count++;
}
else
break;
if(count==3)
{
System.out.println("小样,不要拿别人的卡当作自己的.");
return;
}
}catch(NumberFormatException e)
{
System.out.println("密码不能是非数字!请重试!");
continue L0;
}
break;
}
}catch(Exception e)
{
System.out.println(e);
}
try{
Label1:
while(true)
{
System.out.println("请输入你的新密码:");
InputStreamReader br=new InputStreamReader(System.in);
BufferedReader inm=new BufferedReader(br);
try{
s1=inm.readLine();
number1=Long.parseLong(s1);
}catch(NumberFormatException e)
{
System.out.println("密码不能是非数字!请重试!");
continue Label1;
}
break;
}
}catch(Exception e)
{
System.out.println(e);
}
System.out.println("请再次输入你的新密码:");
try
{
L2:
while(true)
{
InputStreamReader br=new InputStreamReader(System.in);
BufferedReader inn=new BufferedReader(br);
try{
s2=inn.readLine();
number2=Long.parseLong(s2);
}catch(NumberFormatException e)
{
System.out.println("密码不能是非数字!请重试!");
continue L2;
}
break;
}
}catch(Exception e)
{
System.out.println(e);
}
if(number1!=number2)
System.out.println("输入密码不一致,请重新输入.");
else
{
password=number1;
System.out.println("修改密码成功!");
return;
}
}
void cardconsume()
{
float consumemoney=0;
String s="";
try{
InputStreamReader br=new InputStreamReader(System.in);
BufferedReader is=new BufferedReader(br);
L3:
while(true)
{
System.out.println("请输入你消费金额:");
try
{
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
s=is.readLine();
consumemoney=Float.parseFloat(s);
}catch(NumberFormatException e)
{
System.out.println("输入的不是数字,请重新输入。");
continue L3;
};
break;
}
}catch(Exception e)
{
System.out.println(e);
}
if(consumemoney>leftmoney)
System.out.println("卡中余额不足!");
else
{
leftmoney-=consumemoney;
System.out.println("你消费了"+s+"元.");
}

}
float showleftmoney()
{
return leftmoney;
}
void searchrecord()
{
}
void testsignup()
{
}
void borrowbooks()
{
int number;
String name;
System.out.println("请输入书的名字:");
try
{
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
name=in.readLine();
}catch(IOException e){};
System.out.println("请输入书的条码号:");
}
}
运行界面:
校园卡信息管理系统
===================
1.修改密码
2.消费
3.查询消费明细
4.余额查询
5.等级考试报名
6.图书借阅
7.退出
===================
请选择你的操作:
1
请输入卡的当前密码:
密码不能是非数字!请重试!
请输入卡的当前密码:


问题就在这里,我刚刚输入1就显示了错误信息(密码我还没有输呢)
为什么啊
郁闷中
...全文
139 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
jay0518 2005-10-18
  • 打赏
  • 举报
回复
太谢谢superslash(回答问题要有深度,提问要有难度)
Octer 2005-10-18
  • 打赏
  • 举报
回复
楼上这位兄台,你太搞笑了吧,呵呵
superslash 2005-10-18
  • 打赏
  • 举报
回复
int menu() {
System.out.println("校园卡信息管理系统");
System.out.println("===================");
System.out.println("1.修改密码");
System.out.println("2.消费");
System.out.println("3.查询消费明细");
System.out.println("4.余额查询");
System.out.println("5.等级考试报名");
System.out.println("6.图书借阅");
System.out.println("7.退出");
System.out.println("===================");
System.out.println("请选择你的操作:");
String c = "";
try {
BufferedReader in = new BufferedReader(new InputStreamReader(
System.in));
c = in.readLine();
System.out.println(c);
} catch (IOException e) {
System.err.println(e.toString());
}
int choice = c.charAt(0) - '0';
int count = 0;
while (choice > 7 || choice < 1) {
count++;
if (count == 3) {
System.out.println("小样,你在捣蛋。");
System.exit(0);
}
System.out.println("小样,操作错误,请重新选择:");
try {
BufferedReader in = new BufferedReader(new InputStreamReader(
System.in));
c = in.readLine();
} catch (IOException e) {
}

choice = c.charAt(0) - '0';
}
return choice;
}
呵呵,没怎么动:)
jay0518 2005-10-18
  • 打赏
  • 举报
回复
to superslash(回答问题要有深度,提问要有难度):
谢谢指点
刚刚学,没有头绪呵呵
但是怎么样才能消除回车的影响呢?
superslash 2005-10-18
  • 打赏
  • 举报
回复
总体感觉楼主在读取密码时从代码看思维比较乱,呵呵,个人意见:)
superslash 2005-10-18
  • 打赏
  • 举报
回复
s1 = in.readLine();读取了上一句c = (char) System.in.read();的回车换行符
trumplet 2005-10-18
  • 打赏
  • 举报
回复
c=(char)System.in.read();

读如一个字符(以整数表示),键盘上的“1”,对应的 int 是 49(0x21)
unicode 的 0x7f以下的与ascii一致。
内容概要:本文深入研究了电力系统状态估计问题,重点围绕无迹卡尔曼滤波(UKF)、自适应无迹卡尔曼滤波(AUKF)以及扩展无迹卡尔曼滤波(EUKF)三种先进非线性滤波方法展开理论分析与仿真验证。通过Matlab平台实现了完整的算法架构与系统建模,系统地比较了各方法在处理电力系统非线性动态特性及噪声干扰方面的性能差异,旨在提升电压幅值、相角等关键状态变量的估计精度与鲁棒性。研究突出了算法在智能电网实时监控、故障诊断与动态调度中的应用潜力,并提供了可复现的代码支持。; 适合人群:具备电力系统分析基础和Matlab编程能力的研究生、科研人员,以及从事电力自动化、智能电网状态监测与控制相关的工程技术人员。; 使用场景及目标:①掌握UKF、AUKF与EUKF在非线性状态估计中的建模流程与实现细节;②应用于电力系统实时数据融合、动态安全评估与运行优化,提升估计系统的抗噪能力与适应性;③为学术论文撰写、课题申报或工程原型开发提供算法参考与仿真基础。; 阅读建议:建议结合Matlab环境逐模块调试代码,深入理解滤波器在不同噪声水平和系统非线性程度下的响应特性,重点关注协方差自适应机制与数值稳定性处理策略,并可根据具体应用场景调整系统模型与参数配置以优化性能。
【重要提示】本资源设置为0积分下载,若非0积分请勿轻易下载 亲爱的CSDN用户: 首先感谢你点进这个资源页面。我需要提前说明一个重要情况: 本资源原本已设置为“0积分下载”,即作者希望完全免费共享。但CSDN平台有时会根据文件的下载热度、文件大小、用户权限等因素,自动将部分资源的积分调整为非0数值(如1积分、2积分、5积分等)。这是平台系统的自动行为,而非作者本人的设定。 因此,如果你当前看到该资源的下载所需积分不是0(例如显示为1、2、3……),请谨慎决定是否下载。 如果你按照非0积分支付并下载后发现资源内容不符合预期、链接失效,或者实际上该资源本应是免费的,作者无法为此承担积分损失或退还操作。强烈建议:仅在页面显示为0积分时进行下载。 另外,本资源描述中并未直接提供具体的下载地址或外部链接,因为它本身是一个通过CSDN官方上传通道提交的文件/内容包。如果你看到描述中没有外部网盘地址,这是正常的——资源文件应通过CSDN内置的“下载”按钮获取。若因平台积分显示异常导致你支付了积分,请优先联系CSDN客服咨询积分退还政策,作者没有权限修改平台自动设定的积分值。 感谢你的理解与支持。技术分享本应开放,但受限于平台规则,特此提醒如上。祝学习进步!
【重要提示】本资源设置为0积分下载,若非0积分请勿轻易下载 亲爱的CSDN用户: 首先感谢你点进这个资源页面。我需要提前说明一个重要情况: 本资源原本已设置为“0积分下载”,即作者希望完全免费共享。但CSDN平台有时会根据文件的下载热度、文件大小、用户权限等因素,自动将部分资源的积分调整为非0数值(如1积分、2积分、5积分等)。这是平台系统的自动行为,而非作者本人的设定。 因此,如果你当前看到该资源的下载所需积分不是0(例如显示为1、2、3……),请谨慎决定是否下载。 如果你按照非0积分支付并下载后发现资源内容不符合预期、链接失效,或者实际上该资源本应是免费的,作者无法为此承担积分损失或退还操作。强烈建议:仅在页面显示为0积分时进行下载。 另外,本资源描述中并未直接提供具体的下载地址或外部链接,因为它本身是一个通过CSDN官方上传通道提交的文件/内容包。如果你看到描述中没有外部网盘地址,这是正常的——资源文件应通过CSDN内置的“下载”按钮获取。若因平台积分显示异常导致你支付了积分,请优先联系CSDN客服咨询积分退还政策,作者没有权限修改平台自动设定的积分值。 感谢你的理解与支持。技术分享本应开放,但受限于平台规则,特此提醒如上。祝学习进步!

62,622

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧