Java黑皮书课后题第9章:*9.11(代数:2*2的线性方程)为一个2*2的线性方程设计一个名为LinearEquation的类
生活随笔
收集整理的這篇文章主要介紹了
Java黑皮书课后题第9章:*9.11(代数:2*2的线性方程)为一个2*2的线性方程设计一个名为LinearEquation的类
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
Java黑皮書課后題第9章:*9.11(代數(shù):2*2的線性方程)為一個2*2的線性方程設(shè)計一個名為LinearEquation的類
- 題目
- 破題
- 代碼
- Test10
- Test11_LinearEquation
- 運行結(jié)果
- UML圖
題目
破題
Test11:測試程序
Test11_LinearEquation:實現(xiàn)題目要求
點擊跳轉(zhuǎn)練習(xí)題3.3
代碼
Test10
import java.util.Scanner;public class Test11 {public static void main(String[] args) {// 獲取用戶輸入Scanner input = new Scanner(System.in);System.out.println("Enter a, b, c, d, e, f: ");double a = input.nextInt(), b = input.nextInt(), c = input.nextInt();double d = input.nextInt(), e = input.nextInt(), f = input.nextInt();// 傳入構(gòu)造方法Test11_LinearEquation le = new Test11_LinearEquation(a, b, c, d, e, f);// 判斷是否有結(jié)果boolean bool = le.isSolvable();if (bool){System.out.println("x is " + le.getX() + " and y is " + le.getY());} elseSystem.out.println("The equation has no solution");} }Test11_LinearEquation
public class Test11_LinearEquation {private double a, b, c, d, e, f;// 構(gòu)造方法public Test11_LinearEquation (double a, double b, double c, double d, double e, double f){this.a = a;this.b = b;this.c = c;this.d = d;this.e = e;this.f = f;}// getterpublic double getA() {return a;}public double getB() {return b;}public double getC() {return c;}public double getD() {return d;}public double getE() {return e;}public double getF() {return f;}// isSolvable方法public boolean isSolvable(){boolean bool = false;if (a * d - b * c != 0){bool = true;}return bool;}// getX和getYpublic double getX(){return (e * d - b * f) / (a * d - b * c);}public double getY(){return (a * f - e * c) / (a * d - b * c);} }運行結(jié)果
Enter a, b, c, d, e, f: 1 2 3 4 5 6 x is -4.0 and y is 4.5UML圖
總結(jié)
以上是生活随笔為你收集整理的Java黑皮书课后题第9章:*9.11(代数:2*2的线性方程)为一个2*2的线性方程设计一个名为LinearEquation的类的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Java黑皮书课后题第9章:*9.10(
- 下一篇: vs2013配置opencv2.4.9后