【任务解决】:
import java.util.*;
public class Yi {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
int []total=new int[108];
int[][]player=new int[4][25];
int leftNum=108;
int ranNumber;
Random random=new Random();
for(int i=0;i
【测试结果】
玩家 0 的牌 11 41 8 38 13 9 16 19 54 43 15 18 46 17 48 30 33 41 6 47 5 26 1 26 27
玩家 1 的牌 36 36 9 2 44 42 4 13 16 14 8 21 32 34 25 1 51 19 22 3 7 6 29 18 51
玩家 2 的牌 44 35 31 39 2 10 12 24 23 5 20 24 14 50 48 45 11 15 32 25 12 54 27 40 4
玩家 3 的牌 34 49 52 23 28 33 31 38 42 43 45 22 28 53 37 53 17 50 21 37 20 7 29 49 30
底牌 47 46 52 10 35 40 3 39
实验二:
import java.io.*;
class Account{
//卡号
//客户姓名
//客户密码
private String number=null;
private String name=null;
private String password=null;
private double money=0.0;
/*****构造方法,以生成多个储户信息*****/
public Account(String number,String name,String password,double money)
{
//余额
this.number=number;
this.name=name;
this.password=password;
this.money=money;
}
protected String get_number(){
return number;
}
protected String get_Name(){
return name;
}
protected String get_Password(){
return password;
}
protected double get_Money(){
return money;
}
protected void sub_Balance(double mon){
money-=mon;
}
protected void add_Balance(double mon){
money+=mon;
}
}
/*ATM 类实现 ATM 机的主要功能*/
//import java.io.*;
class ATM{
Account act;
public ATM(){
act=new Account("000","test","111",5000);
}
/*********欢迎界面*********/
protected void Welcome()
{
}
String str="----------------------------";
System.out.print(str+"\n");
System.out.print("1.取款."+"\n"+
"2.查询."+"\n"+
"3.存款."+"\n"+
"4.退出系统."+"\n");
System.out.print(str+"\n");
/*********登录系统*********/
protected void Load_Sys()throws Exception
{
String card,pwd;
int counter=0;
BufferedReader br=new BufferedReader(new
InputStreamReader(System.in));
do{
System.out.println("请输入您的卡号:");
card=br.readLine();
System.out.println("请输入您的密码");
pwd=br.readLine();
if(!isRight(card,pwd))
{
System.out.println("您的卡号或密码输入有误");
counter++;
}
else
SysOpter();
}while(counter<3);
}
/******系统操作提示*******/
protected void SysOpter()throws Exception
{
int num;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("请选择您要操作的项目(1-4):");
num=br.read();
switch(num){
case 49:GetBalance();break;
case 50:Inqu_Info();break;
case 51:AddBalance();break;
case 52:Exit_Sys();break;
}
System.exit(1);
}
/******信息查询*******/
protected void Inqu_Info()throws Exception
{
System.out.print("------------------\n"+
"账户:"+act.get_number()+"\n"+
"姓名:"+act.get_Name()+"\n"+
"余额:"+act.get_Money()+"\n"+
"------------------\n");
SysOpter();
}
/*********取款**********/
public void GetBalance()throws Exception
{
String str=null,str1;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
do{
System.out.println("请输入取款数目:");
str=br.readLine();
double qu=Double.valueOf(str).doubleValue();
if(qu>act.get_Money()){
System.out.println("余额不足,请重新输入您要取的数目:");
}
else{
act.sub_Balance(qu);
System.out.println("取款成功,您的账户余额为:"+act.get_Money());
Welcome();
SysOpter();
}
}while(true);
}
/*********存款***********/
public void AddBalance()throws Exception
{
String str=null,str1;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
do{
System.out.println("请输入存款数目:");
str=br.readLine();
double qu=Double.valueOf(str).doubleValue();
act.add_Balance(qu);
System.out.println("存款成功,您的账户余额:"+act.get_Money());
Welcome();
SysOpter();
}while(true);
}
/*********判断卡内是否有钱***********/
protected boolean isBalance(){
if(act.get_Money()<0){
return false;
}
return true;
}
/*********卡号密码是否正确***********/
protected boolean isRight(String card,String pwd)
{
if(act.get_number().equals(card)&&act.get_Password().equals(pwd))
else
return true;
return false;
}
/*********结束系统***********/
protected void Exit_Sys(){
System.out.println("感谢您使用本系统,再见");
System.exit(1);
}
}
public class Er {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws Exception{
ATM atm=new ATM();
atm.Welcome();
atm.Load_Sys();
// TODO code application logic here
}
}
输出:
run:
----------------------------
1.取款.
2.查询.
3.存款.
4.退出系统.
----------------------------
请输入您的卡号:
000
请输入您的密码
222
您的卡号或密码输入有误
请输入您的卡号:
000
请输入您的密码
111
请选择您要操作的项目(1-4):
1
请输入取款数目:
1000
取款成功,您的账户余额为:4000.0
----------------------------
1.取款.
2.查询.
3.存款.
4.退出系统.
----------------------------
请选择您要操作的项目(1-4):
2
------------------
账户:000
姓名:test
余额:4000.0
------------------
请选择您要操作的项目(1-4):
3
请输入存款数目:
100
存款成功,您的账户余额:4100.0
----------------------------
1.取款.
2.查询.
3.存款.
4.退出系统.
----------------------------
请选择您要操作的项目(1-4):
4
感谢您使用本系统,再见
Java Result: 1
实验三:
public abstract class Shape{
public abstract double getArea();
//抽象方法取得图形面积
}
/*通过继承定义正方形子类 Square*/
public class Square extends Shape{
private double height=0;
public Square(double height){
this.height=height;
}
/*重写 getArea 方法*/
public double getArea(){
return(this.height*this.height);
}
}
/*通过继承定义圆子类 Circle*/
public class Circle extends Shape{
private double r=0;
private final static double PI=3.4;
public Circle(double r){
this.r=r;
}
/*重写 getArea 方法*/
public double getArea(){
return (PI*r*r);
}
}
/*通过定义继承三角形子类 Triangle*/
public class Triangle
extends Shape{
private double a=0;
private double b=0;
private double c=0;
private double h=0;
public Triangle(double a,double h){
this.a=a;
this.h=h;
}
public Triangle(double a,double b,double c){
this.a=a;
this.b=b;
this.c=c;
}
/*重写 getArea 方法*/
public double getArea(){