게시판 즐겨찾기
편집
드래그 앤 드롭으로
즐겨찾기 아이콘 위치 수정이 가능합니다.
자바 생성자랑 메소드 다루는것좀 도와주세요
게시물ID : programmer_20148짧은주소 복사하기
작성자 : Athalwolf
추천 : 0
조회수 : 461회
댓글수 : 2개
등록시간 : 2017/04/01 12:02:36
옵션
  • 본인삭제금지
P20170401_115630999_E6C4B6AB-FA37-48B0-B3BD-D9FD23C4E091.JPG


요 문제 풀고 있는데요

public class ch4_2 {
public class Rectangle{
public int x1,x2,y1,y2;
public Rectangle(){}
public Rectangle(int x1,int y1, int x2,int y2){
this.x1=x1;
this.x2=x2;
this.y1=y1;
this.y2=y2;
}
void set(int x1, int y1, int x2, int y2){
this.x1=x1;
this.x2=x2;
this.y1=y1;
this.y2=y2;
}
void show(){
int s ;
s = (x1-x2)*(y1-y2);
if(s<0)
s*=-1;
System.out.println("사각형의 넓이 " + s);
System.out.println("좌표 x1 >> " + x1 + "좌표 y1 >> "+ y1 +"좌표 x1 >> " + x2 + "좌표 y2 >> "+ y2);
}
int square(){
int s ;
s = (x1-x2)*(y1-y2);
if(s<0)
s*=-1;
return s; 
}
// boolean equals(Rectangle r){
// if(r == )
//}
}
public static void main(String[] args) {
Rectangle r = new Rectangle();  <- 여기가 no enclosing instance 에러가 나요 
Rectangle s = new Rectangle(1,1,2,3);
r.show();
s.show();
System.out.println(s.square());
r.set(-2,2,-1,4);
r.show();
System.out.println(r.square());
//if(r.equals(s))
//System.out.println("두 사각형은 같습니다");

}

}


그리고 boolean을 어떻게 짜야 될지 모르겠어요
자바 어려워요
도와주세요 
꼬릿말 보기
전체 추천리스트 보기
새로운 댓글이 없습니다.
새로운 댓글 확인하기
글쓰기
◀뒤로가기
PC버전
맨위로▲
공지 운영 자료창고 청소년보호