java 質問 簡単?
■ このスレッドは過去ログ倉庫に格納されています
0001名無しさん@お腹いっぱい。
NGNGpublic class Point {
public int x = 0;
public int y = 0;
// a constructor!
public Point(int x@` int y) {
this.x = x;
this.y = y;
}
}
(2)
public class Rectangle {
public int width = 0;
public int height = 0;
public Point origin;
// four constructors
public Rectangle() {
origin = new Point(0@` 0);
}
public Rectangle(Point p) {
origin = p;
}
public Rectangle(int w@` int h) {
this(new Point(0@` 0)@` w@` h);
}
public Rectangle(Point p@` int w@` int h) {
origin = p;
width = w;
height = h;
}
// a method for moving the rectangle
public void move(int x@` int y) {
origin.x = x;
origin.y = y;
}
// a method for computing the area of the rectangle
public int area() {
return width * height;
}
}
(3)
public class CreateObjectDemo {
public static void main(String[] args) {
// create a point object and two rectangle objects
Point origin_one = new Point(23@` 94);
Rectangle rect_one = new Rectangle(origin_one@` 100@` 200);
Rectangle rect_two = new Rectangle(50@` 100);
// display rect_one's width@` height@` and area
System.out.println("Width of rect_one: " + rect_one.width);
System.out.println("Height of rect_one: " + rect_one.height);
System.out.println("Area of rect_one: " + rect_one.area());
// set rect_two's position
rect_two.origin = origin_one;
// display rect_two's position
System.out.println("X Position of rect_two: " + rect_two.origin.x);
System.out.println("Y Position of rect_two: " + rect_two.origin.y);
// move rect_two and display its new position
rect_two.move(40@` 72);
System.out.println("X Position of rect_two: " + rect_two.origin.x);
System.out.println("Y Position of rect_two: " + rect_two.origin.y);
}
}
0002名無しさん@お腹いっぱい。
NGNG0003名無しさん@お腹いっぱい。
NGNG簡単すぎて答えるのもバカバカしいや。
0004名無しさん@お腹いっぱい。
NGNG(゚Д゚)ハァ?
0005名無しさん@お腹いっぱい。
NGNG(゚Д゚)ハァ?
0006名無しさん@お腹いっぱい。
NGNG(゚Д゚)ハァ?
0007>1
NGNGそれで動きますので、コンパイルして確認しなくても大丈夫。
0008名無しさん@お腹いっぱい。
NGNG(゚Д゚)ハァ?
0009名無しさん@お腹いっぱい。
NGNGうお、久々に真性アホ登場。
ネタか?そうは見えないが…
0010名無しさん@お腹いっぱい。
NGNG0011名無しさん@お腹いっぱい。
NGNGJハウスネタで荒らされて終わったか?
0012名無しさん@お腹いっぱい。
NGNGあなたのブラウザには検索機能がないんですか?
http://piza.2ch.net/test/read.cgi?bbs=tech&key=971960169&ls=50
0013名無しさん@お腹いっぱい。
NGNG宿題クンを引っ掛ける罠だということくらい読みとってやれよ……。
つーか、これですでに罠として機能してないな。
0014名無しさん@お腹いっぱい。
NGNGアクセサ・メソッド入れればいいだけじゃないの?
それよりこの問題はちょっとダメな部類かもしれない。
先生はJavaの素人?
■ このスレッドは過去ログ倉庫に格納されています