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