Account类:
目前成都创新互联公司已为千余家的企业提供了网站建设、域名、网页空间、网站托管维护、企业网站设计、农安网站维护等服务,公司将坚持客户导向、应用为本的策略,正道将秉承"和谐、参与、激情"的文化,与客户和合作伙伴齐心协力一起成长,共同发展。
package Test;
import java.util.HashMap;
import java.util.Map;
public class Account {
private String cardId;//卡号
private String name;//姓名
private String password;//密码
private long leftAmt;//剩余金额
public MapObject, ObjectgetAccountInfo(String id){
//这里暂设一个用户信息
//实际要建一个数据库存放多个用户的信息
MapObject, Object map = new HashMapObject, Object();
map.put("cardId", "123");
map.put("name", "qwe");
map.put("password", "789");
map.put("leftAmt", 88);
//实际要通过sql语句在数据库中查询id对应的账户信息
if(id == "123"){
//这里没有考虑密码,全部返回
return map;
}
return null;
}
public void setCardId(String cardId) {
this.cardId = cardId;
}
public String getCardId() {
return cardId;
}
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setPassword(String password) {
this.password = password;
}
public String getPassword() {
return password;
}
public void setLeftAmt(long leftAmt) {
this.leftAmt = leftAmt;
}
public long getLeftAmt() {
return leftAmt;
}
}
userOperate类:
package Test;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class UserOperate {
Account account = new Account();
public void operate(String id){
System.out.println("欢迎您使用ATM系统");
System.out.println("1--存款 2--查询");
System.out.println("3--取款 0--退出");
System.out.println("请选择操作类型【0-3】");
Scanner in = new Scanner(System.in);
int type = in.nextInt();
while(type!=0){
if(type==1){
System.out.println("请存入钞票");
type = in.nextInt();
}else
if(type==2){
System.out.println("您的银行账户信息为:");
MapObject, Object map = new HashMapObject, Object();
map = account.getAccountInfo(id);
System.out.println(map);
type = in.nextInt();
}else
if(type==3){
System.out.println("请取走您的钞票");
type = in.nextInt();
}else{
System.out.println("操作有误,请重新操作");
type = in.nextInt();
}
}
System.out.println("请尽快取走您的卡,谢谢使用!再见!");
in.close();
}
}
测试类(我放在main里):
package Test;
public class test1 {
public static void main(String[] args){
//测试
UserOperate userOperate = new UserOperate();
//假设银行卡插入后读取到的id为123
String id = "123";
userOperate.operate(id);
}
}
运行结果:
这是很简单的一个思路,简单跑跑可以。
也不知道你要什么样的结果,如果是要一个完整的系统,那具体还得建立数据库,还有如何读取账户信息,等等。
public class Circle {
private double radiums; //半径
private Point point; //坐标
public Circle(double radium, Point point) {
super();
this.radiums = radium;
this.point = point;
}
public double getRadium() {
return radiums;
}
public void setRadium(double radium) {
this.radiums = radium;
}
public Point getPoint() {
return point;
}
public void setPoint(Point point) {
this.point = point;
}
public double getLength(){ //周长
return 2*Math.PI*radiums;
}
public double getArea(){ //面积
return Math.PI*Math.pow(radiums, 2);
}
}
public class Point {
private int x; //x轴
private int y; //y轴
public Point(int x, int y) {
super();
this.x = x;
this.y = y;
}
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
}
public class Test {
public static void main(String[] args) {
Point point = new Point(14,16); //设置坐标
Circle circle = new Circle(5, point); //创建一个圆
double area = circle.getArea();
double length = circle.getLength();
System.out.println("圆的面积是:"+area);
System.out.println("圆的周长是:"+length);
System.out.println("圆的x坐标是: "+point.getX());
System.out.println("圆的y坐标是:"+point.getY());
}
}
输出结果如下:
圆的面积是:78.53981633974483
圆的周长是:31.41592653589793
圆的x坐标是: 14
圆的y坐标是:16
import java.util.Comparator;
public class Student implements ComparableStudent {
private int no;
private String name;
private String sex;
private int roomNo;
private double score;
public Student(int no, String name, String sex, int roomNo, double score) {
this.no = no;
this.name = name;
this.sex = sex;
this.roomNo = roomNo;
this.score = score;
}
public Student(int no, String name, String sex, double score) {
this.no = no;
this.name = name;
this.sex = sex;
this.score = score;
}
public int getNo() {
return no;
}
public void setNo(int no) {
this.no = no;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public int getRoomNo() {
return roomNo;
}
public void setRoomNo(int roomNo) {
this.roomNo = roomNo;
}
public double getScore() {
return score;
}
public void setScore(double score) {
this.score = score;
}
@Override
public int compareTo(Student o) {
if (this.no o.no) return 1;
else if (this.no o.no) return -1;
else return 0;
}
@Override
public String toString() {
return "Student{" +
"no=" + no +
", name='" + name + '\'' +
", sex='" + sex + '\'' +
", roomNo=" + roomNo +
", score=" + score +
'}';
}
}
//性别比较器类
class SexComparator implements ComparatorStudent {
@Override
public int compare(Student o1, Student o2) {
if (o1.getSex()点抗 pareTo(o2.getSex()) 0) return 1;
else if (o1.getSex()点抗 pareTo(o2.getSex()) 0) return -1;
else return 0;
}
}
//寝室号比较器类
class RoomNoComparator implements ComparatorStudent {
@Override
public int compare(Student o1, Student o2) {
if (o1.getRoomNo() o2.getRoomNo()) return 1;
else if (o1.getRoomNo() o2.getRoomNo()) return -1;
else return 0;
}
}
//入学成绩比较器类
class ScoreComparator implements ComparatorStudent {
@Override
public int compare(Student o1, Student o2) {
if (o1.getScore() o2.getScore()) return 1;
else if (o1.getScore() o2.getScore()) return -1;
else return 0;
}
}
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class TestStudent {
public static void main(String[] args) {
Student s1 = new Student(1, "jack", "boy", 90);
Student s2 = new Student(5, "jack", "boy", 90);
Student s3 = new Student(4, "jack", "boy", 90);
Student s4 = new Student(2, "jack", "boy", 90);
ListStudent studentList=new ArrayList();
studentList.add(s1);
studentList.add(s2);
studentList.add(s3);
studentList.add(s4);
Collections.sort(studentList);
System.out.println(Arrays.toString(studentList.toArray()));
}
}