/*클래스만들기, 객체 만들기
* 필드, 메소드 만들기
import java.util.*;
class Person{
String name; //필드
int age;
void view() //메소드 (함수)
{
System.out.println(name+"는 "+age+"살이예요.");
}
}
class Main{
public static void main(String[] args) { //메인메소드
Person p; //1. 레퍼런스변수 생성
p = new Person(); //2. Person 객체 생성
Person s = new Person(); //1,2번 한번에 하기
p.age = 100;
p.name = "준영이";
p.view();
s.age = 500;
s.name = "준상이";
s.view();
}
}
import java.util.*;
class Circle{
int radius;
String name;
public Circle() { }
public double getArea()
{
return 3.14*radius*radius;
}
}
class Main{
public static void main(String[] args) {
Circle pizza;
pizza = new Circle();
pizza.radius = 10;
pizza.name = "자바피자";
double area = pizza.getArea();
System.out.println(pizza.name + "의 면적은 " + area);
Circle donut = new Circle();
donut.radius = 2;
donut.name = "자바도넛";
area = donut.getArea();
System.out.println(donut.name + "의 면적은" + area);
}
}
import java.util.Scanner;
class Rectangle {
int width, height; //필드
Rectangle(){
}
public int getArea() { //메소드
return width*height;
}
}
public class Main{
public static void main(String[] args) {
Rectangle main = new Rectangle();
Scanner scanner = new Scanner(System.in);
System.out.println(">> ");
main.width = scanner.nextInt();
main.height = scanner.nextInt();
System.out.println("사각형의 면적은 " + main.getArea());
scanner.close();
}
}
*/
//생성자 : 객체 생성시 필드의 초기값 설정
/*
import java.util.Scanner;
class Rectangle {
int width, height; //필드
Rectangle() { //기본 생성자 1
width=10;
height=10;
}
Rectangle(int w, int h){ //2번 생성자
width=w;
height=h;
}
public int getArea() { //메소드
return width*height;
}
}
public class Main{
public static void main(String[] args) {
Rectangle main = new Rectangle(4,5); //2번 생성자
System.out.println("사각형의 면적은 " + main.getArea());
Rectangle b = new Rectangle(); //1번생성자
System.out.println("사각형의 면적은 " + b.getArea());
}
}
*/
/*
import java.util.Scanner;
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.14*radius*radius;
}
}
public class Main{
public static void main(String[] args) {
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.Scanner;
class TV{
String a;
int year, inch;
public TV(String LG, int year, int inch)
{
a = LG;
year = 2017;
inch = 32;
}
public void show()
{
System.out.println(a + "에서 만든" + year + "년형" + inch + "인치 TV");
}
}
public class Main{
public static void main(String[] args) {
TV myTV = new TV("LG", 2017, 32);
myTV.show();
}
}