第六章作业

简易购房商贷月供计算器

public class Calculate {
    public double lone;
    public int yearchoice;
    public int yc;
    public double interestRate;
    public double monthlyPayment;

    public void Calculate(double lone,int yearchoice) {

        if (yearchoice == 1) {
            yc = 36;
            interestRate = 0.0603;
        }
        if (yearchoice == 2) {
            yc = 60;
            interestRate = 0.0612;
        }
        if (yearchoice == 3) {
            yc = 240;
            interestRate = 0.0639;
        }
        monthlyPayment = (lone + (lone * interestRate)) / yc;
    }

    public double getMonthlyPayment() {
        return monthlyPayment;
    }
}
import java.util.Scanner;

public class HomeBuyersAgentCalculator {

    public static void main(String[] args) {
        Calculate a = new Calculate();
        System.out.print("请输入贷款金额:");
        Scanner input = new Scanner(System.in);
        a.lone = input.nextDouble();
        System.out.println("请选择贷款年限:");
        a.yearchoice = input.nextInt();
        a.Calculate(a.lone, a.yearchoice);
        System.out.println("***月供为:" + a.getMonthlyPayment());
    }

}

判断三角形

public class JudgeTheTriangle {
    public int a;
    public int b;
    public int c;
    public boolean determineWhetherItIsATriangle(int a,int b,int c){
        if (a + b > c && a + c > b&&b + c > a){
            return true;
        } else {
            System.out.println("不是三角形!");
            return false;
        }
    }
    public void judgeWhatKindOfTriangle(int a,int b,int c){
        if (a == b&&b == c){
            System.out.println("三角形是等边三角形");
        } else if ((a * a) == ((b * b) +(c * c))||(b * b) == ((a * a) +(c * c))||(c * c) == ((b * b) +(a * a))){
            System.out.println("三角形为直角三角形");
        } else if ((a * a) > ((b * b) +(c * c))||(b * b) > ((a * a) +(c * c))||(c * c) > ((b * b) +(a * a))){
            System.out.println("三角形为钝角三角形");
        } else {
            System.out.println("三角形为锐角三角形");
        }
    }
}

import java.util.Scanner;

public class Triangle {
    public static void main(String[] args) {
        boolean i = true;
        while (i){
            Scanner input = new Scanner(System.in);
            JudgeTheTriangle first = new JudgeTheTriangle();
            System.out.println("请输入第一条边");
            first.a = input.nextInt();
            System.out.println("请输入第二条边");
            first.b = input.nextInt();
            System.out.println("请输入第三条边");
            first.c = input.nextInt();
            if (first.determineWhetherItIsATriangle(first.a, first.b, first.c)){
                first.judgeWhatKindOfTriangle(first.a, first.b, first.c);
            }
            System.out.println("继续吗?(Y/N)");
            if (input.next().equals("N")) {
                i = false;
            }
        }
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值