JAVA大作业

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

import java.util.Scanner;

/*四则运算*/

class arithmetic{

privatedouble n1;

privatedouble n2;

publicdouble getN1() {

return n1;

}

publicvoid setN1(double n1) {

this.n1 = n1;

}

publicdouble getN2() {

return n2;

}

publicvoid setN2(double n2) {

this.n2 = n2;

}

double subtration(double n1,double n2){ return n1-n2;

}

double addition(double n1,double n2){

return n1+n2;

}

double multiplication(double n1,double n2){ return n1*n2;

}

double division(double n1,double n2){

return n1/n2;

}

public arithmetic(double n1,double n2){ this.getN1();

this.getN2();

}

}

/*计算三角函数值*/

class TriFun{

privatedouble x;

publicdouble getX() {

return x;

}

publicvoid setX(double x) {

this.x = x;

}

publicvoid sin(){

System.out.println("正弦值为"+Math.sin(x));

}

publicvoid cos(){

System.out.println("余弦值为"+Math.cos(x));

}

publicvoid tan(){

System.out.println("正切值为"+Math.tan(x));

}

publicvoid asin(){

if(x>=-1&&x<=1)

System.out.println("反正弦值为"+Math.asin(x));

else

System.out.println("没有反正弦值!");

}

publicvoid acos(){

if(x>=-1&&x<=1)

System.out.println("反余弦值为"+Math.asin(x));

else

System.out.println("没有反余弦值!");

}

publicvoid atan(){

if(x!=0)

System.out.println("反正切值为"+Math.atan(x));

else

System.out.println("反正切值为PI/2="+Math.PI/2); }

public TriFun(double x){

this.x=x;

}

}

/*一元二次方程求解*/

class LinearEquation{

double a, b, c;

publicdouble getA() {

return a;

}

publicvoid setA(double a) {

this.a = a;

}

publicdouble getB() {

return b;

}

publicvoid setB(double b) {

this.b = b;

}

publicdouble getC() {

return c;

}

publicvoid setC(double c) {

this.c = c;

}

public LinearEquation(double a,double b,double c){ this.a=a;

this.b=b;

this.c=c;

}

publicvoid Answer(){

double i;

double x1 = 0;

double x2 = 0;

i = b*b-4*a*c;

if (i>= 0) {

x1 = ((-b) + Math.sqrt(i)) / 2 * a;

x2 = ((-b) - Math.sqrt(i)) / 2 * a;

System.out.println("x1="+x1);

System.out.println("x2="+x2);

}

else

System.out.println("方程没有实数解!\n");

}

}

/*一元三次方程*/

class LinEquation extends LinearEquation{

privatedouble d;

publicdouble getD() {

return d;

}

publicvoid setD(double d) {

this.d = d;

}

public LinEquation(double a, double b, double c,double d) { super(a, b, c);

this.d=d;

}

publicvoid QiuJie(){

System.out.println("x1+x2+x3 ="+(-b/a));

System.out.println("1/x1+1/x2+1/x3 ="+(-c/d));

System.out.println("x1*x2*x3 ="+(-d/a));

System.out.println("请根据上述提示自行计算!\n");

}

}

/*阶乘和m的n次方求解*/

interface factorialandPower{

long fact(double m);

long intPower(double m,double n);

}

class Calu implements factorialandPower{

double m,n;

相关文档
最新文档