My problem is just that. I have tried to declare the string as a specific shape, I sort and do everything, but the only thing that works is putting the string in the main method in the main method that I use I am This is disappointing, because I have tried all those things which I can think of. When I import them from another class, then why do the elements become zero? I added a main method for the trick class and also moved it there to do it, but there is no benefit. Here's the first program:
import java.util.Arrays; Public square tricks square {public string [] getMoves () {return moves; } String [] moves; Public stable string [] useMove (string [] moves) {moves [0] = "punch"; Moves [1] = "kick"; Moves [2] = "rescue"; Moves [3] = "run"; Moves [4] = "inventory"; Moves [5] = "Rickel"; Moves [6] = "heal"; Arrays.sort (move); Return moves; }} And body of the main one: import java.io. *; Import java.util. *; Public class practice button {public static zero main (string [] args) {scanner scan = new scanner (System.in); Random rand = new random (); Inventory class volume = new inventory class (); MovesClass mov = new moves (); String [] moves = mov.getMoves (); Intel HP = 0; Int playerHp = 200; String input = "default"; Int loss = 0; Int hitDif = 50; // default in kick Chance1 = 0; // Default - hits. Chicks in Kick Chance = Kick China 1 - Hit DIF; // chance chance hit hit = 1; Int Hit Chance = Hitchance 1 - Hit DIF; Int runDif = 50; // default en run chance1 = 0; // Default - goes to the run; Runs in Chinat Run China = Runs scored 1 - Run DIF; // The chance to run the enemy MinAttack = 0; Int enemyAttack = 0; Int index = 0; Int [] levelArray = {1, 2, 3}; String [] monsterArray = {"GNOLL", "troll", "dragon"}; String monster = monster [rand. Newest (monster lumber)]; Int level = rand.nextInt (levelArray.length) + 1; If (level == 1) {System.out.println ("Your opponent is a child" + monster + "!"); } Else {System.out.println ("Your opponent is a level" + Level + "+ Monsters +"!); } If (level == 1) {hp = rand.nextInt (20) + 41; EnemyAttack = rand.nextInt (5) + 1; } And if (level == 2) {hp = rand.nextInt (20) + 91; EnemyAttack = rand.nextInt (6) + 5; } And if (level == 3) {hp = rand.nextInt (20) + 141; Enemies: Shock = Rand XXInt (7) +10; } Enemy MnAttack = rand.nextInt (enemy goods) + 1; System.out.println ("Your opponent is HP:" + HP + "\ n"); Int permEnemyAttack = enemyAttack; Int permEnemyMinAttack = enemyMinAttack; Ext: While (HP> 0) {enemyAttack = permEnemyAttack; Enemy MINAttack = permEnemyMinAttack; Do {if (playerHp == 0) {System.out.println ("You are dead! Finish the game! \ N \ n \ n"); Break exhaust; } Else {System.out.println ("Choose an action: \ nkick \ npoint \ ntank \ ndefend \ n"); Input = scan.nextLine (); Index = Arrays.binarySearch (moves, input); Println (index); If (index
You never move move inside the movesClass . It is empty, the default value for reference fields is if you want to intialize it, then you have to: string [] moves = new string [7]; But if you do this, elements of the array will still be null and you have to put the actual strings in the array. It seems that your is useless () is designed for this, but it is never called. The method is weird anyway. You have an array in the form of logic that you fill with the trick and then sort it, but then you return the same array, you have already received it as a parameter. The Java does not copy the array when you pass them from one method to another or return them to some method, then you can modify the array obtained as a parameter. If you always want to initialize the moves field with the same trick, it would be better to do this in the class manufacturer. There is no access in the field of class examples of a static method.
Comments
Post a Comment