- package cn.jbit.test;
- public class testCalculator {
- public static void main(String[] args) {
- Calculator calcu = new Calculator();// 实例化
- calcu.Show();// 调用业务处理方法
- }
- }
- package cn.jbit.test;
- 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;
- public class testTest3 {
- public static void main(String[] args) {
- // 简答题3 模拟简单的贷款月供计算器
- Test3 test = new Test3(); // 实例化
- test.Show();// 调用Show方法
- }
- }
- package cn.jbit.test;
- 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;
- 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);
- }
- }
- }