Results 1 to 2 of 2
- 01-06-2010, 01:36 PM #1
Member
- Join Date
- Jan 2010
- Location
- Belfast
- Posts
- 1
- Rep Power
- 0
Switch Statement/Parameter Passing
Hi guys,
I am trying to use parameter passing to call a method within a switch statement. I can call the method however non of the arrays are displayed, its only displays the string at the end.
This is the code i am having the trouble with.
menuOption = 0;
do
{
optionValid =true;
//call display menu method
displayMenu();
//prompt for user input of menu option
System.out.println(".............................. .................");
System.out.println("Please type in a menu option");
System.out.println(".............................. .................");
menuOption=InOut.readInt();
//while statement to validate if menu option is within range
while ((menuOption < 0) || (menuOption > 5))
System.out.println(".............................. .................");
System.out.println("Invalid value. This should in between 1 and 5");
System.out.println(".............................. .................");
//call display menu method
displayMenu();
//Prompt user for input of menu option
menuOption=InOut.readInt();
//end of while loop
//start of switch statement
switch (menuOption)
{
case 1:displayEmployees(spRefNo,spName, spMonthlySales, spGrossPay, spDeductions, spNetPay,0,20000,"All Employee Details");
break;
case 2: displayEmployees(spRefNo, spName, spMonthlySales, spGrossPay,spDeductions, spNetPay, 10000, 20000,"Employees whose monthly sales are £10000 or above");
break;
case 3: averageSales = averageResult(spMonthlySales, NUMBEROFEMPLOYEES);
displayEmployees(spRefNo, spName, spMonthlySales, spGrossPay, spDeductions, spNetPay, 0, averageSales,"Employees whose monthly sales are below the average");
break;
case 4: for (index = 0; index <= NUMBEROFEMPLOYEES -1; index++)
{
if (spMonthlySales[index]==highestSales)
{
spNetPay[index]=spNetPay[index] + 500;
System.out.println(spRefNo[index] + "\t " + spName[index] + "\t " + spMonthlySales[index] + "\t\t " + spGrossPay[index] + "\t " + spDeductions + "\t " + spNetPay[index]);
}//end of if statement to find employee with highest sales
}
break;//End of for loop
case 5:optionValid=false;
}//End of menu switch statement
}while(menuOption<=4);//end of while statement
}//End of main method
This is the method i am trying to call.
static void displayEmployees (int spRefNo[] ,String spName[],double spMonthlySales[],double spGrossPay[],double spDeductions[],double spNetPay[],int lowValue,double highValue,String message)
{
int index;
int NUMBEROFEMPLOYEES = 0;
System.out.println("" + message + "");
for (index = 0; index <= NUMBEROFEMPLOYEES -1; index =index + 1)
{
if ((spMonthlySales[index] >= lowValue) && ( spMonthlySales[index] < highValue))
{
System.out.println(spRefNo[index] + "\t " + spName[index] + "\t " +spMonthlySales[index] + "\t " + spGrossPay[index] + spDeductions + "\t " + spNetPay[index]);
}//End of if construct
}//End for for loop
}//End of display employees menthod
If you could help it would be fantastics. thanks
- 01-06-2010, 01:50 PM #2
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
Put System.out.println statements to see where your code is going and what are the values of certain variables.
Also given that NUMBEROFEMPLOYEES start at 0 what do you think is happening to the for loop?
More importantly, start the exercise again using object oriented principles instead.
Create an Employee class that has appropriate properties to model the data you are dealing with. Those arrays are older than oldskool.
Similar Threads
-
passing parameter to a thread
By adammyth in forum Threads and SynchronizationReplies: 1Last Post: 01-02-2010, 07:58 PM -
passing a parameter
By aarthi2learn in forum AWT / SwingReplies: 4Last Post: 12-22-2008, 05:46 AM -
Passing short value as parameter
By javanewbie83 in forum New To JavaReplies: 16Last Post: 07-16-2008, 05:27 AM -
passing an enum type as a parameter ??!
By SCS17 in forum New To JavaReplies: 11Last Post: 07-13-2008, 01:44 PM -
Switch Statement Help
By bluegreen7hi in forum New To JavaReplies: 6Last Post: 02-06-2008, 05:16 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks