example:
public class chapterfour {
int x;
int y;
int z;
int a;
int b;
public void passer() {
chapterfour add = new chapterfour();
chapterfour square = new chapterfour();
//send to additup
x = 2;
y = 5;
add.AddItUp(x,y);
//send to squareit
a = 3;
square.SquareIt(a);
}
public void AddItUp(int x, int y) {
//z is the total
z = x + y;
System.out.println("5 and 2 added up is " + z);
}
public void SquareIt(int a) {
//b is the total
b = a * a;
System.out.println("3 squared is " + b);
}
}
public class chapterfourTestDrive {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
chapterfour add = new chapterfour();
chapterfour square = new chapterfour();
//adds
add.AddItUp(2,5);//<--see i know the value of them.
//squares
square.SquareIt(3);
}
}
what i want to do is pass the value of and int that i dont know the value of. look here is my code any help would be great. everything is in there own class cause i really like OO coding
GET USER INPUT CLASS
import java.io.*;
public class input {
public String getUserInput(String prompt) {
String inputLine = null;
System.out.print(prompt + " ");
try {
BufferedReader is = new BufferedReader(
new InputStreamReader(System.in));
inputLine = is.readLine();
if (inputLine.length() == 0 ) return null;
} catch (IOException e) {
System.out.println("IOException: " + e);
}
return inputLine.toLowerCase();
}
}
SET IT UP CLASS
public class start {
input get = new input();
String userInput;
public void setup() {
userInput = get.getUserInput("Ask the 8ball anything:");
}
}
GET THE ANSWERS CLASS
public class answers {
int a;
int a2;
public void getAnswers() {
String an1 = "i dont know";
String an2 = "chuck norris";
String[] answers = {an1, an2};
int lenghtanswers = answers.length;
int rand1 = (int) (Math.random() * lenghtanswers);
String answer = answers[rand1];
if (answer == an1) {
System.out.println(answer);
a++;
}else {
System.out.println(answer);
a2++;
}
}
}
AND MAIN
public class testdrive {
public static void main(String[] args) {
// TODO Auto-generated method stub
int x = 0;
while (x < 200) {
start go = new start();
go.setup();
answers run = new answers();
run.getAnswers();
x++;}
System.out.println(You asked me + x + " questions. And i answered
+ a + of them I dont know. And I answered + a2 + of them chuck norris. Why are you asking me.
}
}
you see i add to a and a2 ONLY if that answer was put out. so i dont know the value of them. and to get that little funny joke and the end i need the value of a and a2. How do i pass the value of a and a2 with out knowing what they are is the exsact question im asking.
EDIT: oh and i know that it can tell if its an1 or an2 cause i once putout ANSWER 1 if it was an1 and ANSWER 2 if it was an2 and it worked.

New Topic/Question
Reply




MultiQuote




|