实验3创建复数类+声明银行账户类Account+增加功能的Student类

创建复数类

public class K334 {
	public static void main(String[] args) {
		Complex co1 = new Complex(3, 5);
		System.out.println(co1.GouZhaoFuShu());
		Complex co2 = new Complex(3, -5);
		System.out.println(co2.GouZhaoFuShu());
		System.out.println(co1.FuShuJiaFa(co2));
		System.out.println(co1.FuShuJianFa(co2));
		System.out.println(co1.equals(co2));
		System.out.println(co1.JiSuanMo());
	}

}

class Complex {
	int i;
	int j;
	Complex co3;
	String fu;

	public Complex(int i, int j) {
		this.i = i;
		this.j = j;
		if (j > 0 && i > 0)
			fu = i + "i" + "+" + j + "j";
		else if (i != 0 && j < 0)
			fu = i + "i" + j + "j";
		else if (i != 0 && j == 0)
			fu = i + "i";
		else if (i == 0 && j != 0)
			fu = j + "j";
		else
			fu = "0";
	}

	public String GouZhaoFuShu() {
		return fu;
	}

	public String FuShuJiaFa(Complex co) {
		this.co3 = new Complex(co.i + this.i, co.j + this.j);
		return this.co3.fu;

	}

	public String FuShuJianFa(Complex co) {
		this.co3 = new Complex(co.i - this.i, co.j - this.j);
		return this.co3.fu;
	}

	@Override
	public String toString() {
		return "Complex [i=" + i + ", j=" + j + "]";
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Complex other = (Complex) obj;
		if (i != other.i)
			return false;
		if (j != other.j)
			return false;
		return true;
	}

	public double JiSuanMo() {
		return Math.sqrt(i * i + j * j);
	}
}

声明银行账户类Account

import java.util.Scanner;

public class j_35 {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		System.out.println("请依次输入身份证号,姓名,账户号,密码,开户时间,余额");
		Account acc = new Account(scan.next(),scan.next(),scan.nextInt(),scan.nextInt(),scan.next(),scan.nextDouble());
		while (true) {
			System.out.println("---欢迎进入银行账户操作系统---");
			System.out.println("---------1银行账户信息--------");
			System.out.println("---------2取款操作------------");
			System.out.println("---------3存款操作------------");
			System.out.println("---------4退出系统------------");
			System.out.println("------------------------------");
			int choice = scan.nextInt();
			switch (choice) {
			case 1:
				System.out.println("---银行账户信息---");
				acc.Display();
				break;
			case 2:
				System.out.println("---取款操作---");
				acc.takeMoney();
				break;
			case 3:
				System.out.println("---存款操作---");
				acc.saveMoney(1000);
				break;
			case 4:
				System.exit(0);
				break;
			default:
				System.out.println("您的选择有误!");
				break;
			}
		}
	}
}

class Account {
	int password, ID;
	String nameId, name, time;
	double money;

	public Account(String nameId, String name, int ID, int password,
			String time, double deposit) {
		this.nameId = nameId;
		this.name = name;
		this.time = time;
		this.ID = ID;
		this.password = password;
		money = deposit;
	}

	// 方法Display(),显示账户的账号、姓名和余额信息
	public void Display() {
		System.out.println("账户:" + ID);
		System.out.println("姓名:" + name);
		System.out.println("开户时间" + time);
		System.out.println("余额:" + money);
	}

	// 取款方法 takeMoney(),先让用户输入密码验证, 密码正确后输入取款金额,取款成功后余额减除相应的金额
	public void takeMoney() {
		while (true) {
			Scanner scan = new Scanner(System.in);
			System.out.println("请输入密码进行验证!");
			int pass = scan.nextInt();
			if (pass == password) {
				System.out.println("请输入需要取款的金额:");
				int withdrawals = scan.nextInt();
				if (withdrawals <= money) {
					money = money - withdrawals;
					System.out.println("账户余额:" + money);
				} else {
					System.out.println("当前余额不足!");
				}
				break;
			} else {
				System.out.println("你输入的密码有误,请重新输入!");
			}
			scan.close();
		}
	}

	// 存款方法 saveMoney(int moneys), 存款是直接传入存款金额,账户余额增加相应的金额
	public void saveMoney(int inmoney) {
		money = money + inmoney;
		System.out.println("此次存款为:" + inmoney);
		System.out.println("账户余额:" + money);
	}
}

增加功能的Student类

import java.util.ArrayList;

public class k340 {
	public static void main(String[] args) {

		ArrayList<Student> st = new ArrayList<Student>();
		st.add(new Student("wangluo", 1, "du", "20180105", "tengzhou", 80, 90));
		for (int i = 0; i < st.size(); i++) {
			st.get(i).chazhaobirthiday(st, "20180105");
		}

	}

}

class Student {
	static int wangluo1 = 20181001;
	static int wangluo2 = 20182001;
	static int xingong1 = 20183001;
	static int xingong2 = 20184001;
	String zhuanye;
	int nianji;
	int id;
	String name;
	String birthday;
	String diqu;
	int grade1;
	int grade2;

	public Student(String zhuanye, int nianji, String name, String birthday,
			String diqu, int grade1, int grade2) {
		this.grade1 = grade1;
		this.grade2 = grade2;
		this.zhuanye = zhuanye;
		this.nianji = nianji;
		this.name = name;
		this.diqu = diqu;
		this.birthday = birthday;
		if ((zhuanye + nianji).equals("wangluo1")) {
			id = wangluo1++;
		}
		if ((zhuanye + nianji).equals("wangluo2")) {
			id = wangluo2++;
		}
		if ((zhuanye + nianji).equals("xingong1")) {
			id = xingong1++;
		}
		if ((zhuanye + nianji).equals("xingong2")) {
			id = xingong2++;
		}
	}

	public void chazhaoname(ArrayList<Student> st, String name) {
		for (int i = 0; i < st.size(); i++) {
			if (st.get(i).name.substring(0, 1).equals(name)) {
				System.out.println(st.get(i).name);
			}
		}
	}

	public void chazhaobirthiday(ArrayList<Student> st, String birthday) {
		for (int i = 0; i < st.size(); i++) {
			if (st.get(i).birthday.equals(birthday)) {
				System.out.println(st.get(i).name + "," + st.get(i).birthday);
			}
		}
	}

	public void chazhaodiqu(ArrayList<Student> st, String diqu) {
		for (int i = 0; i < st.size(); i++) {
			if (st.get(i).diqu.equals(diqu)) {
				System.out.println(st.get(i).name + "," + st.get(i).diqu);
			}
		}
	}

	public void tongji(ArrayList<Student> st) {
		System.out.println("wangluo de grade");
		for (int i = 0; i < st.size(); i++) {
			if (st.get(i).zhuanye.equals("wangluo")) {
				System.out.println(st.get(i).name + ":" + st.get(i).grade1
						+ "," + st.get(i).grade2);
			}
		}
	}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Lales_胜

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值