Outputs random values to Java beginner for statement

Asked 2 years ago, Updated 2 years ago, 20 views

import java.util.Random; import java.util.Scanner;

public class random task { public static void main(String[] args) { Scanner Scanner = new Scanner (System.in); String input = scanner.next(); System.out.println ("Please enter a type"); System.out.println ("1. Terran 2. Protoss 3. Zerg"); // Allows you to enter three races. int Combat input = scanner.nextInt(2); int Marine attack power = 6; int juggling attack power = 10; int Gillette Attack Power = 16;

 If (battle input value == 1) { //Random value of Terran, 3 situations are given
        Random random = newRandom();
        int random value = random.nextInt(2);
    If (random value == 0) { //Terran's combat situation and results
        System.out.println ("Marine is threatened by a gang of jugglers."");
        int Support Request = Random.nextInt(80);
        System.out.println ("Tank Support Fire!" Total damage" + (Marine Attack Power * Support Request) +" damage to win.");
    } else if (random value == 1) {
        System.out.println ("Defeated by the overwhelming Gillette force of Protos").");
        int Use skill = random.nextInt(40);
        System.out.println ("Steam pack upgrade of Firebat and Marine units!!" + " + (using Marine attack * skills) + "As much attack has been upgraded and the battle has been advantageous");
    } else if (random value == 2) {
        int Allied counterattack = random.nextInt(100);
        System.out.println (Zerg and Protoss combined) + (Juggling attack + Juggling attack) * (Associated counterattack) + " was defeated.");
        If (input value.Equals (2) { // Given 3 random values of Zerg
        Random 1 = new Random();
        int random value 1 = random 1.nextInt (2);
        If (random value 1 == 0) { // Zerg combat situation and results
            System.out.println ("Juggling is fighting Marine with a steam pack."");
            int Upgrade = random1.nextInt(40);
            System.out.println ("Juggling's adrenaline upgrade!!" + (Juggling's attack * upgrade) + "The attack was increased and won.");
        } else if (random value 1 == 1) {
            System.out.println ("Protos' Akan unit invaded).");
            int Guardian support = random1.nextInt(20);
            System.out.println ("The Guardian's support has come" + " + (Marine Attack Power * Guardian's support) + "The Arkansas Army has retreated");
        } else if (random value 1 == 2) {
            int Allied Attacks = Random 1.nextInt (50);
            System.out.println ("Terran and Protoss combined" + (Marine Attack + Jericht Attack)* (Associated Attack) + " was defeated by damage.");
            If (input value.Equals(3){ //Giving 3 random values of protocol
            Random 2 = new Random();
            int random value 2 = random 2.nextInt (2);
            If (random value 2 == 0) { // Protos combat situation and results
                System.out.println ("Jerget is fighting juggling with adrenaline."");
                int Templer's support = random2.nextInt(60);
                System.out.println ("Dark Templar and High Templar Support is here!!)" + (Jirut attack power * Templar's support) + "Battle power increased and won.");
            } else if (random value 2 == 1) {
                System.out.println ("Terran's Vulture Force" began attacking the workers' units.");
                int Dragoon out = random 2.nextInt(70);
                System.out.println ("Just in time, the dragoons were produced" + " + (jirut attack force * dragoons) + ", causing damage and destroying a number of beehives, causing Vulture to retreat";
            } else if (random value 2 == 2) {
                int Allied attack = random 2.nextInt (120);
                System.out.println ("Zerg and Terran combined" + (Marine Attack + Juggling Attack)* (Associated Attack) + " was defeated.");
            }
    }
        }
    }
    }
    }
}

}

If I choose three species and enter the species, I would like to randomly call the values of each situation for each species.

java

2022-09-20 22:01

1 Answers

I'm also working hard to answer because you seem to be coding in a fun way.

The biggest problem seems to be the wrong nested structure of the if statement. The situation of Terran, Protoss, Zerg is independent of each other, and we have a strange if-moon structure under which the situation of the Terran is underneath the situation of Protoss. Due to the structure, there is no scenario other than the Terran.

The variable "input" appears to be the only input the user will receive. However, we commented on the variable "battle input value", which was not used. And the "input value" does not need to be a String, so I changed it to int.

Due to the structure, Random random = new Random(); and int random values are variables that can be declared only once, so things such as Random 1 and Random 2 are deleted.

Lastly, when you first guide the user, 1. Terran 2. Protoss 3. Zerg It is being guided, but in the if statement, the order is changed like 1. Terran 2. Jug 3. Protoss, so I modified it based on the order that was guided to the user.

When you copy and paste a code containing the Java main function into the HashCode, the Syntax is all broken. Here's a link to PasteBin. If you look at it from here, it comes out well. https://pastebin.com/TA2qx8up

For your information, the reason why the line change looks weird is because of my intellij code formatter, so you can modify it to suit your taste.


2022-09-20 22:01

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.