第六章章节练习
Posted fkkkkk
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了第六章章节练习相关的知识,希望对你有一定的参考价值。
第一题
1 package com.kgc.zzlx; 2 3 public class Zj6011 { 4 String brand; 5 public Zj6011(){ 6 this.brand="诺基亚"; 7 } 8 public Zj6011(String bra){ 9 this.brand=bra; 10 } 11 public String buy(){ 12 return "没发工资,买一个"+brand+"牌子的手机吧"; 13 } 14 public String buy(String reason){ 15 return reason+",买一个"+brand+"牌子的手机吧"; 16 } 17 }
1 package com.kgc.zzlx; 2 3 public class Zj6012 { 4 public static void main(String[] args){ 5 Zj6011 zj=new Zj6011(); 6 System.out.println(zj.buy()); 7 8 zj.brand="苹果"; 9 String detail=zj.buy("发工资拉"); 10 System.out.println(detail); 11 12 13 } 14 }
第二题
1 package com.kgc.zzlx; 2 3 public class Zj6021 { 4 int daikuan; 5 double lilv; 6 int year; 7 int yueshu; 8 public Zj6021(int daikuan,double lilv,int year,int yueshu){ 9 this.daikuan=daikuan; 10 this.lilv=lilv; 11 this.year=year; 12 this.yueshu=yueshu; 13 } 14 //总利息=贷款金额*利率6.03 6.12 6.39 15 public double lixi(){ 16 double zonglixi=daikuan*lilv*year; 17 return zonglixi; 18 } 19 20 21 //每月还款金额=贷款金额+总利息)/贷款年限 22 public double loan(){ 23 double huankuan=(daikuan+lixi())/yueshu; 24 return huankuan; 25 } 26 27 }
1 package com.kgc.zzlx; 2 3 import java.util.Scanner; 4 5 public class Zj6022 { 6 public static void main(String[] args){ 7 Scanner sc=new Scanner(System.in); 8 9 10 System.out.print("请输入贷款金额:"); 11 int daikuan=sc.nextInt(); 12 System.out.println("请选择还款年限:1.3年(36个月) 2.5年(60个月) 3.20年(240个月)"); 13 int xz=sc.nextInt(); 14 double lilv=0.0; 15 int year=0; 16 int yueshu=0; 17 if (xz==1){ 18 lilv=0.0603; 19 year=3; 20 yueshu=36; 21 }else if(xz==2){ 22 lilv=0.0612; 23 year=5; 24 yueshu=60; 25 }else if (xz==3){ 26 lilv=0.0639; 27 year=20; 28 yueshu=240; 29 } 30 Zj6021 zj=new Zj6021(daikuan,lilv,year,yueshu); 31 System.out.println("总利息是:"+zj.lixi()+"元,每个月利息是"+(zj.lixi()/yueshu)+"元"); 32 System.out.println("每月还款金额是:"+zj.loan()+"元"); 33 } 34 }
第三题
1 package com.kgc.zzlx; 2 3 public class Zj6031 { 4 5 6 7 //判断是否为三角形 8 public boolean is(int a,int b,int c){ 9 boolean flag=false; 10 if (a+b>c && a+c>b && b+c>a){ 11 return true; 12 }else{ 13 System.out.println("不能成为三角形"); 14 } 15 return flag; 16 } 17 18 //判断是什么三角形 19 public String shape(int a,int b,int c){ 20 String shape=""; 21 if (a==(b+c)&& b==(a+c)&& c==(a+b)){ 22 shape="这是直角三角形"; 23 }else if (a>(b+c) && b>(a+c) && c>(a+b)){ 24 shape="这是钝角三角形"; 25 }else if (a<(b+c) && b<(a+c) && c<(a+b)){ 26 shape="这是锐角三角形"; 27 } 28 return shape; 29 } 30 }
1 package com.kgc.zzlx; 2 3 import java.util.Scanner; 4 5 public class Zj6032 { 6 public static void main(String[] args) { 7 Scanner sc = new Scanner(System.in); 8 Zj6031 zj = new Zj6031(); 9 String ies = ""; 10 11 do { 12 System.out.print("请输入第一条边长:"); 13 int a = sc.nextInt(); 14 System.out.print("请输入第二条边长:"); 15 int b = sc.nextInt(); 16 System.out.print("请输入第三条边长:"); 17 int c = sc.nextInt(); 18 zj.is(a, b, c); 19 System.out.println(""); 20 ; 21 System.out.println(zj.shape(a, b, c)); 22 23 System.out.println("继续吗(y/n)?"); 24 ies = sc.next(); 25 } while (ies.equals("y")); 26 } 27 }
以上是关于第六章章节练习的主要内容,如果未能解决你的问题,请参考以下文章