第九章第十题(代数:二次方程式)(Algebra: quadratic equation)

本文介绍了如何设计一个名为QuadraticEquation的Java类来处理二次方程,包括构造方法、获取系数的方法、计算判别式以及求根的方法。在测试程序中,用户输入二次方程的系数,程序将根据判别式的值显示相应的根。当判别式为非负数时,显示两个根;判别式为0时,显示一个根;否则提示方程无实数根。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

第九章第十题(代数:二次方程式)(Algebra: quadratic equation)

  • *9.10(代数:二次方程式)为二次方程式 在这里插入图片描述设计一个名为QuadraticEquation的类。这个类包括:

    • 代表三个系数的私有数据域a、b和c。
    • 一个参数为a、b和c的构造方法。
    • a、b、c的三个获取方法
    • 一个名为getDiscriminant()的方法返回判别式b2-4ac。
    • 名为getRoot1()和getRoot2()的方法返回灯饰的两个根:
      在这里插入图片描述
      这些方法只有在判别式为非负数时才有用。如果判别式为负,这些方法返回0.

    画出该类的UML图并实现这个类。编写一个测试程序,提示用户输入a、b和c的值,然后显示判别式的结果。如果判别式为整数,显示两个根;如果判别式为0,显示一个根;否则,显示“The equation has no roots”.参见编程练习题3.1的运行示例。
    *9.10(Algebra: quadratic equation)It is a quadratic equation在这里插入图片描述Design a class called quatraticequation. This class includes:

    • The private data fields a, B and C represent the three coefficients.
    • A construction method with parameters a, B and C.
    • Three acquisition methods of a, B and C
    • A method called getdiscriminator() returns the discriminant b2-4ac.
    • Methods named getroot1() and getroot2() return the two roots of the lighting:
      在这里插入图片描述

    These methods are only useful when the discriminant is nonnegative. If the discriminant is negative, these methods return 0
    Draw the UML diagram of the class and implement the class. Write a test program to prompt the user to input the values of a, B and C, and then display the results of the discriminant. If the discriminant is an integer, two roots will be displayed; if the discriminant is 0, one root will be displayed; otherwise, “the equation has no roots” will be displayed. See the running example of programming exercise 3.1.

  • 参考代码:

package chapter09;

public class Code_10 {
   
    public static void<
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值