瑞瑞牌计算器

package compute01;

public class Computed {

	public double computed(Double num1, Double num2,String type) {
		//计算方法
		double jieguo = 0;
		switch (type) {
		case "+":
			jieguo = num1 + num2;
			break;
		case "-":
			jieguo = num1 - num2;
			break;
		case "*":
			jieguo = num1 * num2;
			break;
		case "/":
			jieguo = num1 / num2;
			break;
		default:
			System.out.println("输入有误!");
			break;
		}
		return jieguo;
	}
}
主方法:
package compute01;

import java.io.StreamCorruptedException;
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Computed a = new Computed();
		String[] history = new String[100];
		System.out.println("******瑞瑞牌计算器******");
		while (true) {
		
			System.out.println("请选择功能:1、进行计算2、查看记录3、关机");
			int choose = sc.nextInt();
			switch (choose) {
			case 1:
				System.out.println("欢迎使用计算器(计算功能)");
				System.out.println("请输入第一个数字:");
				double num1 = sc.nextDouble();
				System.out.println("请输入第二个数字:");
				double num2 = sc.nextDouble();
				System.out.println("请输入算法:");
				String type = sc.next();
				if(history[history.length-1] != null) {
					history = new String[100];
				}
				String scr = num1 + type + num2 + "=" + a.computed(num1, num2, type);
				System.out.println(scr);
				for (int i = 0; i < history.length; i++) {
					if (history[i] == null) {
						history[i] = scr;
						break;
					}
				}
				break;
			case 2:
				String asd = "";
				for (int i = 0; i < history.length; i++) {
					if (history[i] != null) {
						asd += history[i] + ",";
					}
				}
				System.out.println(asd.substring(0, asd.length() - 1));
				break;
			case 3:
				System.exit(0);
			}
		}
	}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值