P168 실전 연습(권한 수식자)
1 package org.hanqi.pn0120;
2
3 public class Game {
4
5 private String name;
6 private String category;
7 private int totalcost = 10000;
8
9 public String getName() {
10 return name;
11 }
12 public void setName(String name) {
13 this.name = name;
14 }
15 public String getCategory() {
16 return category;
17 }
18 public void setCategory(String category) {
19 this.category = category;
20 }
21 public int getTotalcost() {
22 return totalcost;
23 }
24 public void setTotalcost(int totalcost) {
25 this.totalcost = totalcost;
26 }
27
28 public Game(String name, String category) {
29 super();
30 this.name = name;
31 this.category = category;
32 }
33
34 public void cost1(int cost)
35 {
36 if(cost <= 0)
37 {
38 System.out.println(" ?!");
39 }
40 else if(cost>this.totalcost)
41 {
42 int excess=cost-this.totalcost;
43 System.out.println(" , "+excess+" ");
44 }
45 else
46 {
47 this.totalcost=cost;
48 System.out.println(" "+this.totalcost);
49 }
50 }
51
52 private int sales;
53 public int getSales()
54 {
55 return this.sales;
56 }
57 public void money(int number,int price)
58 {
59 if(number<=0)
60 {
61 System.out.println(" , , ");
62 }
63 else if(price<=0)
64 {
65 System.out.println(" 0?");
66 }
67 else if(price>50)
68 {
69 System.out.println(" ");
70 }
71 else
72 {
73 this.sales=number*price;
74 System.out.println(" "+sales);
75
76 if(this.sales<this.totalcost)
77 {
78 int debt = this.totalcost-this.sales;
79 System.out.println(" , , "+debt+" ");
80 }
81 else
82 {
83 int profit = this.sales-this.totalcost;
84 System.out.println(" , "+profit);
85 }
86 }
87 }
88
89 public static void main(String[]args)
90 {
91 Game myGame = new Game(" ","Galgame");
92 System.out.println(" :"+myGame.getName());
93 System.out.println(" :"+myGame.getCategory());
94 myGame.cost1(-10000);
95 myGame.cost1(20000);
96 myGame.cost1(2000);
97 myGame.money(0, 25);
98 myGame.money(14, 0);
99 myGame.money(200, 88);
100 myGame.money(200, 25);
101 }
102 }
실행 코드는 다음과 같습니다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.