dポイントプレゼントキャンペーン実施中!

compareto()を使って名前、身長、体重を「身長昇順」拡張for文でだしたいのですが・・・
(1)returnを使って何を返せばいいのか?
(2)System.out.println()でなにをすればいいのか?
(3)他の文で間違っているのか?
この3点が分かりません。JAVAに詳しい方よろしくお願いします。。。

package class;
public class NewClass {

public static void main(String[] args) {
NewClass2 A = new NewClass2("aaa", 160, 40);
NewClass2 B = new NewClass2("bbb", 170, 60);
NewClass2 C = new NewClass2("ccc", 150, 70);

System.out.println("---Comparable---");

Set<Comparable> ts3 = new TreeSet<Comparable>();
ts3.add(A);
ts3.add(B);
ts3.add(C);
for(Comparable cm : ts3)
{
System.out.println(?????????????);
}



package class;
public class NewClass2 implements Comparable< NewClass2>
{
private String name;
private int Weight;
private int Height;
public String getName()
{
return this.name;
}
public void setName(String name)
{
this.name = name;
}
public int getWeight()
{
return this.Weight;
}
public void setWeight(int Weight)
{
this.Weight = Weight;
}
public int getHeight()
{
return this.Height;
}
public void setHeight(int Height)
{
this.Height = Height;
}
public StudentBean(String name, int Height, int Weight)
{
this.name = name;
this.Weight = Weight;
this.Height = Height;

}
@Override
public int compareTo(Object arg0) {
StudentBean sb = (StudentBean)arg0;
    String name1 = this.name;
int Height1 = this.Height;
int Weight1 = this.Weight;
    int returnval = 0;
if(Height1 > sb.getHeight())
{
returnval = 1;
}
else if(Height1 < sb.getHeight())
{
returnval = -1;
}
else
returnval = 0;
}
return ???????;
}





文は以上です
出力は
aaa
160
40



なかんじでお願いします。

A 回答 (2件)

(1)returnを使って何を返せばいいのか?


No.1の方がおっしゃる通りです。

(2)System.out.println()でなにをすればいいのか?
System.out.println()って何だかわかってらっしゃいます?

(3)他の文で間違っているのか?
意味がよく分かりませんが、構文で間違っているところを…
StudentBeanクラスなんですか?
NewClass2クラスなんですか?
このままだと、コンパイルが通りません。
どちらかに統一しましょう。
    • good
    • 0

変数returnvalは何のために用意したのですか?

この回答への補足

え~と・・・returnvalの値でTreeSetが並び替える。って感じです

補足日時:2012/11/28 20:21
    • good
    • 0

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!