| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1469 人关注过本帖
标题:新手java作业,创建一个box输入长宽高求面积体积
取消只看楼主 加入收藏
llawlh
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2012-2-17
结帖率:0
收藏
已结贴  问题点数:20 回复次数:0 
新手java作业,创建一个box输入长宽高求面积体积
大家好,我是java新手,这个作业马上要交了,不知道为什么摁‘2’的时候第二个长方体的代码run出不来,有问题的一段我用红色标出了,请高人指点 :) 不胜感激!
谢谢
刘丽~

public class lliuBox {
private double length;
private double height;
private double width;

lliuBox(){
    length = 2.0;
    height = 2.0;
    width = 2.0;
}
lliuBox(double l, double h, double w){
    this.length = l;
    this.height = h;
    this.width = w;
}
public void printBox(){
    System.out.println("length: " + length);
    System.out.println("height: " + height);
    System.out.println("width: " + width);
}
int volume(){
    return (int)(length*height*width);
}
int surfaceArea(){
    return (int) (2*length*height + 2*length*width + 2*width*height);
}

public void setLength(double length){
    this.length = length;
}
public void setHeight(double height){
    this.length = height;
}
public void setWidth(double width){
    this.length = width;
}
public double getLength(){
    return length;
}
public double getHeight(){
    return height;
}
public double getWidth(){
    return width;
}
}


import *;
public class lliuBoxTest {
    public static void main(String args[])
    throws {
        BufferedReader br = new BufferedReader (new InputStreamReader(System.in));
        String len, hei, wid;
        double valuelength, valueheight,valuewidth;
        char choice;
        lliuBox x = new lliuBox();
        lliuBox y = new lliuBox();
        for (;;){
                do{
            System.out.println("Welcome to create-a-box! What would you like to do?");
            System.out.println("1. Create a box");
            System.out.println("2. Create a box (dimensions specified)");
                  do{
                choice = (char) System.in.read();
                    }while(choice == '\n'|choice == '\r');
                  } while(choice < '1'|choice > '2');
                System.out.println();
               
                switch(choice){
                case '1':
                    System.out.println("Selection: ");
                    System.out.println("1");
                    System.out.println("A box appeared!");
                    System.out.println("length: "+ x.getLength());
                    System.out.println("length: "+ x.getHeight());
                    System.out.println("length: "+ x.getWidth());
                    System.out.println("Surface Area: "+ x.surfaceArea());
                    System.out.println("Volume: "+ x.volume());
                    break;
                    
                case '2':
                    System.out.println("Selection: ");
                    System.out.println("2");
                    
                        System.out.println("Please enter the box's length: " );
                        len = br.readLine();
                        valuelength = Double.parseDouble(len);
                    
                        System.out.println("Please enter the box's height: " );
                        hei = br.readLine();
                        valueheight = Double.parseDouble(hei);
                    
                        System.out.println("Please enter the box's width: " );
                        wid = br.readLine();
                        valuewidth = Double.parseDouble(wid);
                    
                        System.out.println("A box appeared!" );
                    
                    y.setHeight(valueheight);
                    y.setLength(valuelength);
                    y.setWidth(valuewidth);
                    y.printBox();
                    
                    System.out.println("Volume: "+ y.surfaceArea());
                    System.out.println("Surface Area: "+ y.volume());
                    break;
                }
                System.out.println();
                }
        
}
}
搜索更多相关主题的帖子: java class 不胜感激 private public 
2012-02-17 05:05
快速回复:新手java作业,创建一个box输入长宽高求面积体积
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.040248 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved