廣告廣告
  加入我的最愛 設為首頁 風格修改
首頁 首尾
 手機版   訂閱   地圖  簡體 
您是第 2731 個閱讀者
 
發表文章 發表投票 回覆文章
  可列印版   加為IE收藏   收藏主題   上一主題 | 下一主題   
文心 手機
數位造型
個人文章 個人相簿 個人日記 個人地圖
小人物
級別: 小人物 該用戶目前不上站
推文 x0 鮮花 x8
分享: 轉寄此文章 Facebook Plurk Twitter 複製連結到剪貼簿 轉換為繁體 轉換為簡體 載入圖片
推文 x0
[Java] JAVA~~~拜托幫幫忙
題目是: 設計一個含有length及width屬性的rectangle類別, 而且這兩種屬性預設值是1.該類別具有可計算矩形的perimeter(周長)及area(面積)的方法.當然也必須提供length和width的set及get方法. set方法應該要能夠檢查length及width都是否為浮點數. 且其值會大於0.0而小於20.0.


請幫我把???部份寫出來好嗎 謝謝


class Rectangle
{
in ..

訪客只能看到部份內容,免費 加入會員 或由臉書 Google 可以看到全部內容




終於上大學了~~感覺好特別唷
獻花 x0 回到頂端 [樓 主] From:台灣 和信超媒體寬帶網 | Posted:2006-06-02 01:08 |
奉茶
個人文章 個人相簿 個人日記 個人地圖
小人物
級別: 小人物 該用戶目前不上站
推文 x0 鮮花 x21
分享: 轉寄此文章 Facebook Plurk Twitter 複製連結到剪貼簿 轉換為繁體 轉換為簡體 載入圖片

class rectangle{
private double length = 1;
private double width = 1;
private String str = null;
public rectangle(double l,double w,String s){
length = l; width = w; str = s;
}
public double Length(){
return length;
}
public double Width(){
return width;
}
public setLength(double length){
if(length > 0.0 && length < 20.0)
this.length = length;
}
public setWidth(double width){
if(width > 0.0 && width < 20.0)
this.width = width;
}
public String Print(){
return width + str + "x" + height + str;
}
public String Perimeter(){
return ((length+width)*2) + str;
}
public String Area(){
return (length * width) + "平方" + str;
}
}


獻花 x0 回到頂端 [1 樓] From:台灣和信超媒體 | Posted:2006-06-02 13:07 |
文心 手機
數位造型
個人文章 個人相簿 個人日記 個人地圖
小人物
級別: 小人物 該用戶目前不上站
推文 x0 鮮花 x8
分享: 轉寄此文章 Facebook Plurk Twitter 複製連結到剪貼簿 轉換為繁體 轉換為簡體 載入圖片

謝謝你的回答唷~~~
不過可不可以問一下這個是要放在我上面題目的問號裡面嗎



終於上大學了~~感覺好特別唷
獻花 x0 回到頂端 [2 樓] From:台灣 和信超媒體寬帶網 | Posted:2006-06-05 15:08 |
奉茶
個人文章 個人相簿 個人日記 個人地圖
小人物
級別: 小人物 該用戶目前不上站
推文 x0 鮮花 x21
分享: 轉寄此文章 Facebook Plurk Twitter 複製連結到剪貼簿 轉換為繁體 轉換為簡體 載入圖片

這是給你參考的
你要自己稍微修改一下^^


獻花 x0 回到頂端 [3 樓] From:台灣和信超媒體 | Posted:2006-06-06 12:51 |
文心 手機
數位造型
個人文章 個人相簿 個人日記 個人地圖
小人物
級別: 小人物 該用戶目前不上站
推文 x0 鮮花 x8
分享: 轉寄此文章 Facebook Plurk Twitter 複製連結到剪貼簿 轉換為繁體 轉換為簡體 載入圖片

OK了解~~~感謝你的頂力相助



終於上大學了~~感覺好特別唷
獻花 x0 回到頂端 [4 樓] From:印度尼西亞 | Posted:2006-06-06 16:44 |
文心 手機
數位造型
個人文章 個人相簿 個人日記 個人地圖
小人物
級別: 小人物 該用戶目前不上站
推文 x0 鮮花 x8
分享: 轉寄此文章 Facebook Plurk Twitter 複製連結到剪貼簿 轉換為繁體 轉換為簡體 載入圖片

class Rectangle
{
double length,width; //長,寬
String unit;     //單位
private double length = 1;
private double width = 1;
private String unit = null;
{
     public rectangle (double l,double w,String u);
}

{
length = l;
width = w;
unit = u;

}

public double Length()
{
return length;
}
public double Width()
{
return width;
}
public void length(double length);
{
if(length > 0.0 && length < 20.0)
this.length = length;
}
public void width(double width);
{
if(width > 0.0 && width < 20.0)
this.width = width;
}



public String Print()
{
System.out.print("\n");
return("長方形:"+length+unit+"*"+width+unit);

}
public String Area()
{
System.out.print("\n");
return("長方形面積:"+(width*length)+"平方"+unit);

}
public String Length()
{
System.out.print("\n");
return("長方形周長:"+(length+width)*2+unit);

}

}

class rectangle1
{

public static void main(String args[])
  {
       Rectangle r1=new Rectangle(12,10,"公分");
        r1.Print(); // 長方形:12公分x10公分
        r1.Area();   // 長方形面積:120 平方公分
        r1.Length(); // 長方形周長:44 公分
       Rectangle r2=new Rectangle(5,6,"公尺");        
        r2.Print(); // 長方形:5公尺x6公尺
        r2.Area();   // 長方形面積:30 平方公尺
        r2.Length(); // 長方形周長:22 公尺        
  }      
  }

/*
長方形:12公分x10公分
長方形面積:120 平方公分
長方形周長:44 公分
長方形:5公尺x6公尺
長方形面積:30 平方公尺
長方形周長:22 公尺  
press any key to continue...
     
*/



終於上大學了~~感覺好特別唷
獻花 x0 回到頂端 [5 樓] From:印度尼西亞 | Posted:2006-06-06 17:20 |
文心 手機
數位造型
個人文章 個人相簿 個人日記 個人地圖
小人物
級別: 小人物 該用戶目前不上站
推文 x0 鮮花 x8
分享: 轉寄此文章 Facebook Plurk Twitter 複製連結到剪貼簿 轉換為繁體 轉換為簡體 載入圖片

那可以請問一下我這樣有那裡錯了嗎~~~拜托了~~~ 表情



終於上大學了~~感覺好特別唷
獻花 x0 回到頂端 [6 樓] From:印度尼西亞 | Posted:2006-06-06 17:20 |
奉茶
個人文章 個人相簿 個人日記 個人地圖
小人物
級別: 小人物 該用戶目前不上站
推文 x0 鮮花 x21
分享: 轉寄此文章 Facebook Plurk Twitter 複製連結到剪貼簿 轉換為繁體 轉換為簡體 載入圖片

幫你改好了^^"
原來我之前也犯了一些錯誤

class InvalidRangeException extends Exception{}
class Rectangle
{
private double length = 1,width = 1; //長,寬
String unit = null;   //單位
public Rectangle (double l,double w,String u){
length = l;
width = w;
unit = u;

}

public double Length()
{
return length;
}
public double Width()
{
return width;
}
public void length(double length) throws InvalidRangeException
{
if(length > 0.0 && length < 20.0)
this.length = length;
else
throw new InvalidRangeException();
}
public void width(double width) throws InvalidRangeException
{
if(width > 0.0 && width < 20.0)
this.width = width;
else
throw new InvalidRangeException();
}



public void Print()
{
System.out.println();
System.out.println("長方形:"+length+unit+"*"+width+unit);

}
public void Area()
{
System.out.println();
System.out.println("長方形面積:"+(width*length)+"平方"+unit);

}
public void perimeter()
{
System.out.println();
System.out.println("長方形周長:"+(length+width)*2+unit);

}

}

class rectangle1
{

public static void main(String args[])
{
    Rectangle r1=new Rectangle(12,10,"公分");
    r1.Print(); // 長方形:12公分x10公分
    r1.Area();   // 長方形面積:120 平方公分
    r1.perimeter(); // 長方形周長:44 公分
    Rectangle r2=new Rectangle(5,6,"公尺");      
    r2.Print(); // 長方形:5公尺x6公尺
    r2.Area();   // 長方形面積:30 平方公尺
    r2.perimeter(); // 長方形周長:22 公尺      
}    
}
自己compile看看
我就是沒有自己compile才會沒注意到有錯誤^^"


[ 此文章被奉茶在2006-06-07 08:28重新編輯 ]

此文章被評分,最近評分記錄
財富:20 (by codeboy) | 理由: 熱心助人...感謝您的回覆喔..^^


獻花 x1 回到頂端 [7 樓] From:台灣和信超媒體 | Posted:2006-06-07 07:51 |
文心 手機
數位造型
個人文章 個人相簿 個人日記 個人地圖
小人物
級別: 小人物 該用戶目前不上站
推文 x0 鮮花 x8
分享: 轉寄此文章 Facebook Plurk Twitter 複製連結到剪貼簿 轉換為繁體 轉換為簡體 載入圖片

因為你的頂力幫助~~~~我的java才不致於當掉~~~~謝謝 表情



終於上大學了~~感覺好特別唷
獻花 x0 回到頂端 [8 樓] From:印度尼西亞 | Posted:2006-06-07 13:40 |

首頁  發表文章 發表投票 回覆文章
Powered by PHPWind v1.3.6
Copyright © 2003-04 PHPWind
Processed in 0.014736 second(s),query:16 Gzip disabled
本站由 瀛睿律師事務所 擔任常年法律顧問 | 免責聲明 | 本網站已依台灣網站內容分級規定處理 | 連絡我們 | 訪客留言