Java实验(6) 二次方程类

这篇博客介绍了一个名为QuadraticEquation的Java类,该类用于处理二次方程ax^2 + bx + c = 0。类中包含私有成员a、b、c,以及对应的getter方法。此外,还有计算判别式、获取根的方法。测试类验证了所有方法的正确性。
摘要由CSDN通过智能技术生成

设计一个二次方程类QuadraticEquation,用于处理形如ax2 + bx + x = 0 (a≠0)的二次方程,成员如下:

私有成员a, b, c用于存储系数;

含三个参数的构造方法,用于传入a, b, c;

三个方法getA(), getB(), getC(),用于传出系数;

一个方法getDiscriminant()用于传出b2 - 4ac的值;

两个方法getRoot1()和getRoot2()用来返回方程的两个根。注意方程可能没有实根,所以返回值定义为String。

请提供一个测试类,测试上述所有方法。

                                                                                 

<span 
  • 1
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Write a class called Person with the following attributes: title (Mr., Mrs., Ms., etc.) first name last name nickname age in years sex (boolean - true/false to indicated either male or female) Write a constructor that takes no parameters and performs no initializations. Write a constructor that takes a parameter for each of the attributes listed above and sets them within the objects by calling the setter methods listed below. The Person class should have a setter method and a getter method with public access for each attribute. In the setter methods, get rid of any leading or trailing spaces (String trim() method). For a Person with the following attributes: title = "Mr." first name = "Michael" last name = "Zheng" nickname = "Mike" age = 22 sex = true (true is male, false is female) The Person class should have the following public access methods that return Strings as follows: standardName() concatenation of the first and last names (i.e., "Michael Zheng") formalName() concatenation of the title, first name, lastname (i.e., "Mr. Michael Zheng") casualName() return the nickname if it is not null, otherwise return the first name (i.e., "Mike") Be realistic when generating names. If a particular attribute does not exist for a given person, don't try to concatenate it. If necessary, add appropriate spacing and punctuation, but do not leave any leading or trailing spaces in the String that is returned. MakePerson Write a class called MakePerson with a main() method that instantiates 2 Person objects. Initialize the attributes of one of the Person objects by supplying parameters to it's constructor. Instantiate the other Person object with the default constructor (that does not accept any parameters), then set it's attributes via the appropriate setter methods. For each of the Person objects, execute and print (System.out.println()) the results of all of the getter methods and of the standardName(), formalName(), and casualName() methods.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值