As my title states I'm just looking for a little input on how I can improve one of my side projects when I'm not doing my CS assignments. All my program is, is a primitive randomizer for Battlefield 4 classes and weapons (because I can never choose what to play). But since I am still new to java (second semester in) I was wondering if someone more experienced than I could shoot a few concepts my way on how I can make this better, if not more re-useable for other things. Here is my driver:package BattlefieldClassRandomizer;import java.util.Scanner;public class BF4ClassRandomizerDriver {    public static void main(String[] args) {       BattlefieldClass random = new BattlefieldClass();       Scanner keyboard = new Scanner(System.in);       int numberOfClasses;       do{            System.out.print(Choose how many times to randomize: );           numberOfClasses = keyboard.nextInt();       } while (numberOfClasses <= 0);        System.out.println(Here are your soldiers);        for (int r = 0; r < numberOfClasses; r++) {            random.randomizeChance();            random.classSelection();            random.randomizeChance();            random.weaponSelection();            System.out.println(Class: + random.getClassType()+ ; Weapon: + random.getWeaponType());        }       }    }And here is the my entity class (clunky, I know):    package BattlefieldClassRandomizer;//System.out.println(System.getProperty(user.dir));public class BattlefieldClass {    private String classType;    private double chance;    private String weaponType;    BattlefieldClass() {        classType = Assault;        chance = 0.0;        weaponType = Assault Rifle;    }    public String getClassType() {        return classType;    }    public double getChance() {        return chance;    }    public String getWeaponType() {        return weaponType;    }    public void setClassType(String newClassType) {        if ((classType.equals(Assault)) || (classType.equals(Engineer))                || (classType.equals(Support)) || classType.equals(Recon)) {            classType = newClassType;        }    }    public void setWeaponType(String newWeaponType) {        if ((weaponType.equals(Assault)) || (weaponType.equals(Engineer))                || (weaponType.equals(Support)) || weaponType.equals(Recon)) {            classType = newWeaponType;        }    }    public void randomizeChance() {        chance = Math.random();    }    public void classSelection() {        if ((chance >= 0) && (chance < .25)) {            classType = Assault;        }        if ((chance >= .25) && (chance < .50)) {            classType = Engineer;        }        if ((chance >= .50) && (chance < .75)) {            classType = Support;        }        if (chance >= .75) {            classType = Recon;        }    }    public void weaponSelection() {        if ((chance >= 0) && (chance < .25) && (classType.equals(Assault))) {            weaponType = Assault Rifle;        } else if ((chance >= .25) && (chance < .50) && (classType.equals(Assault))) {            weaponType = Carbine;        } else if ((chance >= .50) && (chance < .75) && (classType.equals(Assault))) {            weaponType = DMR;        } else if ((chance >= .75) && (classType.equals(Assault))) {            weaponType = Shotgun;        }        if ((chance >= 0) && (chance < .25) && (classType.equals(Engineer))) {            weaponType = PDW;        } else if ((chance >= .25) && (chance < .50) && (classType.equals(Engineer))) {            weaponType = Carbine;        } else if ((chance >= .50) && (chance < .75) && (classType.equals(Engineer))) {            weaponType = DMR;        } else if ((chance >= .75) && (classType.equals(Engineer))) {            weaponType = Shotgun;        }        if ((chance >= 0) && (chance < .25) && (classType.equals(Support))) {            weaponType = LMG;        } else if ((chance >= .25) && (chance < .50) && (classType.equals(Support))) {            weaponType = Carbine;        } else if ((chance >= .50) && (chance < .75) && (classType.equals(Support))) {            weaponType = DMR;        } else if ((chance >= .75) && (classType.equals(Support))) {            weaponType = Shotgun;        }        if ((chance >= 0) && (chance < .25) && (classType.equals(Recon))) {            weaponType = Sniper Rifle;        } else if ((chance >= .25) && (chance < .50) && (classType.equals(Recon))) {            weaponType = Carbine;        } else if ((chance >= .50) && (chance < .75) && (classType.equals(Recon))) {            weaponType = DMR;        } else if ((chance >= .75) && (classType.equals(Recon))) {            weaponType = Shotgun;        }    }}
Input on where and how I can make improvements on my randomizer
java;random
BugYour setWeaponType function sets classType, not weaponType.You also do not check the input parameters (newClassType and newWeaponType), but classType and weaponType.BracketsI think that you use too many brackets, this makes your code harder to read. Generally, grouping complex boolean expressions with brackets is good, but you don't need to put a single expression in them (eg (classType.equals(Support))).Public MethodsRight now, you have to call 4 methods to use your class. Do you expect use cases where you need to call these methods separately? If not, just make them private and only create one public method (eg called generate).Extract code to functionYou do a lot of range checks in your code, so why not define a function for it:// returns true if input is in between min and max (including min, excluding max).private boolean inInterval(double input, double min, double max) {    return input >= min && input < max;}Then your classSelection function would look like this:public void classSelection() {    if (inInterval(chance, 0, .25)) {        classType = Assault;    } else if (inInterval(chance, 0.25, .50)) {        classType = Engineer;    } else if (inInterval(chance, 0.50, .75)) {        classType = Support;    } else  if (inInterval(chance, .75, 1.0)) {        classType = Recon;    }}Note also that I replaced your ifs with else-ifs, as only one condition can be true at a time. No need to check the other once.You can also use this function in your weaponSelection method.You can do the same for the type checks:private boolean isValidType(String type) {    return  classType.equals(Assault) || classType.equals(Engineer)            || classType.equals(Support) || classType.equals(Recon);}Then use this in your setWeaponType and setClassType functions to avoid duplicate code and to make it easier to add new types. You could also create a list or enum of types to make this a lot easier.Use switch to simplify if statementsIf you use a switch, your if statements in weaponSelection would look like this:public void weaponSelection() {           switch(classType) {        case Assault:             if (inInterval(chance, 0, .25)) {                weaponType = Assault Rifle;            } else if (inInterval(chance, 0.25, .50)) {                weaponType = Carbine;            } else if (inInterval(chance, 0.50, .75)) {                weaponType = Carbine;            } else  if (inInterval(chance, .75, 1.0)) {                weaponType = Shotgun;            }            break;        case Engineer:            [...]            break;        case Support:            [...]            break;        case Recon:            [...]            break;    }}I think that this would be a bit cleaner and more readable.General structureRight now, your class does two things: It selects classes, and - relatively independent of this - it selects weapons.You might consider creating two classes, a WeaponSelector and a ClassSelector. They can both extend a common base class and share some methods (like the inRange and randomizeChance methods). You could also create an enum for the different classes. Then, your ClassSelector could return a value from this enum, and pass it to the WeaponSelector, so it can make it's choice based on it.