0

Java: How do I print an array from another class? My array contains another array from that class

Okay so this is my code i know its messy and full of other errors, i I am still trying to learn. I know i could do it in one class but that takes away from the OOP portion of java. I figure if I am going to learn i may as well learn right. I have been trying to figure out how to print out that charHpArray for two days and everything i found on google has been useless because they dont contain another array . Essentially I am trying to make it so level works as the parameter, so when level = 1 hp is 5, and when level is 2 hp is 10 and so on. Also if you could tell me why level + # isnt working that would be great. //if you want to take a crack at that too, I am trying to make mage, arch, and war, all have different starting bonuses so war would have a little more health than the basic level bonus. ** ALL ANSWERS ARE ENCOURAGED, EVEN IF IT MEANS NEW IDEAS IM JUST TRYING TO LEARN** Thanks package rpg; import java.io.*; import java.util.Scanner; import java.util.Random; public class Main { public static void main(String[]args) { Scanner input = new Scanner(System.in); Random roll = new Random(); System.out.println("Welcome To Adventure Heroes"); System.out.println("-------------------"); System.out.println("You awake to the sound of screaming, \"GET AWAY FROM ME!\""); System.out.println("You call out to the voice in the distance..."); System.out.println("There is no answer"); System.out.println("You run towards the troubled screams in the distance"); System.out.println("You see a man on the floor being kicked, without hesitation you charge in and push the attacker off the man."); System.out.println("You examine the man to see if he is okay. When you look up the attacker is gone."); System.out.println("\"Thank you so much... erm, come to think of it I've never seen you around these parts. What is Your name?\""); String yourName = input.next(); System.out.println("\"What a weird name, Hi " + yourName + ", I'm Borgan\""); System.out.print("\"Well " + yourName + ", your

5th Oct 2018, 12:09 AM
Dylan Cunha
Dylan Cunha - avatar
2 Réponses
0
You can use a loop for (Object object: ObjectList) { System.out.println() } The shared code is incomplete, try to send the whole I will try to help you
5th Oct 2018, 4:30 AM
Daniel (kabura)
Daniel (kabura) - avatar
0
System.out.print("\"Well " + yourName + ", your journey begins here.\""); Character.getcharHp() ; public class Character { int[] level ={1,2,3,4,5,6,7,8,9,10}; int[] charHpArray = {5,10,15,20,25,30,35,40,45,50}; Character(int[] charHp) { charHp = charHpArray; } public int[] getCharHp() { return charHpArray; } int xp; int def; int meleeDmg; int magicDmg; function increment(array) int mage[] = { charHpArray[level], def = level + 2, meleeDmg = level + 1, magicDmg = level + 6 }; int archer[] = {charHp[level] = level + 4, def = level + 3, meleeDmg= level + 4, magicDmg = level + 1}; int[] warrior = {getcharHp()[level] = level + 5, def = level + 4, meleeDmg = level + 3, magicDmg = level + 0}; int player[][] = {mage, archer, warrior}; }
5th Oct 2018, 10:44 PM
Dylan Cunha
Dylan Cunha - avatar