- #1
wyosteve
- 23
- 0
Without adding new Fields, how do I use local variables from another method in the same class? I know I could simply add these variables to the list of Fields and get to them that way but our instructor specifically told us NOT to do this. I am stumped. Heres the realavent code, in bold are the local variables I want to use again.
public static void main(String[] args)
{
String userName; // the name of the person using this program
String password; // user's password
String input; // temporary String for holding returned values from input dialog boxes
boolean done = false; // false until the employee is done entering products sold
String itemName; // the name of the item sold
String itemID; // product ID # for the item sold
double price; // price for the item
int quantity; // quantity sold
ArrayList<Item> items = new ArrayList<Item>();// holds all items sold by this employee today
code
/**
* Prints out the sales report in an organized format.
*/
public void printReport()
{
int totalPrice = 0;
for(Item item: items)
{
totalPrice = item.getPrice();
}
}
/**
* Verify a user account and password.
*/
public void verifyUser()
{
for(String name: EMPLOYEE)
{
for(String pswd: EMPLOYEE_PSWD)
{
if((userName.equals(name)) && (password.equals(pswd)))
{
do this }
}
}
}
}
Any clue would be appriciated! Oh and first post!
public static void main(String[] args)
{
String userName; // the name of the person using this program
String password; // user's password
String input; // temporary String for holding returned values from input dialog boxes
boolean done = false; // false until the employee is done entering products sold
String itemName; // the name of the item sold
String itemID; // product ID # for the item sold
double price; // price for the item
int quantity; // quantity sold
ArrayList<Item> items = new ArrayList<Item>();// holds all items sold by this employee today
code
/**
* Prints out the sales report in an organized format.
*/
public void printReport()
{
int totalPrice = 0;
for(Item item: items)
{
totalPrice = item.getPrice();
}
}
/**
* Verify a user account and password.
*/
public void verifyUser()
{
for(String name: EMPLOYEE)
{
for(String pswd: EMPLOYEE_PSWD)
{
if((userName.equals(name)) && (password.equals(pswd)))
{
do this }
}
}
}
}
Any clue would be appriciated! Oh and first post!