MrDoyle

OOP instance variables at the class level

May 10th, 2021
820
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.99 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class CustomMob {
  4.  
  5.     String name;
  6.     String type;
  7.     String hostility;
  8.     String colour;
  9.  
  10.     public CustomMob (String name, String type, String colour, String hostility, String location){
  11.         this.name =name;
  12.         this.type =type;
  13.         this.hostility = hostility;
  14.         this.colour=colour;
  15.     }
  16.  
  17.     public String getName (){
  18.         return name;
  19.     }
  20.  
  21.     public void changeName(String newName){
  22.         name = newName;
  23.     }
  24.  
  25.  
  26.     public static void main(String[] args){
  27.  
  28.         CustomMob myNewMob = new CustomMob("Bob", "Creeper","green","Dangerous","plains");
  29.         System.out.println("My mobs name is: " +myNewMob.getName());
  30.         Scanner input = new Scanner(System.in);
  31.         System.out.println("Please input the new name you want for your mob");
  32.         String newName = input.next();
  33.         myNewMob.changeName(newName);
  34.  
  35.         System.out.println("My mobs name is: " +myNewMob.getName());
  36.  
  37.  
  38.     }
  39. }
  40.  
Advertisement
Add Comment
Please, Sign In to add comment