JAVA using assigned values from an array in a calculation -


this basic question have started out java , have hit bit of bump regards arrays.

what trying populate array 6 pieces of information user:

  • number of employees input,
  • an alphanumeric employee number,
  • a first name,
  • a last name,
  • the number of hours have worked,
  • a number input corresponding pay scale.

so far have gotten these inputs array in java wanted use corresponding number input select constant within pay scale array , use constant calculate wages of each employee.

for instance employee 1 worked 10 hours @ scale 0 10*4.50 , employee worked 10 hours @ scale 1 10*4.62

import java.util.arrays; //imports array utility import java.util.scanner; //imports scanner utility  public class test1 {      static scanner keyb = new scanner(system.in);   //adds keyboard input       public static void main(string[] args) {          scanner scanner = new scanner(system.in);         system.out.println("enter number of employees: ");         int employees = scanner.nextint();         string[] employee = new string[employees];         string[] firstname = new string[employees];         string[] lastname = new string[employees];         double[] hoursworked = new double[employees];         double[] payscale = {4.50,4.62,4.90,5.45,6.20};           (int = 0; < employee.length; i++) {             system.out.print("enter employee number: ");             employee[i] = scanner.next();             system.out.print("enter employee's first name: ");             firstname[i] = scanner.next();             system.out.print("enter employee's last name: ");             lastname[i] = scanner.next();             system.out.print("enter employee's hours worked: ");             hoursworked[i] = scanner.nextdouble();             system.out.print("enter employee's payscale (number 0 4): ");             payscale[i] = scanner.nextdouble();         }           (int = 0; < hoursworked.length; i++) {                 system.out.println("employee " + employee[i] + " " + firstname[i] + " " + lastname[i] + " has "                         + hoursworked[i] * payscale[0]);              }         }     } } 

am close solution on this?

is i'm asking possible in java?

maybe i'm looking @ wrong way, regarding appreciated.

edit

ok added extras array code scanner scanner = new scanner(system.in); system.out.println("enter number of employees: "); int employees = scanner.nextint(); string[] employee = new string[employees]; string[] firstname = new string[employees]; string[] lastname = new string[employees]; double[] hoursworked = new double[employees]; int[]payscale2 = {0,1,2,3,4}; double[] payscale = {4.50,4.62,4.90,5.45,6.20};

i'm unsure i'd index original payscale array

payscale[payscale2[i]]

would go statement codeblock? (i have tried putting in there error it's not statement :/

change

+ hoursworked[i] * payscale[0]); 

to

+ hoursworked[i] * payscale[i]); 

apart seems me you're doing you're saying should doing..

you have payscales here: double[] payscale = {4.50,4.62,4.90,5.45,6.20}; following doesn't make lot of sense:

system.out.print("enter employee's payscale (number 0 4): ");             payscale[i] = scanner.nextdouble(); 

first of all, if want keep number (number 0 4) separately, should use another array, not 1 keep payscales, index first array keeps different rates.. or else directly use first array if know pay scale every employee.. in end has want , how want it, logic , tools there. if call 2nd array payscale2 example:

 system.out.print("enter employee's payscale (number 0 4): ");             payscale2[i] = scanner.nextdouble(); 

then can index first array example:

payscale[payscale2[i]]  

in case if user inputs 0 payscale2[i] 0 payscale[payscale2[i]] payscale[0] or 4.5 or whatever set value equal @ first array


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -