need some help in looping
Hi .. I am new here , so i realy need some help in addaing a loop into this
final double B1= .15;
final double B2 = .10;
final double B3 = .06;
final double B4 = 0.00;
switch(employeeRating)
{
case 1: employeeBonus = (employeeSalary * B1);
break;
case 2: employeeBonus = (employeeSalary * B2);
break;
case 3: employeeBonus = (employeeSalary * B3);
break;
}
Re: need some help in looping
This is no valid java class... before you implement a loop make it a class and use the forum code tags to make your code readable.
Describe what you already did, what you actual problem is and what proposal you have to solve it.
Re: need some help in looping
i didnt get it realy :(think):
so this is the whole program , i wanted to add an aray and a loop but i didnt know how !
could you tell me what to do, please ?
import javax.swing.JOptionPane;
public class Array {
public double employeeBonus;
static String[] info ={"employeeName","salary","rating"};
public static void main(String[] args) {
String employeeName, salaryString, ratingString;
double employeeSalary;
double employeeBonus = 0;
int employeeRating;
final double B1= .20;
final double B2 = .15;
final double B3 = .10;
final double B4 = 0.00;
final int RATING1 = 1;
final int RATING2 = 2;
final int RATING3 = 3;
// This is the work done in the housekeeping() method
// Get user input.
employeeName = JOptionPane.showInputDialog("Enter employee's name: ");
salaryString = JOptionPane.showInputDialog("Enter employee's yearly salary: ");
ratingString = JOptionPane.showInputDialog("Enter employee's performance rating: ");
// Convert Strings to int or double.
employeeSalary = Double.parseDouble(salaryString);
employeeRating = Integer.parseInt(ratingString);
switch(employeeRating)
{
case 1: employeeBonus = (employeeSalary * B1);
break;
case 2: employeeBonus = (employeeSalary * B2);
break;
case 3: employeeBonus = (employeeSalary * B3);
break;
}
// This is the work done in the endOfJob() method
// Output.
System.out.println("Employee Name " + employeeName);
System.out.println("Employee Salary $" + employeeSalary);
System.out.println("Employee Rating " + employeeRating);
System.out.println("Employee Bonus $" + employeeBonus);
System.exit(0);
Re: need some help in looping
You may do loop in different ways it depends on what you are trying to archieve, right?
A loop is a very basic thing, I suggest you read one of the tutorials on that matter, there are two basic types of loops:
- for (...) { ... }
- while(...) { ... }
And as I said - as long as you do not say what you want to do we cannot help you. As I also said, use the forum code tags to make your code readable!
EDIT: I guess you want to read in multiple employees, is that correct?
Re: need some help in looping
ok, i just need to ask you a couple questions , if you dont mind :)
Q1 : i want to calculate the imployee bonus , can i add a loop in it ?
Q2 : i want to add an array , is my array correct or not ?
static String[] info ={"employeeName","salary","rating"};
Re: need some help in looping