一、银行存取款
import java.util.Scanner;
public class Bank{
//接收键盘数据
private Scanner sc = new Scanner(System.in);
//账号
public int zhanghao;
//姓名
public String name;
//地址
public String dizhi;
//余额
public float lastmoney;
//最小余额
public float lowmoney;
bank(int zhanghao,String name,String dizhi,float lastmoney,float lowmoney){
this.setzhanghao(zhanghao);
this.setname(name);
this.setdizhi(dizhi);
this.setlastmoney(lastmoney);
this.setlowmoney(lowmoney);
this.operation();
}
public void setzhanghao(int zhanghao){
this.zhanghao=zhanghao;
}
public void setname(String name){
this.name=name;
}
public void setdizhi(String dizhi){
this.dizhi=dizhi;
}
public void setlastmoney(float lastmoney){
this.lastmoney=lastmoney;
}
public void setlowmoney(float lowmoney){
this.lowmoney=lowmoney;
}
public void print(){
System.out.println("Name="+name+"余额="+lastmoney+"最小余额"+lowmoney);
}
//存钱
public void cunqian(){
System.out.println("您要存的钱数?");
double d = sc.nextDouble();
lastmoney+=d;
System.out.println("成功存入="+d);
}
//取钱
public void quqian(){
System.out.println("您要取出的钱数");
double d1 = sc.nextDouble();
double bijiao;
bijiao=lastmoney-d1;
if(bijiao>=lowmoney)
lastmoney-=d1;
else
System.out.println("错误,银行卡内钱数不得少于="+lowmoney);
}
//主页面
public void operation() {
System.out.println("请选择菜单项:");
System.out.println("1、查询余额:");
System.out.println("2、取款:");
System.out.println("3、存款:");
System.out.println("4、退出:");
switch (sc.nextInt()) {
case 1:
//获取账户余额
this.print();
operation();
break;
case 2:
//取款
quqian();
operation();
break;
case 3:
//存款
cunqian();
operation();
break;
case 4:
break;
}
}
public static void main(String[] args){
//内部建立的数据
bank one=new bank(110,"chenlin","xiaoheiwu",18000,10);
}
}
运行结果:
二、车辆类型
public class car{
//速度
public int speed;
//种类
public String kind;
//颜色
public String color;
public int getspeed(){
return speed;
}
public void setspeed(int speed){
this.speed=speed;
}
public String getkind(){
return kind;
}
public void setkind(String kind){
this.kind=kind;
}
public String getcolor(){
return color;
}
public void setcolor(String color){
this.color=color;
}
public static void main(String[] args){
car car1=new car();
car1.setcolor("blue");
car1.setkind("cars");
car1.setspeed(120);
System.out.println(car1.getkind());
System.out.println(car1.getcolor());
System.out.println(car1.getspeed());
}
}
运行结果:
三、家庭住址
public class address{
//省
static String province;
//市
static String city;
//街道
static String street;
//门牌号
static String DoorNumber;
//邮编
static String ZipCode;
public static String getProvince() {
return province;
}
public void setProvince(String province) {
this.province = province;
}
public static String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public static String getStreet() {
return street;
}
public void setStreet(String street) {
this.street = street;
}
public static String getDoorNumber() {
return DoorNumber;
}
public void setDoorNumber(String DoorNumber) {
this.DoorNumber = DoorNumber;
}
public static String getZipCode() {
return ZipCode;
}
public void setZipCode(String ZipCode) {
this.ZipCode = ZipCode;
}
public static void main(String[] args){
address addr=new address();
addr.setProvince("陕西省");
addr.setCity("宝鸡市");
addr.setStreet("东关街");
addr.setDoorNumber("10023");
addr.setZipCode("721400");
System.out.println("省份:"+getProvince());
System.out.println("City:"+getCity());
System.out.println("街道:"+getStreet());
System.out.println("门牌号:"+getDoorNumber());
System.out.println("邮编:"+getZipCode());
}
}
运行结果: