(8) getpi() 함수는정적함수이므로 main() 에서호출할수있다. (9) class Circle private double radius; static final double PI= ; // PI 이름으로 로초기화된정적상수 public

Similar documents
PowerPoint Presentation

PowerPoint Presentation

PowerPoint Presentation

<4D F736F F F696E74202D20C1A63038C0E520C5ACB7A1BDBABFCD20B0B4C3BC4928B0ADC0C729205BC8A3C8AF20B8F0B5E55D>

PowerPoint Presentation

Microsoft PowerPoint - Lect04.pptx

쉽게 풀어쓴 C 프로그래밍

JAVA 프로그래밍실습 실습 1) 실습목표 - 메소드개념이해하기 - 매개변수이해하기 - 새메소드만들기 - Math 클래스의기존메소드이용하기 ( ) 문제 - 직사각형모양의땅이있다. 이땅의둘레, 면적과대각

PowerPoint Presentation

JAVA PROGRAMMING 실습 05. 객체의 활용

Design Issues

쉽게 풀어쓴 C 프로그래밍

Microsoft PowerPoint 장강의노트.ppt

Microsoft PowerPoint - 2강

JAVA PROGRAMMING 실습 08.다형성

gnu-lee-oop-kor-lec06-3-chap7

PowerPoint Presentation

자바 프로그래밍

비긴쿡-자바 00앞부속

쉽게 풀어쓴 C 프로그래밍

PowerPoint Presentation

PowerPoint Presentation

쉽게 풀어쓴 C 프로그래밍

PowerPoint Presentation

Chapter 6 Objects and Classes

Microsoft PowerPoint 자바-기본문법(Ch2).pptx

PowerPoint Presentation

JAVA PROGRAMMING 실습 02. 표준 입출력

JAVA PROGRAMMING 실습 05. 객체의 활용

Microsoft PowerPoint - C++ 5 .pptx

Microsoft PowerPoint - Java7.pptx

Microsoft PowerPoint - 8ÀÏ°_Æ÷ÀÎÅÍ.ppt

쉽게 풀어쓴 C 프로그래밍

PowerPoint Presentation

Microsoft PowerPoint - java1-lab5-ImageProcessorTestOOP.pptx

JAVA PROGRAMMING 실습 02. 표준 입출력

5장.key

public String breed; public String color; // 메소드정의 public void bark()... public void bite()... public void eat()... // 종 // 색깔 p 기초변수는 int, flo

No Slide Title

class Sale void makelineitem(productspecification* spec, int qty) SalesLineItem* sl = new SalesLineItem(spec, qty); ; 2. 아래의액티비티다이어그램을보고 Java 또는 C ++,

슬라이드 1

q 이장에서다룰내용 1 객체지향프로그래밍의이해 2 객체지향언어 : 자바 2

슬라이드 1

PowerPoint 프레젠테이션

<4D F736F F F696E74202D2036C0CFC2B05FB0B4C3BCC1F6C7E2C7C1B7CEB1D7B7A1B9D62E707074>

설계란 무엇인가?

제11장 프로세스와 쓰레드

PowerPoint 프레젠테이션

PowerPoint 프레젠테이션

untitled

Microsoft PowerPoint - Chapter 6.ppt

슬라이드 1

쉽게 풀어쓴 C 프로그래밍

Modern Javascript

ch09

PowerPoint Presentation

PowerPoint Template

TEST BANK & SOLUTION

PowerPoint 프레젠테이션

PowerPoint 프레젠테이션

(Microsoft PowerPoint - java1-lecture11.ppt [\310\243\310\257 \270\360\265\345])

Microsoft PowerPoint - 04-UDP Programming.ppt

* Factory class for query and DML clause creation * tiwe * */ public class JPAQueryFactory implements JPQLQueryFactory private f

(Microsoft Word - \301\337\260\243\260\355\273\347.docx)

Microsoft Word - java19-1-midterm-answer.doc

쉽게 풀어쓴 C 프로그래밍

05-class.key

PowerPoint 프레젠테이션

adfasdfasfdasfasfadf

11장 포인터

1. 상속의기본개념 다음과같은문제를위한클래스설계 자동차 속성 : 색상, 배기량, 현재속도 메서드 : 가속하라, 멈춰라, 시동을켜라 트럭 속성 : 색상, 배기량, 현재속도, 최대중량 메서드 : 가속하라, 멈춰라, 시동을켜라 택시 속성 : 색상, 배기량, 현재속도, 요금,

PowerPoint 프레젠테이션

07 자바의 다양한 클래스.key

rmi_박준용_final.PDF

슬라이드 1

쉽게

PowerPoint Presentation

10.0pt1height.7depth.3width±â10.0pt1height.7depth.3widthÃÊ10.0pt1height.7depth.3widthÅë10.0pt1height.7depth.3width°è10.0pt1height.7depth.3widthÇÁ10.0pt1height.7depth.3width·Î10.0pt1height.7depth.3width±×10.0pt1height.7depth.3width·¡10.0pt1height.7depth.3width¹Ö pt1height.7depth.3widthŬ10.0pt1height.7depth.3width·¡10.0pt1height.7depth.3width½º, 10.0pt1height.7depth.3width°´10.0pt1height.7depth.3widthü, 10.0pt1height.7depth.3widthº¯10.0pt1height.7depth.3width¼ö, 10.0pt1height.7depth.3width¸Þ10.0pt1height.7depth.3width¼Ò10.0pt1height.7depth.3widthµå

Chapter 6 Objects and Classes

1. 클래스와배열 int 형배열선언및초기화 int ary[5] = 1, 2, 3, 4, 5 ; for (int i = 0; i < 5; i++) cout << "ary[" << i << "] = " << ary[i] << endl; 5 장클래스의활용 1

PowerPoint Presentation

02 C h a p t e r Java

슬라이드 1

Microsoft PowerPoint - ch10 - 이진트리, AVL 트리, 트리 응용 pm0600

슬라이드 1

Microsoft PowerPoint - additional06.ppt [호환 모드]

untitled

12-file.key

Microsoft PowerPoint - 14주차 강의자료

01-OOPConcepts(2).PDF

Microsoft PowerPoint - additional01.ppt [호환 모드]

1. 객체의생성과대입 int 형변수 : 선언과동시에초기화하는방법 (C++) int a = 3; int a(3); // 기본타입역시클래스와같이처리가능 객체의생성 ( 복습 ) class CPoint private : int x, y; public : CPoint(int a

유니티 변수-함수.key

Microsoft PowerPoint 장.객체의이용.ppt

No Slide Title

[ 마이크로프로세서 1] 2 주차 3 차시. 포인터와구조체 2 주차 3 차시포인터와구조체 학습목표 1. C 언어에서가장어려운포인터와구조체를설명할수있다. 2. Call By Value 와 Call By Reference 를구분할수있다. 학습내용 1 : 함수 (Functi

Cluster management software

Java ~ Java program: main() class class» public static void main(string args[])» First.java (main class ) /* The first simple program */ public class

교육자료

PowerPoint 프레젠테이션

Transcription:

Chapter 9 Lab 문제정답 1. public class Circle private double radius; static final double PI=3.141592; // PI 이름으로 3.141592 로초기화된정적상수 (1) public Circle(double r) radius = r; (2) public double getradius() return radius; public void setradius(double radius) (3) this.radius = radius; private double square(double value) return value*value; (4) public double getarea() (5) return square(radius)*pi; public double getperimeter() (6) return 2.0*PI*radius; public static double getpi() return PI; (7) square() 함수는정적함수가아니라서 main() 에서호출하면오류가발생한다.

(8) getpi() 함수는정적함수이므로 main() 에서호출할수있다. (9) class Circle private double radius; static final double PI=3.141592; // PI 이름으로 3.141592 로초기화된정적상수 public Circle(double r) radius = r; public double getradius() return radius; public void setradius(double radius) this.radius = radius; private double square(double value) return value*value; public double getarea() return square(radius)*pi; public double getperimeter() return 2.0*PI*radius; public static double getpi() return PI; public class CircleTest public static void main(string args[]) Circle c = new Circle(5.0); // 객체생성, 생성자호출시반지름을 5.0 으로설정 System.out.println(c.getArea());// 원의면적계산하여출력 System.out.println(c.getPerimeter());// 원의둘레계산하여출력

Exercise 1. (1) 객체가생성될때에필드에게초기값을제공하고필요한초기화절차를실행 (2) 매개변수의자료형이나매개변수개수로구별되어호출 (3) 자기자신을참조 (4) 정적변수는하나의클래스에하나만존재하여그클래스의모든객체들에의해공유되지 만인스턴스변수는각인스턴스마다별도로생성된다. (5) 객체의참조값이전달된다. (6) 정적메소드는객체가생성되지않은상태에서호출되는메소드이므로객체안에서존재 하는인스턴스변수들은사용할수없다. 2. (1) 생성자 Point() 는값을반환하지않는다따라서 void를삭제한다. (2) 메소드의반환형이다르다고해서메소드를중복시킬수있는것은아니다. class MyMath public int getrandom1() return (int)math.random(); public double getrandom() return Math.random(); (3) 정적메소드 getstringname() 에서인스턴스메소드 getname() 을호출할수없다. class MyClass private static String getname() return "Myclass"; public static String getclassname() return getname(); 3. (1) public class Cube private double side; // 정육면체의한변 public Cube() side = 0;

public double getside() return side; public double getvolume() return side*side*side; (2) public class Cube private double side; // 정육면체의한변 public Cube() side = 0; public Cube(double side) this.side = side; public double getside() return side; public double getvolume() return side*side*side; 4. class MyMetric private static double distance; public static double kilotomile(double d) distance = d / 1.6093; return distance; public static void miletokilo(double d) distance = d * 1.6093; public class MyMetricTest public static void main(string args[]) double d = MyMetric.kiloToMile(1); System.out.println(d);

5. s_instance 가 null 일때만객체를생성하고이미객체가생성되어있으면단순히객체의참 조값을반환한다. class Single private static Single s_instance; public static Single getinstance() if (s_instance == null) s_instance = new Single(); return s_instance;

Programming 2. class Plane private int num, p_num; private String model; private static int planes; public void setnum(int n) num = n; public void setpnum(int pn) p_num = pn; public void setmodel(string m) model = m; public int getnum() return num; public int getpnum() return p_num; public String getmodel() return model; public static void setplanes(int p) planes = p; public static int getplanes() return planes; public Plane() public Plane(int n, String m, int pn) num = n; p_num = pn; model = m;

public Plane(int n, String m) num = n; model = m; public String tostring() return " 식별번호 :" + getnum() + " 모델 : " + getmodel() + " 승객수 : " + getpnum(); public class PlaneTest public static void main(string[] args) Plane plane1 = new Plane(1, "aa", 200); Plane plane2 = new Plane(2, "bb"); Plane plane3 = new Plane(); plane1.setplanes(0); plane1.getplanes(); plane3.setnum(3); plane3.setmodel("cc"); plane3.setpnum(150);

3. public class Box private int width, length, height; private boolean empty = false; public int getwidth() return width; public void setwidth(int width) this.width = width; public int getlength() return length; public void setlength(int length) this.length = length; public int getheight() return height; public void setheight(int height) this.height = height; public boolean isempty() return empty; public void setempty(boolean empty) this.empty = empty;

public Box() width = 0; length = 0; height = 0; empty = true; public Box(int w, int l, int h) width = w; length = l; height = h; empty = true; 4. public class Movie private String title; private String direction; private String company; public Movie() public Movie(String t, String d, String c) title = t; direction = d; company = c;

5. public class BankAccount private String ownername; private int accountnumber; private int balance; private double rate; public String getownername() return ownername; public void setownername(string ownername) this.ownername = ownername; public int getaccountnumber() return accountnumber; public void setaccountnumber(int accountnumber) this.accountnumber = accountnumber; public int getbalance() return balance; public void setbalance(int balance) this.balance = balance; public double getrate() return rate; public void setrate(double rate) this.rate = rate; public BankAccount() public BankAccount(String n, int a, int b, double r) ownername = n; accountnumber = a; balance = b; rate = r;