Java问题,求教大神,在线等,定义类Box 定义double型的三个变量:length,width,height具体如下

急急急java用算 定义一个盒子类Box,包括三个私有变量(width.length.height~

public class Box{ private double width; private double length; private double height; public Box(double width, double length, double height){ this.width = width; this.length = length; this.height = height; } public void showBox(){ System.out.printf("width=%f; length=%f; height=%f", width, length, height); }}

public class Box{
double length,width,height;
double v,s;//定义立方体的体积和表面积
Box(double length,double width,Double height){//初始化三个变量
this.length=length;
this.width=width;
this.height=height;
}
public int tiji(){ //返回体积的整型值
return (int)(length*width*height);
}
public int mianji(){//返回表面积的整型值
return ((int)(length*width+length*height+width*height)*2);
}

public static void main(String[] args){
double l=Double.parseDouble(args[0]);
double w=Double.parseDouble(args[1]);
double h=Double.parseDouble(args[2]); //接收测试时输入的参数并转换为double类型
Box box1=new Box(l,w,h);

System.out.println("长方体的体积是:"+box1.tiji());
System.out.println("长方体的表面积是:"+box1.mianji());
}
}
编译过后测试的时候用java Box para1,para2,para3的形式
比如 java Box 1 2 3
本人原创现编的,我测试是没问题的,有什么问题直接留言

class Box
{
double length,width,height;

public Box(double length,double width,double height){
this.length = length;
this.width = width;
this.height = height;
}

public void setLength(double x){
length = x;
}
public void setWidth(double x){
width = x;
}
public void setHeight(double x){
height = x;
}

public double getLength(){
return length;
}
public double getWidth(){
return width;
}
public double getHeight(){
return height;
}

public double getArea(){
return (lenght*width+length*height+width*length)*2;
}

public double getVolumn(){
return length*height*width;
}
}

public class TestBox
{
public static void main(String [] args){
Box b = new Box(2,4,5);

}
}

求JAVA大神,在线等答案 , 急急急 ,谢谢思密达~~~!!!
答:代码比较长,如下,里面加了注释,赶紧抄上去吧。interface A {String a = "this is string A.";}interface B extends A {String b = "this is string B.";}interface C extends B {String c = "this is string C.";}class D implements C {public void display() {System.out.println...

求JAVa大神,在线等,急!!!
答:答案 --- 1, A 2, B 3, B 4, B 5, D 6, D 7, C 8, A 9, C 10, D 11, D 12, B 13, A 14, D 15, B 16, D 17, C 18, B 19, C

求教java maven项目打包引入的问题,求大神解答
答:使用maven-shade-plugin插件:在打包项目的pom.xml中配置maven-shade-plugin插件,让它将所有的依赖库打包进jar中。在引入的jar包的pom.xml中增加第三方库的依赖配置, 编写dependency:unpack命令,将对应的第三方库依赖解压在项目中。使用maven-dependency-plugin来解决问题,将依赖库重新复制到本地仓库中,...

关于java IO流异常抛出问题,跪求Java大神回答(我在线可以马上给分)_百 ...
答:如图所示,第一次因为你的文件内容是空的,已经达到末尾了,所以catch到的异常是EOFException,如下所示:同学,好好看看API文档:readInt当文件达到末尾的时候会抛出EOFException,而第一次你调用readInt文件肯定是在末尾,所以抛出了异常,而不是1+1等于2的道理。

JAVA小问题,关于类访问另一个包中的类的问题,请大神看清问题在作答
答:二:绕弯路的方法:使用java的反射机制来操作B类。代码如下:default package里的B类 public class B {public String name;public int age;public void sayHi(String name) {System.out.print(this.name + "告诉" + name + ":“我今年" + age + "岁了。”");}}test包里的A类 package test...

JAVA编程问题求大神帮忙看看解答谢谢!
答:for(String strone : str){ System.out.println(strone);} } 以上我的代码供参考 你的问题:1 、定义的数组类型有问题 讲解:字符数组用该用char 或者String 你这个由于是中文字符串,所以用String char 和String 定义是需要引号引起来,2 、java中,结束一段表达式的时候要用英文的分号结...

求大神指点 Java问题
答:Person类的代码如下:public class Person {//声明一个Person类 private String name;//声明私有的名字、性别字段 private String sex;public Person(String name,String sex )//Person的有参构造方法 { this.name = name;this.sex = sex;System.out.println("学生为:"+name+" 性别为:"+sex);/...

求JAVA大神解答,写了好几遍都不对,在线等,急?
答:package com.harman.plat.spring.springioc;import java.util.HashMap;import java.util.Map;public class Weekly {public static void main(String args[]){Map<Integer,String> map = new HashMap();map.put(1,"Monday");map.put(2,"Tuesday");map.put(3,"Wednesday");map.put(4,"Thusday...

Java问题,求大神解答
答:第一、抽象类的说明 抽象类不能被实例化(也就是不能直接 new 抽象类()),如果被实例化,就会报错,编译无法通过。只有抽象类的非抽象子类可以创建对象。抽象类中不一定包含抽象方法,但是有抽象方法的类必定是抽象类。抽象类中的抽象方法只是声明,不包含方法体,就是不给出方法的具体实现也就是方法...

求教Java大神!!
答:首先安装JDK再在 我的电脑->属性->高级系统设置->环境变量中设置变量 path变量如果你没有就新建一个也可以在系统变量中的path路径中添加,就不用去用户变量去添加了区别在于用户变量添加的电脑换一个用户登录之前的用户设置的变量是不存在的,而系统变量是不变的。 在dos中使用 java -version ...

IT评价网,数码产品家用电器电子设备等点评来自于网友使用感受交流,不对其内容作任何保证

联系反馈
Copyright© IT评价网