Advertisement
makispaiktis

Players with Weapons (Class Weapon)

Oct 30th, 2019 (edited)
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.41 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class Weapon {
  4.  
  5.     // Variables
  6.     String name;
  7.     String type;
  8.     String color;
  9.     float damage;
  10.    
  11.     // *******************************************************************************************************************************************************************
  12.     // *******************************************************************************************************************************************************************
  13.     // *******************************************************************************************************************************************************************
  14.     // *******************************************************************************************************************************************************************
  15.     // Constructors
  16.     Weapon(){
  17.         name = "M4A1";
  18.         type = "Rifle";
  19.         color = "grey";
  20.         damage = 30;
  21.     }
  22.    
  23.     Weapon(String name, String color){
  24.         // Create 2 lists with the possible names and colors
  25.         ArrayList <String> names = new ArrayList <String> ();
  26.         names.add("AK47");
  27.         names.add("M4A1");
  28.         names.add("Pump Shotgun");
  29.         names.add("Tactical Shotgun");
  30.         names.add("Bolt-Action Sniper");
  31.         names.add("Heavy Sniper");
  32.         ArrayList <String> colors = new ArrayList <String> ();
  33.         colors.add("grey");
  34.         colors.add("green");
  35.         colors.add("blue");
  36.         colors.add("purple");
  37.         colors.add("gold");
  38.         // First, I will check if there is both valid name and color (I suppose that they are invalid in the beginning)
  39.         boolean validName = false;
  40.         boolean validColor = false;
  41.         // Cases of invalid inputs/parameters
  42.         for(int i=0; i<names.size(); i++) {
  43.             if(name == names.get(i)) {
  44.                 validName = true;
  45.                 break;
  46.             }
  47.         }
  48.        
  49.         for(int i=0; i<colors.size(); i++) {
  50.             if(color == colors.get(i)) {
  51.                 validColor = true;
  52.             }
  53.         }
  54.        
  55.         // I have completed the value assignment of the 2 flags
  56.         if(validName == true && validColor == true) {
  57.             this.name = name;
  58.             this.color = color;
  59.            
  60.             // About variable "type"
  61.             if(name == names.get(0) || name == names.get(1)) {
  62.                 this.type = "Rifle";
  63.             }
  64.             else if(name == names.get(2) || name == names.get(3)) {
  65.                 this.type = "Shotgun";
  66.             }
  67.             else if(name == names.get(4) || name == names.get(5)) {
  68.                 this.type = "Sniper";
  69.             }
  70.            
  71.             // About variable "damage"
  72.             // RIFLES
  73.             if(name == "AK47" && color == "grey") {
  74.                 this.damage = 38;
  75.             }
  76.             else if(name == "AK47" && color == "green") {
  77.                 this.damage = 40;
  78.             }
  79.             else if(name == "AK47" && color == "blue") {
  80.                 this.damage = 42;
  81.             }
  82.             else if(name == "M4A1" && color == "grey") {
  83.                 this.damage = 30;
  84.             }
  85.             else if(name == "M4A1" && color == "green") {
  86.                 this.damage = 31;
  87.             }
  88.             else if(name == "M4A1" && color == "blue") {
  89.                 this.damage = 33;
  90.             }
  91.            
  92.            
  93.             // SHOTGUNS
  94.             else if(name == "Pump Shotgun" && color == "grey") {
  95.                 this.damage = 70;
  96.             }
  97.             else if(name == "Pump Shotgun" && color == "green") {
  98.                 this.damage = 80;
  99.             }
  100.             else if(name == "Pump Shotgun" && color == "blue") {
  101.                 this.damage = 90;
  102.             }
  103.             else if(name == "Tactical Shotgun" && color == "grey") {
  104.                 this.damage = 71;
  105.             }
  106.             else if(name == "Tactical Shotgun" && color == "green") {
  107.                 this.damage = 75;
  108.             }
  109.             else if(name == "Tactical Shotgun" && color == "blue") {
  110.                 this.damage = 79;
  111.             }
  112.             else if(name == "Tactical Shotgun" && color == "purple") {
  113.                 this.damage = 83;
  114.             }
  115.             else if(name == "Tactical Shotgun" && color == "gold") {
  116.                 this.damage = 87;
  117.             }
  118.            
  119.            
  120.             // SNIPERS
  121.             else if(name == "Bolt-Action Sniper" && color == "green") {
  122.                 this.damage = 100;
  123.             }
  124.             else if(name == "Bolt-Action Sniper" && color == "blue") {
  125.                 this.damage = 105;
  126.             }
  127.             else if(name == "Bolt-Action Sniper" && color == "purple") {
  128.                 this.damage = 110;
  129.             }
  130.             else if(name == "Bolt-Action Sniper" && color == "gold") {
  131.                 this.damage = 116;
  132.             }
  133.             else if(name == "Heavy Sniper" && color == "purple") {
  134.                 this.damage = 150;
  135.             }
  136.             else if(name == "Heavy Sniper" && color == "gold") {
  137.                 this.damage = 157;
  138.             }  
  139.            
  140.            
  141.         }
  142.        
  143.         else {
  144.             System.out.println("Not valid inputs as parameters");
  145.             System.out.println(color + " " + name + " is not a weapon in this game.");
  146.         }
  147.        
  148.        
  149.     }
  150.    
  151.     // *******************************************************************************************************************************************************************
  152.     // *******************************************************************************************************************************************************************
  153.     // *******************************************************************************************************************************************************************
  154.     // *******************************************************************************************************************************************************************
  155.    
  156.    
  157.     // Methods
  158.     void showStatus() {
  159.         System.out.println("Name: " + name);
  160.         System.out.println("Type: " + type);
  161.         System.out.println("Color: " + color);
  162.         System.out.println("Damage: " + damage);
  163.         System.out.println();
  164.     }
  165.    
  166.    
  167.    
  168.    
  169.    
  170.     public static void main(String[] args) {
  171.         // TODO Auto-generated method stub
  172.         Weapon a = new Weapon("Tactical Shotgun", "blue");
  173.         a.showStatus();
  174.         Weapon b = new Weapon();
  175.         b.showStatus();
  176.         Weapon c = new Weapon("Sniper", "mple");
  177.         c.showStatus();
  178.  
  179.     }
  180.  
  181. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement