生成统计信息但得到错误的结果

时间:2018-11-05 02:38:57

标签: java

我正试图编写一个程序,让您拥有枪支。是的,非常暴力。无论如何,我必须生成每个统计信息。但是,我有一个问题。这是我的生成器类:

package generators;

import java.util.Random;

public class Gen {


Random num = new Random();
String tierName;
int nameOfGun;
int id, tier, damage, capacity, accuracy, recoil, firerate, reloadtime;
int maxID = 10;
int maxTier = 25;
int maxDamage = 100;
int maxAmmoCapacity = 100;
int maxAccuracy = 100;
int maxRecoil = 50;
int maxFireRate = 60;
int maxReloadTime = 60;

public String generateCaller(String gunName) {
    nameOfGun = num.nextInt(11);

    if(nameOfGun <= 5)
        gunName = "M14";
    if(nameOfGun <= 7)
        gunName = "AK-47";
    if(nameOfGun > 7)
        gunName = "SCAR";

    return gunName;
}

public int generateGunID(int a) {
    id = num.nextInt(maxID + 1);
    a = id;
    return a;
}

public String generateTier(String a) {
    tier = num.nextInt(maxTier + 1);

    if(tier <= 10)
        tierName = "Common";
    if(tier <= 16)
        tierName = "Uncommon";
    if(tier <= 20)
        tierName = "Rare";
    if(tier <= 22)
        tierName = "Ultra Rare";
    if(tier <= 24)
        tier = num.nextInt(maxTier + 1);
            if(tier == 24)
                tierName = "Legendary";
    if(tier == 25)
        tier = num.nextInt(maxTier + 1);
            if(tier == 25)
        tierName = "Mythical";

    a = tierName;   
    return a;
}

public int generateDamage(int a) {
    damage = num.nextInt(maxDamage + 1);
    a = damage;
    return a;
}

public int generateCapacity(int a) {
    capacity = num.nextInt(maxAmmoCapacity + 1);
    a = capacity;
    return a;
}

public int generateAccuracy(int a) {
    accuracy = num.nextInt(maxAccuracy + 1);
    a = accuracy;
    return a;
}

public int generateRecoil(int a) {
    recoil = num.nextInt(maxRecoil + 1);
    a = recoil;
    return a;
}

public int generateFireRate(int a) {
    firerate = num.nextInt(maxFireRate +1);
    a = firerate;
    return a;
}

public int generateReloadTime(int a) {
    reloadtime = num.nextInt(maxReloadTime + 1);
    a = reloadtime;
    return a;
}

}

这是我的主要课程:

package main;

import java.util.concurrent.TimeUnit;
import generators.*;
import weapons.*;

public class Main {

public static void main(String args[]) {
    Gen mainuse = new Gen();
    int a = 0, b = 0, c = 0, d = 0, e = 0, f = 0;
    String x = "", y = "";

    System.out.println("Generating guns");

    try {
        TimeUnit.SECONDS.sleep(3);
    } catch (InterruptedException error) {
        error.printStackTrace();
    }


    for(a = 0; a < 5; a++) {

        mainuse.generateGunID(a);
        mainuse.generateDamage(b);
        mainuse.generateCapacity(c);
        mainuse.generateRecoil(d);
        mainuse.generateReloadTime(e);
        mainuse.generateAccuracy(f);
        mainuse.generateTier(x);
        mainuse.generateCaller(y);

        ConstructGuns cg = new ConstructGuns(a, b, c, d, e, f, x, y) ;

        System.out.println("The gun's ID is " + a);
        System.out.println("The gun's damage is "  + b);
        System.out.println("The gun's capacity is " + c);
        System.out.println("The gun's recoil is " + d);
        System.out.println("The gun's reload time is " + e);
        System.out.println("The gun's accuracy is " + f);
        System.out.println("The gun's tier is " + x);
        System.out.println("The gun's name is " + y);
    }
}

}

这是我的枪支课程的构造函数:

package weapons;

public class ConstructGuns {
int id, damage, capacity, recoil, reload, accuracy;
String tier, name;

public ConstructGuns(int id, int damage, int capacity, int recoil, 
int reload, int accuracy, 
String tier, String name){

    this.id = id;
    this.damage = damage;
    this.capacity = capacity;
    this.recoil = recoil;
    this.reload = reload;
    this.accuracy = accuracy;
    this.tier = tier;
    this.name = name;
}

}

从此代码中,我没有得到想要得到的东西。我希望每把枪都是随机产生的并且各不相同。相反,我得到这个:

 Generating guns
The gun's ID is 0
The gun's damage is 0
The gun's capacity is 0
The gun's recoil is 0
The gun's reload time is 0
The gun's accuracy is 0
The gun's tier is 
The gun's name is 
The gun's ID is 1
The gun's damage is 0
The gun's capacity is 0
The gun's recoil is 0
The gun's reload time is 0
The gun's accuracy is 0
The gun's tier is 
The gun's name is 
The gun's ID is 2
The gun's damage is 0
The gun's capacity is 0
The gun's recoil is 0
The gun's reload time is 0
The gun's accuracy is 0
The gun's tier is 
The gun's name is 
The gun's ID is 3
The gun's damage is 0
The gun's capacity is 0
The gun's recoil is 0
The gun's reload time is 0
The gun's accuracy is 0
The gun's tier is 
The gun's name is 
The gun's ID is 4
The gun's damage is 0
The gun's capacity is 0
The gun's recoil is 0
The gun's reload time is 0
The gun's accuracy is 0
The gun's tier is 
The gun's name is 

我很高兴我没有收到代码错误,但结果不正确。谁可以帮我这个事? *我使用Eclipse,并且是初学者。 :)

0 个答案:

没有答案