Advertisement
Guest User

Untitled

a guest
Feb 17th, 2020
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.15 KB | None | 0 0
  1. ###################################################
  2.  
  3.  
  4. package predmet;
  5.  
  6.  
  7. public class predmet {
  8. protected String nazev;
  9. protected int body;
  10. protected boolean zapocet = false;
  11. protected static final int MIN_BOD = 15;
  12.  
  13.  
  14.  
  15.  
  16. public int getBody()
  17. {
  18. return this.body;
  19. }
  20. public void setBody(int body)
  21. {
  22. this.body = body;
  23. }
  24.  
  25. public String getNazev()
  26. {
  27. return this.nazev;
  28. }
  29.  
  30. public boolean getZapocet()
  31. {
  32. if (getBody() >= MIN_BOD)
  33. this.zapocet = true;
  34. return this.zapocet;
  35. }
  36.  
  37. }
  38.  
  39. ##############################################
  40.  
  41.  
  42.  
  43. package predmet;
  44.  
  45. public class Bpc1 extends predmet{
  46.  
  47. private String nazev = "BPC-1";
  48. private int cvik = 0;
  49. private int exam = 0;
  50. public int getCvik()
  51. {
  52. return cvik;
  53. }
  54. public void setCvik(int body)
  55. {
  56. this.cvik+= body;
  57. if (this.cvik > 20)
  58. this.cvik = 20;
  59. }
  60. public void setExam(int body)
  61. {
  62. this.exam+= body;
  63. if (this.exam > 80)
  64. this.exam = 80;
  65. }
  66. public int getBody()
  67. {
  68. this.body = this.cvik + this.exam;
  69. return body;
  70. }
  71.  
  72. }
  73.  
  74.  
  75.  
  76.  
  77. ##############################################
  78.  
  79.  
  80.  
  81.  
  82. package predmet;
  83.  
  84. public class Bpc2 extends predmet {
  85. String nazev = "BPC-2";
  86. int projekt = 0;
  87. int halfExam = 0;
  88. int exam = 0;
  89.  
  90. public void setExam(int body)
  91. {
  92. this.exam+= body;
  93. if (this.exam > 50)
  94. this.exam = 50;
  95. }
  96. public void setHalfExam(int body)
  97. {
  98. this.halfExam+= body;
  99. if (this.halfExam > 30)
  100. this.halfExam = 30;
  101. }
  102. public void setProjekt(int body)
  103. {
  104. this.projekt+= body;
  105. if (this.projekt > 20)
  106. this.projekt = 20;
  107. }
  108. public int getBody()
  109. {
  110. this.body = this.projekt + this.exam + this.halfExam;
  111. return body;
  112. }
  113. }
  114.  
  115.  
  116.  
  117.  
  118.  
  119. #######################################################
  120.  
  121.  
  122.  
  123. package predmet;
  124.  
  125. public class Bpis extends predmet {
  126. public void setZapocet()
  127. {
  128. this.zapocet = true;
  129. }
  130. }
  131.  
  132.  
  133. ######################################################
  134.  
  135.  
  136. package predmet;
  137. import java.util.Scanner;
  138.  
  139. public class Test {
  140.  
  141. public static void main(String[] args) {
  142. Scanner sc = new Scanner(System.in);
  143. Bpc1 bpc1 = new Bpc1();
  144. Bpc2 bpc2 = new Bpc2();
  145. Bpis bpis = new Bpis();
  146.  
  147.  
  148.  
  149. System.out.println("Zadejte body za cviceni BPC-1: ");
  150. while(true)
  151. {
  152. if(sc.hasNext())
  153. {
  154. bpc1.setCvik(sc.nextInt());
  155. break;
  156. }
  157. else
  158. System.out.println("Spatny format, zkuste znovu");
  159.  
  160.  
  161. }
  162.  
  163. System.out.println("Zadejte body za zkousku BPC-1: ");
  164.  
  165.  
  166. while(true)
  167. {
  168. if(sc.hasNext())
  169. {
  170. bpc1.setExam(sc.nextInt());
  171. break;
  172. }
  173. else
  174. System.out.println("Spatny format, zkuste znovu");
  175.  
  176.  
  177. }
  178.  
  179.  
  180. System.out.println("Zadejte body za projekt BPC-2: ");
  181. while(true)
  182. {
  183. if(sc.hasNext())
  184. {
  185. bpc2.setProjekt(sc.nextInt());
  186. break;
  187. }
  188. else
  189. System.out.println("Spatny format, zkuste znovu");
  190.  
  191.  
  192. }
  193. System.out.println("Zadejte body za pulsemestralni zlousku BPC-2: ");
  194. while(true)
  195. {
  196. if(sc.hasNext())
  197. {
  198. bpc2.setHalfExam(sc.nextInt());
  199. break;
  200. }
  201. else
  202. System.out.println("Spatny format, zkuste znovu");
  203.  
  204.  
  205. }
  206.  
  207. System.out.println("Zadejte body za zkousku BPC-2: ");
  208. while(true)
  209. {
  210. if(sc.hasNext())
  211. {
  212. bpc2.setExam(sc.nextInt());
  213. break;
  214. }
  215. else
  216. System.out.println("Spatny format, zkuste znovu");
  217.  
  218.  
  219. }
  220.  
  221. System.out.println("Zapocet z BPIS (true/false): ");
  222. while(true)
  223. {
  224. if(sc.hasNextBoolean() && sc.nextBoolean() == true )
  225. {
  226. bpis.setZapocet();
  227. break;
  228. }
  229. else if(sc.hasNextBoolean() && sc.nextBoolean() == false)
  230. {
  231. break;
  232. }
  233. else
  234. System.out.println("Spatny format, zkuste znovu");
  235. }
  236.  
  237. if(bpc1.getZapocet() == true)
  238. System.out.println("BPC-1 zapocet udelan");
  239. else
  240. System.out.println("BPC-1 zapocet neudelan");
  241. if(bpc2.getZapocet() == true)
  242. System.out.println("BPC-2 zapocet udelan");
  243. else
  244. System.out.println("BPC-1 zapocet neudelan");
  245. if(bpc1.getZapocet() == true)
  246. System.out.println("BPIS zapocet udelan");
  247. else
  248. System.out.println("BPC-1 zapocet neudelan");
  249.  
  250.  
  251. }
  252.  
  253. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement