JAVA初学者的一些问题JAVA
给你做了个Demo,生日改成了直接读取一个输入日期,自己运行看下:
import java。text。DateFormat;
import java。text。ParseException;
import java。 text。SimpleDateFormat;
import java。util。Scanner;
public class Chapter03 {
static Scanner input = new Scanner( );
static DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
public s...全部
给你做了个Demo,生日改成了直接读取一个输入日期,自己运行看下:
import java。text。DateFormat;
import java。text。ParseException;
import java。
text。SimpleDateFormat;
import java。util。Scanner;
public class Chapter03 {
static Scanner input = new Scanner( );
static DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
public static void main(String[] args) {
intln("我行我素购物管理系统>客户信息管理>添加客户信息\n");
int("请输入会员号(4位整数):");
int numberID = xtInt();
int("请输入会员生日(格式:年/月/日,例如:2011/01/01:");
String birthday = xt();
int("请输入积分:");
int totalPoints = xtInt();
intln();
if(!checkInfo(numberID, birthday, totalPoints)){
intln("录入信息失败!!!");
}else{
int("您输入的信息如下:");
intln("客户号: " + numberID);
intln("客户生日: " + birthday);
intln("客户积分: " + totalPoints);
}
}
public static boolean checkInfo(int numberID, String birthday, int totalPoints){
boolean result = true;
if(numberID 9999){
intln("客户号 '" + numberID + "' 是无效会员号!");
result = false;
}
if(null == birthday || ""。
equals( im())){
intln("客户生日 '" + birthday + "' 是无效会员生日!");
result = false;
}
try {
rse(birthday);
} catch (ParseException e) {
intln("客户生日 '" + birthday + "' 是无效会员生日!");
result = false;
}
if(totalPoints < 0 ){
intln("客户积分 '" + totalPoints + "' 是无效会员积分");
result = false;
}
return result;
}
}
写代码还是要养成好的编程习惯,首先类名就写的不正确,java类名第一个字母要大写。
变量尽量能达意,不要用汉语拼音。java中条件判断是短路运行的,例如&&运算,如果第一个条件为假,那么后面的条件不管是什么都不会再运行。再有是基本类型如整型是有范围限制的。收起