import com.sun.tools.sjavac.comp.dependencies.PublicApiCollector;
/*
class Book{
String title;
String author;
void show( ) {System.out.println(title + " " + author); }
public Book() //생성자1
{
this("", "");
System.out.println("생성자1번 호출됨");
}
public Book(String title) { //생성자2
this(title, "작자미상"); //자신의 다른 생성자 사용하기
System.out.println("생성자2번 호출됨.");
}
public Book(String title, String author) { //생성자3
System.out.println("생성자3번 호출됨.");
this.title = title;
this.author = author;
}
}
class Main{
public static void main(String[] args) {
//Book littlePrince = new Book("어린왕자", "생택쥐페리");
//Book loveStory = new Book("춘향전");
//Book emptyBook = new Book();
//loveStory.show();
}
}
//객체 배열을 생성할때는, 1. 레퍼런스배열 생성 -> 2. 객체 생성
*/
/*
class Book{
String title;
String author;
}
class Main{
public static void main(String[] args) {
int arr[] = new int[50]; // int arr[50]
//arr[0] ~ arr[49]
Book barr[] = new Book[50]; //레퍼런스 변수를 50개 생성
for(int i=0;i<barr.length;i++)
{
barr[i]=new Book(); //객체 생성
}
barr[0].title="어린왕자";
Book [] b = new Book[50]; //1. 레퍼런스 변수 50개 생성
//for()
//{
// b[i]=new Book(); //2.객체 생성
//}
}
}
*/
//객체 배열 만들기 예제 4-6
/*
class Circle{
int radius;
public Circle(int radius) {
this.radius = radius;
}
public double getArea() {
return 3.14*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()) + " ");
}
}
}
import java.util.Scanner;
class Book {
String title, author;
public Book(String title, String author ) {
this.title = title;
this.author = author;
}
}
public class Main{
public static void main(String[] args) {
Book [] book = new Book[2];
Scanner scanner = new Scanner(System.in);
for(int i=0; i<book.length; i++) {
System.out.println("제목>>");
String title = scanner.nextLine();
System.out.println("저자>>");
String author = scanner.nextLine();
book[i] = new Book(title, author);
}
for(int i=0; i<book.length; i++) {
System.out.println("(" + book[i].title + "," + book[i].author + ")");
}
scanner.close();
}
}
접근지정자
public : 모든 클래스에서 접근 가능
private : 다른 클래스에서 접근 불가능 (프라이빗)
class Book {
public String title;
private String author; //다른 클래스에서는 접근 불가능
public void setAuthor(String author)
{
this.author = author;
}
}
public class Main{
public static void main(String[] args) {
Book b = new Book();
b.title = "어린왕자";
// b.author("생텍쥐베리");
b.setAuthor("생텍쥐베리"); // author는 private 필드라서 메소드로 접근해야한다.
}
}
*/
/*
class SampleClass {
public int field1;
protected int field2;
int field3;
private int field4;
public void set(int fielde4) {
this. field4 = field4;
}
}
public class Main {
public static void main(String[] args) {
SampleClass fa = new SampleClass();
fa.field1 = 0;
fa.field2 = 1;
fa.field3 = 2;
//fa.field4 = 3;
fa.set(3);
}
}
*/
/*
class Person{
static int temp; //같은 클래스로 만든 객체들이 공유하는 필드
String name; // 객체마다 각각 가지는 필드
int age;
}
public class Main {
public static void main(String[] args) {
Person a = new Person();
Person b = new Person();
a.age = 10;
b.age = 50;
System.out.println(a.age);
System.out.println(b.age);
a.temp=20;
System.out.println(b.temp);
b.temp=50;
System.out.println(a.temp);
Person.temp=80;
System.out.println(a.temp + " "+b.temp);
}
}
*/
/*
import java.util.Scanner;
abstract class Converter {
abstract protected double convert(double src);
abstract protected String getSrcString();
abstract protected String getDestString();
protected double ratio;
public void run() {
Scanner scanner = new Scanner(System.in);
System.out.println(getSrcString() + "을 " + getDestString() + "로 바꿉니다.");
System.out.println(getSrcString() + "을 입력하세요>> ");
double val = scanner.nextDouble();
double res = convert(val);
System.out.println("변환결과: " + res + getDestString() + "입니다");
scanner.close();
}
}
class Won2Dollar extends Converter {
public Won2Dollar(double ratio) {
this.ratio = ratio;
}
protected double convert(double src){
return src/ratio;
}
protected String getSrcString() {
return "원";
}
protected String getDestString() {
return "달러";
}
}
class Main{
public static void main(String[] args) {
Won2Dollar toDollar = new Won2Dollar(1200);
toDollar.run();
}
}
*/
/*
import java.util.Scanner;
abstract class Converter {
abstract protected double convert(double src);
abstract protected String getSrcString();
abstract protected String getDestString();
protected double ratio;
public void run() {
Scanner scanner = new Scanner(System.in);
System.out.println(getSrcString() + "을 " + getDestString() + "로 바꿉니다.");
System.out.println(getSrcString() + "을 입력하세요>> ");
double val = scanner.nextDouble();
double res = convert(val);
System.out.println("변환결과: " + res + getDestString() + "입니다");
scanner.close();
}
}
class km2Mile extends Converter {
public km2Mile(double ratio) {
this.ratio = ratio;
}
protected double convert(double src){
return src/ratio;
}
protected String getSrcString() {
return "km";
}
protected String getDestString() {
return "mile";
}
}
class Main{
public static void main(String[] args) {
km2Mile toMile = new km2Mile(1.6);
toMile.run();
}
}
// 클래스 = 필드 + 생성자 + 메소드
*/
/*
class Point{
private int x, y; //필드
public Point(int x, int y) { this.x = x; this.y = y; } //생성자
public int getX() { return x; } //메소드
public int getY() { return y; }
protected void move(int x, int y) { this.x = x; this.y = y; }
}
class ColorPoint extends Point {
private String color;
public ColorPoint(int x, int y, String color) {
super(x,y);
this.color = color;
}
public void setXY(int x, int y) {
move(x,y);
}
public void setColor(String color) {
this.color = color;
}
public String toString() {
return color + "색의 (" + getX() + "," + getY() + ")의 점";
}
}
class Main{
public static void main(String[] args) {
ColorPoint cp = new ColorPoint(5, 5, "YELLOW");
cp.setXY(10, 20);
cp.setColor("RED");
String str = cp.toString();
System.out.println(str + "입니다");
}
}
*/
class Point{
private int x, y; //필드
public Point(int x, int y) { this.x = x; this.y = y; } //생성자
public Point() {this.x = 0; this.y = 0; }
public int getX() { return x; } //메소드
public int getY() { return y; }
protected void move(int x, int y) { this.x = x; this.y = y; }
}
class Point3D extends Point {
public int z;
public Point3D(int x, int y, int z) {
super(x, y);
this.z = z;
}
public Point3D(int z) {
super();
this.z = z;
}
public Point3D() {
super();
this.z = z;
}
public void moveUp()
{
}
public void moveDown()
{
}
public void move()
{
}
}
class Main{
public static void main(String[] args) {
Point3D p = new Point3D(1,2,3);
System.out.println(p.toString() + "입니다.");
p.moveUp();
System.out.println(p.toString() + "입니다.");
p.moveDown();
p.move(10, 10);
System.out.println(p.toString() + "입니다.");
p.move(100, 200, 300);
System.out.println(p.toString() + "입니다.");
}
}