Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.27 KB | None | 0 0
  1. class myPayclass {
  2. double [] payarray;
  3. double [] hrsarray;
  4. double [] totalarray;
  5. int index;
  6.  
  7. public static void main(String[] args){
  8. /* initialize variables that are available to outside methods */
  9. int i;
  10.  
  11. /*the following method is used to allow for loop to access the array length for count++*/
  12. myPayclass tm = new myPayclass();
  13.  
  14. for (i=0; i< tm.length(); i++)
  15. {
  16. /* myarray is not working. It should be diplaying the id of the persons pay rate and hrs */
  17. String hrs = JOptionPane.showInputDialog( null , i<myarray1.length[3] + "?","Enter the employee's hours");
  18. String payrate = JOptionPane.showInputDialog("Enter the employee payrate");
  19.  
  20. /* must be changed into double from string for math calculations */
  21. double hrsnum = Double.parseDouble(hrs);
  22. double paynum = Double.parseDouble(payrate);
  23.  
  24. /* we are not sure yet exactly why thi is change or exactly what change()
  25. * is, or if it is anything else other than a method.*/
  26. tm.change(hrsnum,paynum);
  27.  
  28.  
  29. /* totalarray shoulf be displaying all the values in the array after 8 entries.*/
  30. JOptionPane.showMessageDialog(null, tm.totalarray[i], "Printing results",JOptionPane.INFORMATION_MESSAGE);
  31.  
  32.  
  33. }
  34. }
  35.  
  36. /* other half of for loop access to array length */
  37. public int length(){
  38. return payarray.length;
  39. }
  40.  
  41. /* this is a debug attempt. myarray1 is still conficting as int */
  42. public int myarray1(){
  43. return int myarray1[] = {88761, 89865, 22457, 77541, 7777, 8888, 99999, 7892};
  44. }
  45.  
  46. public int length2(){
  47. return totalarray.length;
  48. }
  49.  
  50. /* initialize arrays and perform math calc */
  51. public myPayclass(){
  52. payarray=new double[8];
  53. hrsarray=new double[8];
  54. totalarray=new double[8];
  55. index = 0;
  56. }
  57.  
  58. /*"My problem is here I am sure. total array should be storing each value but appears to not be*/
  59. public void change(double paynum,double hrsnum) {
  60. payarray[index] = paynum;
  61. hrsarray[index]= hrsnum;
  62. totalarray[index]=hrsnum * paynum;
  63. index++;
  64.  
  65. /* begin loop to display the inputed values in the array to the screen*/
  66. if (index == 8) {
  67. for(int counter=0;counter<totalarray.length;counter++){
  68. System.out.println(counter + "\t" + totalarray[counter]);
  69. }
  70. }
  71. }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement