Advertisement
MrDoyle

OOP) Minecraft Exam

Apr 9th, 2021
1,479
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.66 KB | None | 0 0
  1. import java.util.HashMap;
  2. import java.util.Scanner;
  3. import java.util.ArrayList;
  4.  
  5. public class CustomMob extends MinecraftMobs{
  6.  
  7.     String name;
  8.     String type;
  9.     String hostility;
  10.     String colour;
  11.  
  12.  
  13.     public CustomMob (String name, String type, String colour, String hostility, String location){
  14.         this.name = name;
  15.         this.type = type;
  16.         this.colour = colour;
  17.         this.hostility = hostility;
  18.         this.location = location;
  19.     }
  20.     public String getName (){
  21.         return name;
  22.     }
  23.  
  24.     public String changeName (){
  25.         System.out.println();
  26.         System.out.print("Please enter the new name for your mob: ");
  27.         Scanner keyboard = new Scanner(System.in);
  28.         name = keyboard.next();
  29.         return name;
  30.     }
  31.  
  32.     public String getType (){
  33.         return type;
  34.     }
  35.  
  36.     public String changeType (){
  37.         System.out.println();
  38.         System.out.print("Please enter the new type for your mob: ");
  39.         Scanner keyboard = new Scanner(System.in);
  40.         String newType = keyboard.next();
  41.         type = newType;
  42.         return type;
  43.     }
  44.  
  45.     public String getColour(){
  46.         return colour;
  47.     }
  48.  
  49.     public String changeColour(){
  50.         System.out.println();
  51.         System.out.print("Please input the new colour for your mob: ");
  52.         Scanner keyboard = new Scanner(System.in);
  53.         String newColour = keyboard.next();
  54.         colour = newColour;
  55.         return colour;
  56.     }
  57.  
  58.     public String getHostility (){
  59.         return hostility;
  60.     }
  61.  
  62.     public String changeHostility(){
  63.         System.out.println();
  64.         Scanner keyboard = new Scanner(System.in);
  65.         System.out.print("Select your mob's hostility level (1=friendly, 2=passive or 3=hostile): ");
  66.         int hostilitySelection = keyboard.nextInt();
  67.  
  68.         if(hostilitySelection==1){
  69.             hostility = "friendly";
  70.         }else if (hostilitySelection==2){
  71.             hostility = "passive";
  72.         }else{
  73.             hostility = "hostile";
  74.         }
  75.         return hostility;
  76.     }
  77.  
  78.     public void getStats (CustomMob mob){
  79.         System.out.println();
  80.  
  81.         HashMap<String, String> mobStats = new HashMap<>();
  82.         mobStats.put("Name", mob.getName());
  83.         mobStats.put("Type", mob.getType());
  84.         mobStats.put("Colour", mob.getColour());
  85.         mobStats.put("Hostility", mob.getHostility());
  86.         mobStats.put("Location", mob.getLocation());
  87.  
  88.         for(String slot: mobStats.keySet()){
  89.             System.out.println(slot + ": " + mobStats.get(slot));
  90.         }
  91.     }
  92.  
  93.     public static void main(String[] args) {
  94.         System.out.println();
  95.         System.out.println("This code helps you to create custom Minecraft mob");
  96.         System.out.println("Lets create our new mob: ");
  97.         System.out.print("Enter your mob's name: ");
  98.         Scanner keyboard1 = new Scanner(System.in);
  99.         String newName = keyboard1.next();
  100.         System.out.print("Enter your mob's type: ");
  101.         String newType = keyboard1.next();
  102.         System.out.print("Enter your mob's colour: ");
  103.         String newColour = keyboard1.next();
  104.         System.out.print("Select your mob's hostility level (1=friendly, 2=passive or 3=hostile): ");
  105.             int hostilitySelection = keyboard1.nextInt();
  106.             String newHostility;
  107.             if(hostilitySelection==1){
  108.                 newHostility = "friendly";
  109.             }else if (hostilitySelection==2){
  110.                 newHostility = "passive";
  111.             }else{
  112.                 newHostility = "hostile";
  113.             }
  114.         System.out.print("Enter your mob's preferred biome location: ");
  115.         String newLocation = keyboard1.next();
  116.  
  117.         CustomMob mob = new CustomMob(newName, newType, newColour, newHostility, newLocation);
  118.  
  119.             System.out.println();
  120.             System.out.println("Select your next action from the list below:");
  121.             System.out.println("1) Check the name of your mob");
  122.             System.out.println("2) Rename your mob");
  123.             System.out.println("3) Check the type of your mob");
  124.             System.out.println("4) Change the type of your mob");
  125.             System.out.println("5) Check the colour of your mob");
  126.             System.out.println("6) Change the colour of your mob");
  127.             System.out.println("7) Check the hostility of your mob");
  128.             System.out.println("8) Change the hostility of your mob");
  129.             System.out.println("9) Check the location of your mob");
  130.             System.out.println("10) Change the location of your mob");
  131.             System.out.println("11) Print the stats of your mob");
  132.             System.out.println("12) Exit the simulation");
  133.  
  134.             while(true) {
  135.                 Scanner keyboard = new Scanner(System.in);
  136.                 int option = keyboard.nextInt();
  137.  
  138.                 if (option == 1) {
  139.                     System.out.println("The name of your mob is: " + mob.getName());
  140.                 } else if (option == 2) {
  141.                     System.out.println("The new name of your mob is: " + mob.changeName());
  142.                 } else if (option == 3) {
  143.                     System.out.println("Your mob is a " + mob.getType() + " type");
  144.                 } else if (option == 4) {
  145.                     System.out.println("The new type of your mob is: " + mob.changeType());
  146.                 } else if (option == 5) {
  147.                     System.out.println("Your mob's colour is: " + mob.getColour());
  148.                 } else if (option == 6) {
  149.                     System.out.println("The new colour of your mob is: " + mob.changeColour());
  150.                 } else if (option == 7) {
  151.                     System.out.println("Your mob's hostility is classed as: " + mob.getHostility());
  152.                 } else if (option == 8) {
  153.                     System.out.println("Your mob is now classed as a " + mob.changeHostility() + " mob");
  154.                 } else if (option == 9) {
  155.                     System.out.println("Your current mob's preferred location is: " + mob.getLocation());
  156.                 } else if (option == 10) {
  157.                     System.out.println("Your mob's new location is " + mob.changeLocation());
  158.                 } else if (option == 11) {
  159.                     System.out.println("The current stats for your new mob:");
  160.                     mob.getStats(mob);
  161.                 } else if (option == 12) {
  162.                     System.out.println("Thank you for choosing the Custom Mobinator Program");
  163.                     System.out.println("These are the final stats for your new mob:");
  164.                     mob.getStats(mob);
  165.                     break;
  166.  
  167.                 } else {
  168.                     System.out.println("Please select a valid option from the menu");
  169.                 }
  170.  
  171.                     System.out.println();
  172.                     System.out.print("Please choose again from the menu: ");
  173.         }
  174.     }
  175. }
  176.  
  177. class MinecraftMobs {
  178.  
  179.     String location;
  180.  
  181.     public String getLocation(){
  182.         return location;
  183.     }
  184.  
  185.     public String changeLocation (){
  186.         ArrayList<String> biomes = new ArrayList<>();
  187.         biomes.add("Plains");
  188.         biomes.add("Water");
  189.         biomes.add("Underground");
  190.         biomes.add("The Nether");
  191.         biomes.add("The End");
  192.  
  193.         System.out.println("Choose the location you wish your mob to be most likely found in: ");
  194.         for (int i = 0; i<biomes.size(); i++) {
  195.             System.out.println((i+1) + ") " + biomes.get(i));
  196.         }
  197.         System.out.print("Enter the number: ");
  198.         Scanner keyboard = new Scanner(System.in);
  199.         int mobLocation = keyboard.nextInt();
  200.  
  201.         return biomes.get(mobLocation-1);
  202.     }
  203. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement