So I have some code here, and I want to change the "reactionFactor" variable in "ReactionAgent" to private or protected and still be able to access it in the next class "Augmentium"
when i cahnge it to private it tells me that i cant access it because It is private.. I dont want the rectionFactor variable to be changed in the "ReactionAgent" class, only in the instance in the "Augmentium" class.
I panic so much when I cant get these things done. Im new to java and im wondering if i should just switch to another major or dropout ....I appreciate all help
Here are the two classes:
package ReactionAgent; public class ReactionAgent { public int reactionFactor; //I want this to be private public ReactionAgent() { reactionFactor = 1; } public void setFactor (int Factor) { reactionFactor = Factor; } public int getFactor() { return reactionFactor; } }
import ReactionAgent.ReactionAgent; import java.util.Random; // import this library public class Augmentium { private int val; private int max; private int nextInt; public void Augmentium() { val = 1; max = 4; nextInt = 1; } ReactionAgent Augmentium = new ReactionAgent(); /*public int oreReaction(int Ore) { Ore = reactionFactor + Ore; return Ore; }*/ Random randNum = new Random(); public int randNum() { max = 3; Augmentium.reactionFactor = randNum.nextInt(max) + 2; //gets a value between 2 and max(inclusive) return Augmentium.reactionFactor; } public static void main(String args[]) { Augmentium test = new Augmentium(); System.out.println(test.randNum()); }