java作业帮我做做啊 5
编写1个TubeLight类,该类是对管状灯的描述,它继承于Light类。还拥有:(1)2个成员变量tubeLength(私有,整型)//用于存放灯管的长度color(私...
编写1个TubeLight类,该类是对管状灯的描述,它继承于Light类。还拥有:
(1)2个成员变量
tubeLength(私有,整型) //用于存放灯管的长度
color(私有,String类型) //用于存放灯光的颜色
(2)构造器方法
TubeLight(int watts, int tubeLength,String color) //用于创建具有watts瓦,灯管长度为tugeLength,颜色为color的对象
(3)成员方法
public void printInfo() //打印输出灯的相关信息,包括瓦数、开关信息、长度以及颜色
解:
(4)请写一个测试程序,要求:
①创建一个管状灯的实例对象,该灯瓦数为:32;长度为50;白色灯光,状态为开。
②打印输出该灯的相关信息。
Linght类如下:
class Linght{
Private int watts;
Private Boolean indicator;
Linght(int watts){this.watts=watts;}
Light(int watts,Boolean indicator)
{
this.watts=watts;
this.indicator=indicator;}
public void switchOn()
{this.indicator=true;}
public void switchOff()
{this.indicator=false;}
pulic void printInfo(){
System.out.println(“watts=”+watts);
System.out.println(“indicator =”+ indicator);
}} 展开
(1)2个成员变量
tubeLength(私有,整型) //用于存放灯管的长度
color(私有,String类型) //用于存放灯光的颜色
(2)构造器方法
TubeLight(int watts, int tubeLength,String color) //用于创建具有watts瓦,灯管长度为tugeLength,颜色为color的对象
(3)成员方法
public void printInfo() //打印输出灯的相关信息,包括瓦数、开关信息、长度以及颜色
解:
(4)请写一个测试程序,要求:
①创建一个管状灯的实例对象,该灯瓦数为:32;长度为50;白色灯光,状态为开。
②打印输出该灯的相关信息。
Linght类如下:
class Linght{
Private int watts;
Private Boolean indicator;
Linght(int watts){this.watts=watts;}
Light(int watts,Boolean indicator)
{
this.watts=watts;
this.indicator=indicator;}
public void switchOn()
{this.indicator=true;}
public void switchOff()
{this.indicator=false;}
pulic void printInfo(){
System.out.println(“watts=”+watts);
System.out.println(“indicator =”+ indicator);
}} 展开
4个回答
展开全部
class Light{
private int watts;
private boolean indicator;
Light(int watts){this.watts=watts;}
Light(int watts,boolean indicator){
this.watts=watts;
this.indicator=indicator;}
public void switchOn()
{this.indicator=true;}
public void switchOff()
{this.indicator=false;}
public void printInfo(){
System.out.println("watts="+watts);
System.out.println("indicator ="+ indicator);
}
}
class TubeLight extends Light{
private int tubeLength;//用于存放灯管的长度
private String color;//用于存放灯光的颜色
//用于创建具有watts瓦,灯管长度为tugeLength,颜色为color的对象
TubeLight(int watts,int tubeLength,String color) {
super(watts);
this.tubeLength=tubeLength;
this.color=color;
}
//打印输出灯的相关信息,包括瓦数、开关信息、长度以及颜色
public void printInfo() {
super.printInfo();
System.out.println("tubeLength="+tubeLength);
System.out.println("Color ="+ color);
}
}
public class TestLight {
public static void main(String[] args) {
// TODO code application logic here
TubeLight tube=new TubeLight(32,50,"white");
tube.switchOn();
tube.printInfo();
}
}
private int watts;
private boolean indicator;
Light(int watts){this.watts=watts;}
Light(int watts,boolean indicator){
this.watts=watts;
this.indicator=indicator;}
public void switchOn()
{this.indicator=true;}
public void switchOff()
{this.indicator=false;}
public void printInfo(){
System.out.println("watts="+watts);
System.out.println("indicator ="+ indicator);
}
}
class TubeLight extends Light{
private int tubeLength;//用于存放灯管的长度
private String color;//用于存放灯光的颜色
//用于创建具有watts瓦,灯管长度为tugeLength,颜色为color的对象
TubeLight(int watts,int tubeLength,String color) {
super(watts);
this.tubeLength=tubeLength;
this.color=color;
}
//打印输出灯的相关信息,包括瓦数、开关信息、长度以及颜色
public void printInfo() {
super.printInfo();
System.out.println("tubeLength="+tubeLength);
System.out.println("Color ="+ color);
}
}
public class TestLight {
public static void main(String[] args) {
// TODO code application logic here
TubeLight tube=new TubeLight(32,50,"white");
tube.switchOn();
tube.printInfo();
}
}
展开全部
TubeLight类:
public class TubeLight extends Linght{
//私有成员变量
private int tubeLength;
private String color;
//构造方法
TubeLight(int watts,int tubeLenth, String color) {
super(watts);
this.tubeLength=tubeLenth;
this.color=color;
}
TubeLight(int watts,boolean indicator, int tubeLenth, String color) {
super(watts, indicator);
this.tubeLength=tubeLenth;
this.color=color;
}
//成员方法
public void printInfo(){
super.printInfo();
System.out.println("tubeLenth=" + this.tubeLength);
System.out.println("color=" + this.color);
}
}
测试程序:
public class Test {
public static void main(String[] args){
Linght lingth=new TubeLight(32,true,50,"white");
lingth.printInfo();
}
}
public class TubeLight extends Linght{
//私有成员变量
private int tubeLength;
private String color;
//构造方法
TubeLight(int watts,int tubeLenth, String color) {
super(watts);
this.tubeLength=tubeLenth;
this.color=color;
}
TubeLight(int watts,boolean indicator, int tubeLenth, String color) {
super(watts, indicator);
this.tubeLength=tubeLenth;
this.color=color;
}
//成员方法
public void printInfo(){
super.printInfo();
System.out.println("tubeLenth=" + this.tubeLength);
System.out.println("color=" + this.color);
}
}
测试程序:
public class Test {
public static void main(String[] args){
Linght lingth=new TubeLight(32,true,50,"white");
lingth.printInfo();
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Class TubeLight extends Light{
private int tubeLength;
private String color;
public TubeLight(int watts, int tubeLength,String color){
super(watts,true);
this.tubeLength=tubeLength;
this.color = color;
}
public void printInfo() {
this();
System.out.println(tubeLength=”+tubeLength);
System.out.println(color =”+ color);
}
public static void main(String[] args){
TubeLight light = new TubeLight(30,50,"white");
light.pringln();
}
}
private int tubeLength;
private String color;
public TubeLight(int watts, int tubeLength,String color){
super(watts,true);
this.tubeLength=tubeLength;
this.color = color;
}
public void printInfo() {
this();
System.out.println(tubeLength=”+tubeLength);
System.out.println(color =”+ color);
}
public static void main(String[] args){
TubeLight light = new TubeLight(30,50,"white");
light.pringln();
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
aklsdhlcniaspodasdv
追问
怎么做啊??
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询