import java.util.Scanner; class Circle{ private double x,y; private int radius; public Circle (double x, double y, int radius) { this.x = x;this.y = y;this.radius = radius; } public void show() { System.out.println("가장 면적이 큰 원은 ("+x+","+y+")"+radius); } //원의 넓이 리턴 public double circle() { return radius*radius*3.14; } } public class CircleManager { public static void main(String[] args) { // TODO..
명품JAVA프로그래밍/4장 클래스와 객체
import java.util.Scanner; class Circle{ private double x,y; private int radius; public Circle (double x, double y, int radius) { this.x = x;this.y = y;this.radius = radius; } public void show() { System.out.println("("+x+","+y+")"+radius); } } public class CircleManager { public static void main(String[] args) { // TODO Auto-generated method stub Scanner scanner = new Scanner(System.in); Circle ..
public class Rectangle { private int x,y,width,height; //생성자 public Rectangle(int x, int y, int width, int height) { this.x = x; this.y = y; this.width = width; this.height = height; } //사각형 넓이 리턴 public int square() { return width*height; } //사각형의 좌표와 넓이를 화면에 출력 void show() { System.out.println("("+x+","+y+")에서 크기가 "+width+"x"+height+"인 사각형"); } //매개변수로 받은 r이 현 사각형 안에 있으면 리턴 boolean contains(Re..
public class Song { private String title; private String artist; private int year; private String country; public Song() {} public Song(int year,String country,String artist,String title) { this.year = year; this.country = country; this.artist = artist; this.title = title; } void show() { System.out.println(year+"년 "+country+"국적의 "+artist+"가 부른 "+title); } public static void main(String[] args) ..
import java.util.Scanner; public class Grade { private int math; private int science; private int english; public Grade(int math, int science, int english) { this.math = math; this.science = science; this.english = english; } public int average() { return (math+science+english)/3; } public static void main(String[] args) { // TODO Auto-generated method stub Scanner scanner = new Scanner(System.i..
public class TV { private String brand; private int year; private int inch; public TV(String brand,int year,int inch) { this.brand = brand; this.year = year; this.inch = inch; } void show() { System.out.println(brand+"에서 만든 "+year+"년형 "+inch+"인치 TV"); } public static void main(String[] args) { // TODO Auto-generated method stub TV myTV = new TV("LG",2017,32); myTV.show(); } } 결과 LG에서 만든 2017년형 3..