Reputation: 31
I'm a beginner when it comes to java. I'm doing a computer course which has some programming in it. I'm currently doing an assignment which has me working with loops and arrays etc.
One part of the assignment is to output employees gross pay. I am just wondering how do I get this value to be stored as a variable This is the code I have:
for(int position=0; position <hours.length;position=position+1) {
System.out.println("Gross Pay for " +employees[position]+("= ")+hours[position]*Wage[position]);}
I want to know the code I need to use to assigngrosspay
to a variable because I then have to calculate the tax at 25% which I am also unsure of how to do but if you could help me with the first part that would be brilliant. I have tried a few things but I just can't figure it out.
I have wages and hours in arrays yes I may as well just show the code I currently have. import java.util.Scanner; public class Assignment2 {
public static void main(String[] args) {
//declare array called employees to store the workers names
String employees[]= {"Samuel Patrick","Thomas Hogans","Murray Murphy","Michael Honnan","Anthony Brosnan","Pauline Clancy","Susan Slattery",};
//declare an array called Wage using the double data type to store the employees hourly wage
double Wage[]= {9.25,8.75,8.65,9.45,8.25,9.50,8.75};
//declare an array called hours which will be used to enter employees hours worked
int hours[] = new int[7];
//set up the scanner to allow employees hours worked to be entered
Scanner in = new Scanner(System.in);
//Instruct the user to enter the amount of hours worked
System.out.println("Enter hours worked");
for(int position=0; position <hours.length;position=position+1) {
System.out.print("Employee "+employees[position]);
hours[position] = in.nextInt();
}
for(int position=0; position <hours.length;position=position+1) {
System.out.println("Gross Pay for " +employees[position]+("= ")+hours[position]*Wage[position]);}
{
for(int position=0; position <hours.length;position=position+1);
System.out.print("Total Tax owed for "+employees[position]
}
}
I have tried entering it like this
double GrossPay = (employees[position]+hours[position]*Wage[position]);
but that keeps coming up with errors what would be the correct way of doing this?
I know this may not be the most effient way of doing things but the teacher wants it done like this.
Upvotes: 0
Views: 226