//簡答題 第二題 計算器
package cn.jbit.test.JianDaTi;

public class testCalculator {
	public static void main(String[] args) {
		Calculator calcu = new Calculator();// 例項化
		calcu.Show();// 呼叫業務處理方法
	}
}

package cn.jbit.test.JianDaTi;

import java.util.Scanner;

public class Calculator {

	public void Show() {// 業務處理
		Scanner input = new Scanner(System.in);
		System.out.println("請選擇運算:1.加法 2.減法  3.乘法 4.除法:");
		int op = input.nextInt();
		int b = 0;// 記錄次數
		for (int i = 0; i < 3; i++) {
			if (op != 1 && op != 2 && op != 3 && op != 4) {// 判斷輸入數字是否非法
				System.out.println("您的輸入有誤,請輸入1~4任意整數");
				op = input.nextInt();// 接收
				b = i;
				continue;
			} else {
				System.out.println("請輸入第一個數:");
				double num1 = input.nextDouble();
				System.out.println("請輸入第二個數:");
				double num2 = input.nextDouble();
				System.out.print("***運算結果是:" + Open(op, num1, num2));
				break;
			}
		}
		if (b == 2) {// 判斷
			System.out.println("輸入錯誤已滿,退出系統,謝謝您的使用!");
		}
	}

	public double Open(int op, double num1, double num2) {// 呼叫運算方法
		if (op == 1) {// 輸入1 呼叫加法
			return Add(num1, num2);
		} else if (op == 2) {// 輸入2 呼叫減法
			return Minus(num1, num2);
		} else if (op == 3) {// 輸入3 呼叫乘法
			return Multiple(num1, num2);
		} else if (op == 4) {// 輸入4 呼叫除法
			return Divide(num1, num2);
		}
		return 0;
	}

	public double Add(double num1, double num2) {// 加法
		return (num1 + num2);
	}

	public double Minus(double num1, double num2) {// 減法
		return (num1 - num2);
	}

	public double Multiple(double num1, double num2) {// 乘法
		return (num1 * num2);
	}

	public double Divide(double num1, double num2) {// 除法
		return (num1 / num2);
	}
}

package cn.jbit.test.JianDaTi;

public class testTest3 {
	public static void main(String[] args) {
		// 簡答題3 模擬簡單的貸款月供計算器
		Test3 test = new Test3(); // 例項化
		test.Show();// 呼叫Show方法
	}
}
package cn.jbit.test.JianDaTi;

import java.util.Scanner;

public class Test3 {

	public void Show() {// 定義初始方法
		Scanner input = new Scanner(System.in);
		System.out.println("請輸入貸款金額:");
		double loan = input.nextDouble();// 貸款金額
		System.out.println("請選擇貸款年限:1.3年(36個月)   2.5年(60個月)   3.20年(240個月)");
		int yearchoice = input.nextInt();// 貸款年限
		int j = 0;// 紀錄輸入次數
		for (int i = 0; i < 3; i++) {
			j = i;
			if (yearchoice == 1) {
				System.out.println("您輸入的貸款金額是:" + loan + "元" + "\t"
						+ "您選擇的貸款年限是:" + "3年(36個月)" + "\n" + "\n" + "***您的月供是:"
						+ loan(loan, yearchoice) + "元");
				break;
			}
			if (yearchoice == 2) {
				System.out.println("您輸入的貸款金額是:" + loan + "元" + "\t"
						+ "您選擇的貸款年限是:" + "5年(60個月)" + "\n" + "\n" + "***您的月供是:"
						+ loan(loan, yearchoice) + "元");
				break;
			}
			if (yearchoice == 3) {
				System.out.println("您輸入的貸款金額是:" + loan + "元" + "\t"
						+ "您選擇的貸款年限是:" + "20年(240個月)" + "\n" + "\n"
						+ "***您的月供是:" + loan(loan, yearchoice) + "元");
				break;
			} else {
				System.out.println("您的輸入有誤,請輸入1~3任意整數");
				yearchoice = input.nextInt();
				continue;
			}
		}
		if (j == 2) {
			System.out.println("輸入錯誤次數已滿,退出系統,謝謝您的使用!!");
		}
	}

	private double loan(double loan, int yearchoice) {// 定義loan方法 計算month 月供
		if (yearchoice == 1) {
			double month = (loan * 6.03 / 100 + loan) / 36;// 36個月月供
			return month;
		}
		if (yearchoice == 2) {
			double month = (loan * 6.12 / 100 + loan) / 60;// 60個月月供
			return month;
		}
		if (yearchoice == 3) {
			double month = (loan * 6.39 / 100 + loan) / 240;// 240個月月供
			return month;
		}
		return 0;
	}
}
//第四題
//**** 原始程式碼片段無法執行
//錯誤1   沒有例項化
//錯誤2 方法呼叫錯誤
package cn.jbit.test.JianDaTi;

import java.util.*;

public class JavaTest {// 修改後程式碼片段
	public static void main(String[] args) {
		JavaTest java=new JavaTest();// 例項化
		Scanner input = new Scanner(System.in);
		System.out.print("請輸入第一個數:");
		int num1 = input.nextInt();
		System.out.print("請輸入第二個數:");
		int num2 = input.nextInt();
		System.out.print("兩數的平均值為:" + java.avg(num1, num2));
	}

	public int avg(int big, int small) {
		int money = 0;
		money = (big + small) / 2;
		return money;
	}
}


//第五題 三角形

package cn.jbit.test.JianDaTi;

public class testTriangle {

	public static void main(String[] args) {
		Triangle triangle = new Triangle();
		triangle.shaPe();
	}
}

package cn.jbit.test.JianDaTi;

import java.util.Scanner;

public class Triangle {
	public boolean isTriangle(int a, int b, int c) {// 判斷是否構成三角形
		if (a + b > c && a + c > b && b + c > a) {
			return true;
		}
		return false;
	}

	public void shaPe() {// 判斷構成何種三角形
		Scanner input = new Scanner(System.in);
		char d = 'y';// 判斷是否錄入學生資訊
		while (d == 'y') {
			System.out.println("請輸入第一條邊:");
			int a = input.nextInt();
			System.out.println("請輸入第二條邊:");
			int b = input.nextInt();
			System.out.println("請輸入第三條邊:");
			int c = input.nextInt();
			isTriangle(a, b, c);
			if (isTriangle(a, b, c) == false) {
				System.out.println("無法構成三角形");
			} else {
				if (a + b == c * c || a + c == b * b || b + c == a * a) {
					System.out.println("這是一個直角三角形");
				}
				if (a * a > b * b + c * c || b * b > a * a + c * c
						|| c * c > a * a + b * b) {
					System.out.println("這是一個鈍角三角形");
				} else {
					System.out.println("這是一個銳角三角形");
				}
			}
			System.out.println("繼續嗎?(y繼續,輸入y以外任意字元結束)");
			d = input.next().charAt(0);

		}

	}
}