Advertisement
Guest User

Untitled

a guest
Feb 28th, 2020
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.57 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. class JavaZoo
  4. {
  5. public static void main(String []args)
  6. {
  7. Scanner sc = new Scanner(System.in);
  8. ZooAnimal myFirstAnimal = new ZooAnimal("Chip", "Monkey", 5, false);
  9. Cage myFirstCage=new Cage(15, 20, 15, false, false);
  10. ZooKeeper myFirstZooKeeper = new ZooKeeper("Mr.Jackson", "ZooKeeper", 15, false);
  11.  
  12. int choice = 0;
  13.  
  14. do
  15. {
  16. System.out.println("[1]Feed");
  17. System.out.println("[2]Put To Sleep");
  18. System.out.println("[3]Clean Cage");
  19. System.out.println("[4]View All Information");
  20. System.out.println("[5]Exit");
  21. System.out.print("Enter Choice: ");
  22.  
  23. try
  24. {
  25. choice = Integer.parseInt(sc.nextLine());
  26. }
  27. catch(Exception e)
  28. {
  29.  
  30. }
  31.  
  32. switch(choice)
  33. {
  34. case 1:
  35. if(myFirstAnimal.isHungry() == true)
  36. {
  37. if(myFirstCage.isClean() == true)
  38. {
  39. myFirstZooKeeper.CoverCage();
  40. myFirstZooKeeper.FeedAnimal();
  41. myFirstAnimal.eat();
  42.  
  43. myFirstCage.Cleaned(false);
  44. myFirstCage.Covered(false);
  45. }
  46. else
  47. {
  48. if(myFirstCage.isClean() == false && myFirstAnimal.isHungry() == true)
  49. {
  50. System.out.println(myFirstAnimal.getName() + " is not eating because the cage is dirty.");
  51. }
  52. else if(myFirstCage.isClean() == true && myFirstAnimal.isHungry() == false)
  53. {
  54. System.out.println(myFirstAnimal.getName() + "is not hungry.");
  55. }
  56. }
  57. }
  58. else
  59. {
  60. System.out.println(myFirstAnimal.getName() + " is not hungry.");
  61. }
  62. break;
  63. case 2:
  64. if(myFirstAnimal.isHungry() == false)
  65. {
  66. if(myFirstCage.isCovered() == false)
  67. {
  68. myFirstZooKeeper.CoverCage();
  69. myFirstAnimal.Sleep();
  70.  
  71. myFirstAnimal.isHungry();
  72. myFirstCage.Covered(true);
  73. }
  74. else
  75. {
  76. if(myFirstCage.isCovered() == true && myFirstAnimal.isHungry() == true)
  77. {
  78. System.out.println(myFirstAnimal.getName() + " is not sleeping because it's hungry.");
  79. }
  80. else if(myFirstCage.isCovered() == false && myFirstAnimal.isHungry() == false)
  81. {
  82. System.out.println(myFirstAnimal.getName() + "is awake.");
  83. }
  84. }
  85. }
  86. else
  87. {
  88. System.out.println(myFirstAnimal.getName() + " is awake.");
  89. }
  90. break;
  91. case 3:
  92. if(myFirstCage.isClean() == false)
  93. {
  94. myFirstZooKeeper.CleanCage();
  95.  
  96. myFirstCage.Cleaned(true);
  97. }
  98. else
  99. {
  100. System.out.println("The cage is already cleaned.");
  101. }
  102.  
  103.  
  104. break;
  105. case 4:
  106. System.out.println("\nAnimal");
  107. System.out.println("Animal Name: " + myFirstAnimal.getName());
  108. System.out.println("Type: " + myFirstAnimal.getType());
  109. System.out.println("Age: " + myFirstAnimal.getAge());
  110. System.out.println("Not Hungry?: " + myFirstAnimal.isHungry());
  111.  
  112. System.out.println("\nCage");
  113. System.out.println("Length: " + myFirstCage.getLength());
  114. System.out.println("Width: " + myFirstCage.getWidth());
  115. System.out.println("Height: " + myFirstCage.getHeight());
  116. System.out.println("Clean Cage?: " + myFirstCage.isClean());
  117. System.out.println("Covered Cage?: " + myFirstCage.isCovered());
  118.  
  119. System.out.println("\nName");
  120. System.out.println("Name: " + myFirstZooKeeper.getName());
  121. System.out.println("Title: " + myFirstZooKeeper.getTitle());
  122. System.out.println("Payrate: " + myFirstZooKeeper.getPayrate());
  123. System.out.println("Has Degree?: " + myFirstZooKeeper.hasDegree());
  124.  
  125. break;
  126. case 5:
  127. System.out.println("Exiting...");
  128. break;
  129. default:
  130. System.out.println("Invalid Choice");
  131. }
  132. }
  133. while(choice != 5);
  134. }
  135. }
  136.  
  137. class Cage
  138. {
  139. private int Length;
  140. private int Width;
  141. private int Height;
  142. private boolean Clean;
  143. private boolean Covered;
  144.  
  145. public Cage()
  146. {
  147. Length = 0;
  148. Width = 0;
  149. Height = 0;
  150. Clean = false;
  151. Covered = false;
  152. }
  153.  
  154. public Cage(int Length, int Width, int Height, boolean Clean, boolean Covered)
  155. {
  156. this.Length = Length;
  157. this.Width = Width;
  158. this.Height = Height;
  159. this.Clean = Clean;
  160. this.Covered = Covered;
  161. }
  162.  
  163. public void setLength(int Length)
  164. {
  165. this.Length = Length;
  166. }
  167.  
  168. public void setWidth(int Width)
  169. {
  170. this.Width = Width;
  171. }
  172.  
  173. public void setHeight(int Height)
  174. {
  175. this.Height = Height;
  176. }
  177.  
  178. public int getLength()
  179. {
  180. return this.Length;
  181. }
  182.  
  183. public int getWidth()
  184. {
  185. return this.Width;
  186. }
  187.  
  188. public int getHeight()
  189. {
  190. return this.Height;
  191. }
  192.  
  193. public void Cleaned(boolean Clean)
  194. {
  195. this.Clean = Clean;
  196. }
  197.  
  198. public void Covered(boolean Covered)
  199. {
  200. this.Covered = Covered;
  201. }
  202.  
  203. public boolean isClean()
  204. {
  205. return this.Clean;
  206. }
  207.  
  208. public boolean isCovered()
  209. {
  210. return this.Covered;
  211. }
  212. }
  213.  
  214.  
  215. class ZooKeeper
  216. {
  217. private String Name;
  218. private String Title;
  219. private double Payrate;
  220. private boolean Degree;
  221.  
  222. Cage cage = new Cage();
  223.  
  224. public ZooKeeper()
  225. {
  226. this.Name = " ";
  227. this.Title = " ";
  228. this.Payrate = 0;
  229. this.Degree = false;
  230. }
  231.  
  232. public ZooKeeper(String Name, String Title, double Payrate, boolean Degree)
  233. {
  234. this.Name = Name;
  235. this.Title = Title;
  236. this.Payrate = Payrate;
  237. this.Degree = Degree;
  238. }
  239.  
  240. public void setName(String Name)
  241. {
  242. this.Name = Name;
  243. }
  244.  
  245. public void setTitle(String Title)
  246. {
  247. this.Title = Title;
  248. }
  249.  
  250. public void setPayrate(double Payrate)
  251. {
  252. this.Payrate = Payrate;
  253. }
  254.  
  255. public void Degree(boolean Degree)
  256. {
  257. this.Degree = Degree;
  258. }
  259.  
  260. public String getName()
  261. {
  262. return this.Name;
  263. }
  264.  
  265. public String getTitle()
  266. {
  267. return this.Title;
  268. }
  269.  
  270. public double getPayrate()
  271. {
  272. return this.Payrate;
  273. }
  274.  
  275. public boolean hasDegree()
  276. {
  277. return this.Degree;
  278. }
  279.  
  280. public void FeedAnimal()
  281. {
  282. System.out.println("Mr.Jackson is feeding the animal.");
  283. }
  284.  
  285. public void CoverCage()
  286. {
  287. System.out.println("Mr.Jackson is covering /uncovering the cage.");
  288. cage.Covered(true);
  289. }
  290.  
  291. public void CleanCage()
  292. {
  293. System.out.println("Mr.Jackson is cleaning the cage.");
  294. }
  295. }
  296.  
  297.  
  298. class ZooAnimal
  299. {
  300. private String Name;
  301. private String Type;
  302. private int Age;
  303. private boolean Hungry;
  304.  
  305. public ZooAnimal()
  306. {
  307. this.Name = " ";
  308. this.Type = " ";
  309. this.Age = 0;
  310. this.Hungry = false;
  311. }
  312.  
  313. public ZooAnimal(String Name, String Type, int Age, boolean Hungry)
  314. {
  315. this.Name = Name;
  316. this.Type = Type;
  317. this.Age = Age;
  318. this.Hungry = Hungry;
  319. }
  320.  
  321. public void setName(String Name)
  322. {
  323. this.Name = Name;
  324. }
  325.  
  326. public void setAge(int Age)
  327. {
  328. this.Age = Age;
  329. }
  330.  
  331. public String getName()
  332. {
  333. return this.Name;
  334. }
  335.  
  336. public String getType()
  337. {
  338. return this.Type;
  339. }
  340.  
  341. public int getAge()
  342. {
  343. return this.Age;
  344. }
  345.  
  346. public boolean isHungry()
  347. {
  348. return this.Hungry;
  349. }
  350.  
  351. public void Sleep()
  352. {
  353. System.out.println("Chip is sleeping.");
  354. Hungry = true;
  355. }
  356.  
  357. public void eat()
  358. {
  359. System.out.println("Chip is eating.");
  360. Hungry = false;
  361. }
  362. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement