实验报告。。。。。

机动车

public class User {
	public static void main(String[] args) {
		Vehicle v = new Vehicle();
		System.out.println("设置功率大小:");
		v.setPower(36);
		System.out.println("功率大小为:" + v.getPower() + "kw");
		v.speedUp(80);
		v.speedDown();
	}
}
public class Vehicle {
	double speed;
	int power;

	public void speedUp(int s) {
		speed = s;
		System.out.println("加速至" + s + "km/h");
	}

	public void speedDown() {
		System.out.println("减速");
	}

	public double getSpeed() {
		return speed;
	}

	public int getPower() {
		return power;
	}

	public void setPower(int p) {
		this.power = p;
	}

电视

public class TV {
	int channel;

	void setChannel(int m) {
		if (m > 0) {
			channel = m;
		}
	}

	int getChannel() {
		return channel;
	}

	void show() {
		switch (channel) {
		case 1:
			System.out.println("少儿频道");
			break;
		case 2:
			System.out.println("经济频道");
			break;
		case 3:
			System.out.println("电影频道");
			break;
		case 4:
			System.out.println("央视频道");
			break;
		case 5:
			System.out.println("体育频道");
			break;
		default:
			System.out.println("无法收看" + channel + "频道");

		}
	}

}
public class Family {
	TV homeTV;

	void buyTV(TV tv) {
		homeTV = tv;
	}

	void remoteControl(int m) {
		homeTV.setChannel(m);
	}

	void seeTV() {
		homeTV.show();
	}

}
public class MainClass {
	public static void main(String[] args) {
		TV haierTV = new TV();
		haierTV.setChannel(5);
		System.out.println("haierTV的频道是" + haierTV.getChannel());
		Family zhangSanFamily = new Family();
		zhangSanFamily.buyTV(haierTV);
		System.out.println("zhangSanFamily开始看电视节目");
		zhangSanFamily.seeTV();
		int m = 2;
		System.out.println("zhangSanFamily将电视更换到" + m + "频道");
		zhangSanFamily.remoteControl(m);
		System.out.println("haierTV的频道是" + haierTV.getChannel());
		System.out.println("zhangSanFamily再看电视节目");
		zhangSanFamily.seeTV();
	}
}

饮水。。。。

求根

package tom.jiafei;
 
public class SquareEquation {
    double a,b,c;
    double root1,root2;
    boolean flag;
    public SquareEquation(double a, double b,double c){
        this.a = a;
        this.b = b;
        this.c = c;
        if(a!=0)
            flag=true;
        else
            flag=false;
    }
    public void getRoots(){
        if(flag){
            System.out.println("是一元2次方程");
            double disk = b*b-4*a*c;
            if(disk>=0){
                root1=(-b+Math.sqrt(disk))/(2*a);
                root2=(-b-Math.sqrt(disk))/(2*a);
                System.out.println("方程的根:"+root1+","+root2);
            }
            else {
                System.out.printf("方程没有实根\n");
            }
        }
        else {
            System.out.println("不是一元2次方程");
        }
    }
    public void setCoefficient(double a, double b, double c){
        this.a=a;
        this.b=b;
        this.c=c;
        if(a!=0)
            flag=true;
        else
            flag=false;
    }
}
package testqiugen.com;

import tom.jiafei.*;

public class SunRise {

	public static void main(String[] args) {
		SquareEquation equation = new SquareEquation(4, 5, 1);
		equation.getRoots();
		equation.setCoefficient(-3, 4, 5);
		equation.getRoots();
	}
}

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值