/*
import java.util.*;
class Circle {
int radius;
String name;
public Circle() { //생성자
radius=1;
name="";
}
public Circle(int r, String n)
{
radius = r;
name = n;
}
public double getArea( ) { //메소드
return 3.141592653585*radius*radius;
}
}
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Circle pizza = new Circle(10, "자바피자");
double area = pizza.getArea();
System.out.println(pizza.name + "의 면적은 " + area);
Circle donut = new Circle();
donut.name = "도넛피자";
area = donut.getArea();
System.out.println(donut.name + "의 면적은 " + area);
}
}
import java.util.*;
class Song {
String title, artist, country;
int year;
public Song() { //기본생성자
title = "No title";
year = 2000;
country = "No info of Location";
artist = "No Name";
}
public Song(String title, String country,int year, String artist) //초기화용 생성자
{
this.title=title;
this.country = country;
this.year = year;
this.artist = artist;
}
public void show() {
System.out.println(year + "년, " + country + "의 " + artist + "가 부른 " + title);
}
}
public class Main {
public static void main(String[] args) {
int arr[] = new int[50]; //자료형 배열
arr[0]=5;
Song sarr[] = new Song[50]; //1. 객체 배열
for(int i=0;i<sarr.length;i++)
sarr[i]=new Song();
System.out.println(sarr[0].artist);
//Song so = new Song("Dancing Queen", "스웨덴",1978, "아바");
//so.show();
}
}
*/
//객체 배열 만들기 예제 4-6
import java.util.*;
class Circle {
int radius;
public Circle(int r)
{
radius = r;
}
public double getArea( ) { //메소드
return 3.141592653585*radius*radius;
}
}
public class Main {
public static void main(String[] args) {
Circle [] c;
c = new Circle[5];
for(int i = 0;i<c.length;i++) {
c[i] = new Circle(i);
}
for(int i = 0;i<c.length;i++) {
System.out.println((int)(c[i].getArea()) + " ");
}
}
}