Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class Weapon {
- // Variables
- String name;
- String type;
- String color;
- float damage;
- // *******************************************************************************************************************************************************************
- // *******************************************************************************************************************************************************************
- // *******************************************************************************************************************************************************************
- // *******************************************************************************************************************************************************************
- // Constructors
- Weapon(){
- name = "M4A1";
- type = "Rifle";
- color = "grey";
- damage = 30;
- }
- Weapon(String name, String color){
- // Create 2 lists with the possible names and colors
- ArrayList <String> names = new ArrayList <String> ();
- names.add("AK47");
- names.add("M4A1");
- names.add("Pump Shotgun");
- names.add("Tactical Shotgun");
- names.add("Bolt-Action Sniper");
- names.add("Heavy Sniper");
- ArrayList <String> colors = new ArrayList <String> ();
- colors.add("grey");
- colors.add("green");
- colors.add("blue");
- colors.add("purple");
- colors.add("gold");
- // First, I will check if there is both valid name and color (I suppose that they are invalid in the beginning)
- boolean validName = false;
- boolean validColor = false;
- // Cases of invalid inputs/parameters
- for(int i=0; i<names.size(); i++) {
- if(name == names.get(i)) {
- validName = true;
- break;
- }
- }
- for(int i=0; i<colors.size(); i++) {
- if(color == colors.get(i)) {
- validColor = true;
- }
- }
- // I have completed the value assignment of the 2 flags
- if(validName == true && validColor == true) {
- this.name = name;
- this.color = color;
- // About variable "type"
- if(name == names.get(0) || name == names.get(1)) {
- this.type = "Rifle";
- }
- else if(name == names.get(2) || name == names.get(3)) {
- this.type = "Shotgun";
- }
- else if(name == names.get(4) || name == names.get(5)) {
- this.type = "Sniper";
- }
- // About variable "damage"
- // RIFLES
- if(name == "AK47" && color == "grey") {
- this.damage = 38;
- }
- else if(name == "AK47" && color == "green") {
- this.damage = 40;
- }
- else if(name == "AK47" && color == "blue") {
- this.damage = 42;
- }
- else if(name == "M4A1" && color == "grey") {
- this.damage = 30;
- }
- else if(name == "M4A1" && color == "green") {
- this.damage = 31;
- }
- else if(name == "M4A1" && color == "blue") {
- this.damage = 33;
- }
- // SHOTGUNS
- else if(name == "Pump Shotgun" && color == "grey") {
- this.damage = 70;
- }
- else if(name == "Pump Shotgun" && color == "green") {
- this.damage = 80;
- }
- else if(name == "Pump Shotgun" && color == "blue") {
- this.damage = 90;
- }
- else if(name == "Tactical Shotgun" && color == "grey") {
- this.damage = 71;
- }
- else if(name == "Tactical Shotgun" && color == "green") {
- this.damage = 75;
- }
- else if(name == "Tactical Shotgun" && color == "blue") {
- this.damage = 79;
- }
- else if(name == "Tactical Shotgun" && color == "purple") {
- this.damage = 83;
- }
- else if(name == "Tactical Shotgun" && color == "gold") {
- this.damage = 87;
- }
- // SNIPERS
- else if(name == "Bolt-Action Sniper" && color == "green") {
- this.damage = 100;
- }
- else if(name == "Bolt-Action Sniper" && color == "blue") {
- this.damage = 105;
- }
- else if(name == "Bolt-Action Sniper" && color == "purple") {
- this.damage = 110;
- }
- else if(name == "Bolt-Action Sniper" && color == "gold") {
- this.damage = 116;
- }
- else if(name == "Heavy Sniper" && color == "purple") {
- this.damage = 150;
- }
- else if(name == "Heavy Sniper" && color == "gold") {
- this.damage = 157;
- }
- }
- else {
- System.out.println("Not valid inputs as parameters");
- System.out.println(color + " " + name + " is not a weapon in this game.");
- }
- }
- // *******************************************************************************************************************************************************************
- // *******************************************************************************************************************************************************************
- // *******************************************************************************************************************************************************************
- // *******************************************************************************************************************************************************************
- // Methods
- void showStatus() {
- System.out.println("Name: " + name);
- System.out.println("Type: " + type);
- System.out.println("Color: " + color);
- System.out.println("Damage: " + damage);
- System.out.println();
- }
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- Weapon a = new Weapon("Tactical Shotgun", "blue");
- a.showStatus();
- Weapon b = new Weapon();
- b.showStatus();
- Weapon c = new Weapon("Sniper", "mple");
- c.showStatus();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement