第二周总结
本周学习了较少的理论知识,主要包括方法的学习及运用,通过方法调用的方式,对前面所学进行了系统的总结与实践。
主要实践内容有:
简易学生成绩管理系统(代码如下):
/*
* 功能:简易学生成绩管理系统
*/
package day7;
import java.util.Scanner;
import javax.swing.plaf.synth.SynthScrollPaneUI;
/**
*
* @FengYan Huang Administrator
* 下午4:07:53
*/
public class HomeWork {
static Runtime run=Runtime.getRuntime();
static Scanner scan=new Scanner(System.in);
static String[] user=new String[2];
static String[] password=new String[2];
static String[] name=new String[5];
static int[] score=new int[name.length];
static boolean c=false;
public static void main(String[] args) {
fun();
}
public static void fun(){
while(true){
System.out.println("欢迎使用简易成绩管理系统0.0");
System.out.println("A注册");
System.out.println("B登录");
System.out.println("C退出");
char str=scan.next().charAt(0);
switch(str){
case 'A':
register(user,password);
break;
case 'B':
login(user,password);
break;
case 'C':
System.out.println("退出成功!!!");
// System.out.println("使用后的空闲内存量:"+run.freeMemory());
System.exit(0);
break;
default :
System.out.println("输入有误,请重新输入。");
}
}
}
public static void register(String user[],String password[]){
for (int i = 0; i < user.length; i++) {
if(user[i]==null){System.out.println("请输入用户名:");
user[i]=scan.next();
System.out.println("请输入密码:");
password[i]=scan.next();
System.out.println("注册成功,返回登录!!!");
fun();
}
}
System.out.println("用户已经达到上限,请联系管理员。");
}
public static void login(String user[],String password[]){
System.out.println("请输入用户名");
String str1=scan.next();
System.out.println("请输入密码:");
String str2=scan.next();
for (int i = 0; i < user.length; i++) {
if(str1.equals(user[i])&&str2.equals(password[i])){
System.out.println("登录成功!!!欢迎您!!!");
fun1();
}else{
System.out.println("没找到该用户!请重新登录");
fun();
}
}
}
public static void fun1(){
System.out.println("A增加学生分数信息");
System.out.println("B修改学生分数信息");
System.out.println("C删除学生分数信息");
System.out.println("D查询学生信息");
System.out.println("E返回上级菜单");
char str=scan.next().charAt(0);
switch(str){
case 'A':
add(name,score);
break;
case 'B':
modify(name,score);
break;
case 'C':
delete(name,score);
break;
case 'D':
insert(name,score);
break;
case 'E':
fun();
break;
}
}
public static void add(String[] name,int[] score){
for (int i = 0; i < name.length; i++) {
System.out.println("请输入第"+(i+1)+"个学生的名字:");
name[i]=scan.next();
System.out.println("请输入第"+(i+1)+"个学生的分数:");
score[i]=scan.nextInt();
}
System.out.println("新增学生信息成功!!!返回上级菜单");
fun1();
}
public static void delete(String[] name,int[] score){
System.out.println("请输入你要删除的学生姓名:");
String str=scan.next();
if(name[0].equals(str)){
System.out.println("成功删除了"+name[0]+"的信息");
for (int j = 0; j < name.length; j++) {
name[j]=name[j+1];
score[j]=score[j+1];
c=true;
}
}
if(name[name.length-1].equals(str)){
System.out.println("成功删除了"+name[name.length-1]+"的信息");
name[name.length-1]=null;
score[score.length-1]=0;
c=true;
}
for (int i = 1; i < name.length; i++) {
if(name[i-1].equals(str)){
System.out.println("成功删除了"+name[i-1]+"的信息");
name[i-1]=name[i];
score[i-1]=score[i];
c=true;
}
}
if(c){
name[name.length-1]=null;
score[score.length-1]=0;
fun1();
}else{
System.out.println("没有找到该学的信息");
fun1();
}
}
public static void modify(String[] name,int[] score){
System.out.println("请输入你要修改的学生姓名:");
String str=scan.next();
for (int i = 0; i < name.length; i++) {
if(name[i].equals(str)){
System.out.println("你要修改的是"+name[i]+"的分数,请输入你要修改的分数:");
score[i]=scan.nextInt();
System.out.println("修改成功!!!返回上级菜单");
fun1();
}else{
System.out.println("没有找到该学的信息");
}
}
}
public static void insert(String[] name1,int[] score1){
System.out.println("A查询一个学生分数:");
System.out.println("B查询所有学生分数:");
char str=scan.next().charAt(0);
switch(str){
case 'A':
System.out.println("请输入查询的学生姓名:");
String str1=scan.next();
for (int i = 0; i < name1.length; i++) {
if(name[i].equals(str1)){
System.out.println("你查询的是"+name1[i]+"的分数,他的分数是:"+score1[i]);
fun1();
}
}
System.out.println("没有找到该学生的信息!!!");
break;
case 'B':
for (int i = 0; i < name1.length; i++) {
System.out.println(name1[i]+"的分数是:"+score1[i]);
}
break;
}
fun1();
}
}
简易ATM机(代码如下):
/*
* 功能:简易银行系统
*/
package day8;
import java.util.Scanner;
/**
*
* @FengYan Huang Administrator
* 下午1:07:20
*/
public class test8_1 {
static int count=0;
static int n=-1;
static boolean flag=false;
static String[] user=new String[10];
static int[] identity={62220000,62220001,62220001,62220002,62220003,62220004,62220005,62220006,62220007,62220008,62220009};
static int[] password=new int[10];
static int[] balance=new int[10];
static Scanner scan=new Scanner(System.in);
public static void main(String[] args) {
fun();
}
public static void fun(){
System.out.println("***欢迎使用ATM机***");
System.out.println("***请选择服务类型***");
System.out.println("***开户***");
System.out.println("***登录***");
System.out.println("***退出***");
String str=scan.next();
if(str.equals("开户")){
register();
}else if(str.equals("登录")){
login();
}else if(str.equals("退出")){
exit();
}else{
System.out.println("很抱歉,无法识别您的操作,请重新选择!!!");
fun();
}
}
public static void login(){
System.out.println("请输入您的卡号:");
int id=scan.nextInt();
for (int i = 0; i < identity.length; i++) {
if(id==identity[i]){
System.out.println("请输入您的密码:");
int ps=scan.nextInt();
if(id==identity[i]&&ps!=password[i]){
System.out.println("温馨提示:");
count++;
System.out.println("您已经输错了"+count+"次密码");
System.out.println("请返回重新操作!");
if(count==3){
System.out.println("您今日的密码输入次数已达上限,卡片已经被吞");
System.out.println("您是否已经忘记了密码???");
System.out.println("请联系本行取回卡片");
fun();
}
login();
}
if(id==identity[i]&&ps==password[i]){
n=i;
System.out.println("***登录成功***");
System.out.println("***欢迎您***"+user[i]);
System.out.println("***请选择服务项目***");
fun1(user,identity,password,balance);
}
}else{
flag=true;
}
}
if(flag=true){
System.out.println("没找到您的卡号!");
System.out.println("请重新操作");
flag=false;
login();
}
}
public static void register(){
System.out.println("***欢迎注册本行银行卡***");
System.out.println("***请输入您的姓名***");
String name=scan.next();
System.out.println("***请输入您的密码***");
int ps=scan.nextInt();
System.out.println("***请确认输入您的密码***");
int ps1=scan.nextInt();
if(ps==ps1){
for (int i = 0; i < user.length; i++) {
if(user[i]==null){
user[i]=name;
password[i]=ps;
System.out.println("***注册成功***");
System.out.println("***您的账户名是:"+user[i]);
System.out.println("***请牢记您的卡号:"+identity[i]);
System.out.println("***请牢记您的密码:"+password[i]);
fun();
}else{
flag=true;
}
}
if(flag=true){
flag=false;
System.out.println("***非常抱歉***");
System.out.println("***本行注册用户已达上限***");
System.out.println("***本行注册用户已达上限***");
fun();
}
}else{
System.out.println("注册失败!!!您两次输入的密码不一样");
fun();
}
}
public static void exit(){
System.out.println("***谢谢您的使用***");
System.out.println("***欢迎再次光临***");
System.out.println("***如果您有好的建议,请联系本行(95555)***");
System.exit(0);
}
public static void fun1(String[] user,int[]identity,int[]password,int[]balance){
System.out.println("***改密***");
System.out.println("***查询***");
System.out.println("***存款***");
System.out.println("***取款***");
System.out.println("***转账***");
System.out.println("***退出***");
String str=scan.next();
if(str.equals("改密")){
changePassword(user,identity,password,balance);
}else if(str.equals("查询")){
insert(user,identity,password,balance);
}else if(str.equals("存款")){
deposit(user,identity,password,balance);
}else if(str.equals("取款")){
withdraw(user,identity,password,balance);
}else if(str.equals("转账")){
transfer(user,identity,password,balance);
}else if(str.equals("退出")){
exit();
}else{
System.out.println("您的操作有误,请重新选择:");
fun1(user,identity,password,balance);
}
}
public static void changePassword(String[] user,int[]identity,int[]password,int[]balance){
System.out.println("***"+user[n]+"***");
System.out.println("***欢迎使用改密系统***");
System.out.println("***请输入新密码:***");
int ps=scan.nextInt();
System.out.println("***请确认新密码:***");
int ps1=scan.nextInt();
if(ps==ps1){
System.out.println("您的密码已经修改成功!");
password[n]=ps;
System.out.println("请牢记您的密码:"+ps);
System.out.println("***系统自动返回ing***");
fun1(user,identity,password,balance);
}else{
System.out.println("两次输入密码不一样!");
System.out.println("请重新操作!");
changePassword(user,identity,password,balance);
}
}
public static void insert(String[] user,int[]identity,int[]password,int[]balance){
System.out.println("***"+user[n]+"***");
System.out.println("***欢迎使用查询系统***");
System.out.println("***您的账户余额为:***");
System.out.println(balance[n]+"元");
System.out.println("***系统自动返回ing***");
fun1(user,identity,password,balance);
}
public static void deposit(String[] user,int[]identity,int[]password,int[]balance){
System.out.println("***"+user[n]+"***");
System.out.println("***欢迎使用存款系统***");
System.out.println("***请输入存款金额***");
int depositmoney=scan.nextInt();
System.out.println("***请放入百元大钞***");
if(depositmoney%100==0){
System.out.println("您要存入的金额是:"+depositmoney+"元");
System.out.println("***系统处理ing***");
balance[n]+=depositmoney;
System.out.println("存款成功!!!");
System.out.println("您的账户余额为:"+balance[n]+"元");
System.out.println("***系统自动返回ing***");
fun1(user,identity,password,balance);
}else{
System.out.println("存款失败!!!");
System.out.println("您放入纸币有疑问,请重新操作");
deposit(user,identity,password,balance);
}
}
public static void withdraw(String[] user,int[]identity,int[]password,int[]balance){
System.out.println("***"+user[n]+"***");
System.out.println("***欢迎使用取款系统***");
System.out.println("***请输入取款金额(为100元的整数倍)***");
int withdrawmoney=scan.nextInt();
System.out.println("***系统处理ing***");
if(balance[n]>withdrawmoney&&withdrawmoney%100==0){
balance[n]-=withdrawmoney;
System.out.println("***正在为您取款ing***");
System.out.println("***请取走您的钞票***");
System.out.println("***您的账户余额为:"+balance[n]+"元***");
System.out.println("***取款成功***");
System.out.println("***系统自动返回ing***");
fun1(user,identity,password,balance);
}else{
System.out.println("***很遗憾!取款失败***");
System.out.println("***给您带来的不便深表遗憾***");
System.out.println("***可能是以下原因造成的:***");
System.out.println("***您的余额不足***");
System.out.println("***您输入的取款金额有误***");
System.out.println("***请重新操作***");
System.out.println("***系统自动返回ing***");
withdraw(user,identity,password,balance);
}
}
public static void transfer(String[] user,int[]identity,int[]password,int[]balance){
System.out.println("***"+user[n]+"***");
System.out.println("***欢迎使用转账系统***");
System.out.println("***请输入您要转入的对方名字:");
String username=scan.next();
for (int i = 0; i < user.length; i++) {
if(username.equals(user[i])){
System.out.println("您要转入的是:"+user[i]+"的账户");
System.out.println("请输入转入的金额");
int transfermoney=scan.nextInt();
System.out.println("***正在为您处理ing***");
if(transfermoney>0&&balance[n]>transfermoney){
balance[n]-=transfermoney;
balance[i]+=transfermoney;
System.out.println("***转账成功***");
System.out.println("您的账户余额为:"+balance[n]);
System.out.println("***系统自动返回ing***");
fun1(user,identity,password,balance);
}else{
System.out.println("转账失败");
System.out.println("可能是您的账户余额不足");
System.out.println("可能是您输入的金额有误");
System.out.println("请返回重新操作");
transfer(user,identity,password,balance);
}
}
else{
flag=true;
}
}
if(flag==true){
System.out.println("没找到账户!");
System.out.println("请重新操作!");
flag=false;
transfer(user,identity,password,balance);
}
}
}
学无止境,勤奋为佐!