코딩
-
학생 정보 (함수 재정의)코딩/java 2019. 3. 8. 16:27
public class Student { private int id; private int tuition; private double gpa; public void setTuition(int tuition) {this.tuition = tuition;}; public void setGpa(double gpa) {this.gpa = gpa;}; public int getId() {return id;}; public int getTuition() {return tuition;}; public double getGpa() {return gpa;}; public int clacScholarship() { return tuition / 2; } public String toString() { return "학번:..
-
학생 정보 출력 (super)코딩/java 2019. 3. 8. 16:22
public class Student { private int id; private int tuition; private double gpa; public void setTuition(int tuition) {this.tuition = tuition;}; public void setGpa(double gpa) {this.gpa = gpa;}; public int getId() {return id;}; public int getTuition() {return tuition;}; public double getGpa() {return gpa;}; public String toString() { return "학번: " + id + ", 등록금: " + tuition + ", 평균등급: " + gpa; } p..
-
상자 정보 (상속 super)코딩/java 2019. 3. 4. 23:08
public class Box { private int x; private int y; private int z; private boolean empty; public String toString() { String rslt = "가로: " + x + "cm 세로: " + y + "cm 높이: " + z + "cm"; /*if (empty) return rslt + "지금 박스는 비어있습니다.\n"; else return rslt + "지금 박스에는 물건이 들어있습니다.\n";*/ return rslt; } public void fillBox() { this.empty = false; } public void emptyBox() { this.empty = true; } public int getVolum..
-
사각형, 도형 정보 출력코딩/java 2019. 3. 3. 17:37
public class Shape { private int x; private int y; public void setX(int x) {this.x = x;}; public void setY(int y) {this.y = y;}; public int getX() {return x;}; public int getY() {return y;}; public String toString() { return "::중심좌표 (" + x + ", " + y + ")"; } public int area() { return 0; } public int perimeter() { return 0; } public Shape() { x = 0; y = 0; } } public class Rectangle extends Sha..
-
음식 정보 출력(package)코딩/java 2019. 3. 3. 16:00
package Fruit; public class Food { int calory; protected int price; protected double weight; public int getCalory() {return calory;}; //NoFruit에도 쓸 수 있게 메소드 추가하였다. public int getPrice() {return price;}; public double getWeight() {return weight;}; public void setCalory(int calory) {this.calory = calory;}; public void setPrice(int price) {this.price = price;}; public void setWeight(double weight) ..
-
음식 정보 출력코딩/java 2019. 3. 3. 15:42
public class Food { int calory; protected int price; protected double weight; public String toString() { return "칼로리: " + calory +"\n가격: " + price + "\n무게: " + weight; } } public class Melon extends Food{ String farmInfo; public String toString() { return "칼로리: " + calory +"\n가격: " + price + "\n무게: " + weight + "\n재배농장: " + farmInfo; } } public class Potato extends Food{ public int getUnitPrice(..
-
주사위 던지기2코딩/java 2019. 3. 3. 15:38
package casino; public class Practice66B { public static void main(String[] args) { int i = 1; game.Dice dice1 = new game.Dice(); game.Dice dice2 = new game.Dice(); do { dice1.roll(); dice2.roll(); System.out.println(i + "차: 첫번째 " + dice1.toString() + ", 두번째 " + dice2.toString()); i++; } while (dice1.getValue() != dice2.getValue()); System.out.println("게임이 종료되었습니다."); } } package casino; import ..
-
랜덤 주사위 (같은 수가 나올 때까지)코딩/java 2019. 3. 3. 13:53
import java.util.Random; public class Dice { Random rg = new Random(); private int value; public void roll() { value = rg.nextInt(6) + 1; } public int getValue() {return value;}; private void setValue(int value) {this.value = value;}; public String toString() { return "주사위 = " + value; } public Dice() { setValue(0); } } public class Practice_65 { public static void main(String[] args) { int i = ..