printing items from an array of a string onto a sketch

so i am trying to make a payroll program, right now i am getting caught up on getting the items of the array to print properly, i have my data files in my folder and they are being pulled properly but i cant get them to print on to the sketch, im not sure if im not using something properly or if im not declaring my variables properly but im getting caught up and could use a hand

in my data file for EmployeeID.txt it has 1,2,3,4 in it exactly like that

in my data file for EmployeeName.txt it has Alabaster Snowball,Bush Evergren, Pepper Minstix, Sugerplum Mary exactly like that

here is what i have so far

//Carmine
//
//Lab 5 Payroll Lab
//

PFont font;
String[] EmployeeID;
String[] EmployeeName;
final float MINIMUM_WAGE=9.84;
final float EMPLOYEE_1_HOURS=40;
final float EMPLOYEE_2_HOURS=25.5;
final float EMPLOYEE_3_HOURS=45;
final float EMPLOYEE_4_HOURS=42;

void setup() {
  size(800, 600);
  background(255);
  EmployeeID=loadStrings("EmployeeID.txt");
  EmployeeName=loadStrings("EmployeeName.txt");
  font= loadFont("ComicSansMS-48.vlw");
  textFont(font, 32);
  fill(0);
  text("Sam's Payroll", 250, 50);
}

void draw() {
  //print text from arrays onto sketch
  textSize(16);
  textAlign(LEFT);
  println(EmployeeID,50,50);
}

ive tried using printArray, print, println, ive tried changing stuff around but it doesnt seem to work and i have been looking on the reference for processing but cant find something to help yet so maybe someone can here.. Thanks again im probably making a really stupid error but it happens im still learning

Answers

  • edited May 2018

    Helpful example code follows:

    String[] EmployeeIDs;
    
    void setup() {
      size(800, 600);
      //EmployeeIDs = loadStrings("EmployeeID.txt");
      EmployeeIDs = fakeStrings("Don'tActuallyUseThis.wtf");
      println("The fourth ID is " + EmployeeIDs[3]);
    }
    
    void draw() {
      background(255);
      fill(0);
      text("Sam's Payroll", 250, 50);
      text(EmployeeIDs[0], 50, 50);
      for ( int i = 1; i < 3; i++) {
        text(EmployeeIDs[i], 50, 50+20*i);
      }
    }
    
    String [] fakeStrings(String filename) {
      filename = filename + filename; // Busywork.
      String [] returnValue = { "1234", "5678", "1357", "2468" };
      return( returnValue );
    }
    

    Study this and try applying what it demonstrates to your own code. Notice that, since I don't have your data files, I am spoofing the data with the included fakeStrings() function.

  • edited May 2018

    Look at text() in the reference

    https://www.processing.org/reference/

    This is Homework

    Please post the content of your data file and format it as code too

    In my opinion you have a data file with multiple columns (3) - or your classmates have - so I am unsure why you work with 2 files

    Anyway, loadStrings() (see reference) gives you an array so in draw() you want to for loop i over employeeID !!!

    And use text(EmployeeID[i], 44, i*44); inside for loop

    Read more of the reference in future

    https://www.processing.org/reference/for.html

  • @TFGuy44 i appreciate all your help but your example has me so confused mainly because i failed to include my data files properly most likely

    @Chrisir i am going to add them in this comment here and also what i currently have

    ok so i have been messing around and i got what i want to work but now have some further questions

    i am going to show what i currently have then ask my questions

    //Carmine
    //
    //Lab 5 Payroll Lab
    //
    
    PFont font;
    String[] IDs;
    String[] EmployeeName;
    final float MINIMUM_WAGE=9.84;
    final float EMPLOYEE_1_HOURS=40;
    final float EMPLOYEE_2_HOURS=25.5;
    final float EMPLOYEE_3_HOURS=45;
    final float EMPLOYEE_4_HOURS=42;
    
    void setup() {
      size(800, 600);
      background(255);
    
      font= loadFont("ComicSansMS-48.vlw");
      textFont(font, 32);
      fill(0);
      text("Sam's Payroll", 250, 50);
    }
    
    void draw() {
      //print text from arrays onto sketch
      String[] IDs=loadStrings("EmployeeID.txt");
      String[] Names=loadStrings("EmployeeName.txt");
      text(IDs, 10, 10, 80, 80);
      noLoop();
    }
    

    here are my data files

    EmployeeName.txt
    Alabaster Snowball,Bush Evergren, Pepper Minstix, Sugerplum Mary
    
    EmployeeID.txt
    1,2,3,4
    

    i used some examples from class and it got me to this point, my strings load in and show what is in them but now i have questions

    1. is the String[] equivalent to an array? i think it is because of the [] and how it is loading the items from the data files to be displayed but im not sure and what to clear it up looking more at the reference i am noticing that using the String[] is a array i think since i am declaring it that way and making the string the array with the brackets( i could be very wrong)

    2 . i am trying to use the text() command to display my data from String[] IDs and String[]Names but when i was trying i am getting an error saying that i cannot use string[] with it, i thought it would work since it shows on the reference that strign can be printed that way but i guess since its an array (i think) it cannot? since i do need to print my array items onto the actual sketch how could i go along to do this?

  • edited May 2018

    Your 2 data files and additional data

    as I said, instead of having 2 data files PLUS employee data inside the sketch (very bad programming style):

    final float EMPLOYEE_1_HOURS=40;
    final float EMPLOYEE_2_HOURS=25.5;
    final float EMPLOYEE_3_HOURS=45;
    final float EMPLOYEE_4_HOURS=42;
    

    you should have ONE file like a table:

    Employee ID, Employee Name,Hours Worked
    1,Alabaster Snowball,40
    2,Bushy Evergreen,25.5
    3,Pepper Minstix,45
    4,Sugarplum Mary,42
    

    this could be loaded as a table using the command loadTable and then Table etc. - see reference.

    Your questions

    1.

    String[] of course is an array. It's of type String. int[] is an array of type int. This means the type of the variable in the slots of the array is String / int.

    I already said that in my previous posts!!! Maybe read more slowly.

    Anyway, loadStrings() (see reference) gives you an array so in draw() you want to for loop i over employeeID !!!

    see also:

    https://www.processing.org/reference/loadStrings_.html

    quote:

    Reads the contents of a file and creates a String array of its individual lines.

    2.

    text(IDs, 10, 10, 80, 80); won't work on an array (IDs). text can't display an entire array. Instead you need to display each slot / String separately.

    Instead, for loop over IDs as I explained already above

    for(int i=0; i <= IDs.length; i++) {
    
         text(IDs[i], 10, 10, 80, 80);
    
    }
    

    Chrisir ;-)

  • @chrissir using that makes sense but this assignment requires us to "1. Read 4 numbers from a text file into an array 2. Read 4 names from a text file into an array 3. Display all items of the arrays in the original order" thats why i need to use arrays,

    if i recall correctly it was said in class an array can be multidimensional (probably not the correct term) but like in the array i would be able to store the employee ids, name, and hours all in one array if i do recall this correctly, i havent been able to find this anywhere yet looking more before i post my comment i found what i am looking for.. so could i use a 3-D array to store all my information? i was looking and actually found another post where you helped someone with one and it looks like i could also use it to work for me?

  • when you want to work with 2 files do me favour and make this :

    final float EMPLOYEE_1_HOURS=40;
    final float EMPLOYEE_2_HOURS=25.5;
    final float EMPLOYEE_3_HOURS=45;
    final float EMPLOYEE_4_HOURS=42;
    

    a 3rd file.

    it looks like i could also use it to work for me?

    to be honest with you, better just work with the 3 arrays and make it work.

    Let's do the 2d array later (3D array is something else entirely).

    Here comes a small explanation about 2D arrays anyway:

    When you have String[] IDs and String[] Names and float[] hoursEmployee these are 1D arrays (like a shopping list, one dimension) and they are parallel in that the data of one employee are distributed over the 3 arrays. So for one employee look into the same line number of all 3 shopping lists.

    Now, when you place the 3 shopping lists next to each other you'll see a grid like a game of chess board. each row is an employee, each column is one property (ID, name, hours). That there are 3 columns has nothing to do with 2D dimension. It's still a 2D array with 1000 columns. (The dimension thing means: 1D=shopping list, 2D=grid, 3D=cube, 4D=list of cubes...)

    So you don't need a 3D array but a 2D array.

    see here for 1D array :

    https://www.processing.org/tutorials/arrays/

    and for 2D

    https://www.processing.org/tutorials/2darray/

  • @chrissir probably is a good idea to work with easier stuff till i really understand what i am doing,

    now im trying to use that text statement as you show and im getting an ArrayOutOfBoundsException:1 error and im not sure since to me it looks like the for loop,

    two i dont follow what you mean by when you saying when im working with two files do me a favour and make this with my float variables... ohh i think i get it now; your saying make the hours into another file and make them an array as well and just work with the three arrays as you also say.. makes sense

  • ok so heres what i currently have after everything youve helped with so far, i believe this is the route you were saying would be best

    //Carmine
    //
    //Lab 5 Payroll Lab
    //
    
    PFont font;
    final float MINIMUM_WAGE=9.84;
    final float EMPLOYEE_1_HOURS=40;
    final float EMPLOYEE_2_HOURS=25.5;
    final float EMPLOYEE_3_HOURS=45;
    final float EMPLOYEE_4_HOURS=42;
    
    void setup() {
      size(800, 600);
      background(255);
    
      font= loadFont("ComicSansMS-48.vlw");
      textFont(font, 32);
      fill(0);
      text("Sam's Payroll", 250, 50);
    }
    
    void draw() {
      //print text from arrays onto sketch
      String[] IDs=loadStrings("EmployeeID.txt");
      String[] Names=loadStrings("EmployeeName.txt");
      String[] Hours=loadStrings("EmployeeHours.txt");
      //prints the employee ids from the array
      for (int i=0; i<= IDs.length; i++) {
        println(IDs[i]);
        //prints the hours from the hour array
        for (int h=0; h<=Hours.length; h++) {
          println(Hours[i]);
        }
        //print the names from the name array
        for (int n=0; n<=Names.length; n++) {
          println(Names[n]);
        }
        text(IDs[0],10,10,80,80);
      }
    }
    
    void calculatePay() {
      float TimeAndHalf= 1.5;
      float NormalPay=1;
    }
    

    i started the void calculatePay because i will be using a function to calculate the pay for all the items in the array

    as of now all items in the array do print out in the console, the hour array prints twice for some reason tho.. also i get the ArrayOutOfBoundsException:1 still so i cant seem to get the text statement to print on the sketch to work yet... (

    i appreciate you taking so much time to really explain all this stuff to me because now it makes a lot more sense @chrissir

  • i think i get it now; your saying make the hours into another file and make them an array as well and just work with the three arrays as you also say.. makes sense

    Yes.

    I'm getting an ArrayOutOfBoundsException:1 error and im not sure since to me it looks like the for loop,

    show your entire code; how can we find the error without seeing the code?!

  • @chrissir quite convenient that i posted it up right as you asked

  • I believe you have this data in the new file now?

    I want you to delete these lines then:

    final float EMPLOYEE_1_HOURS=40;
    final float EMPLOYEE_2_HOURS=25.5;
    final float EMPLOYEE_3_HOURS=45;
    final float EMPLOYEE_4_HOURS=42;
    

    Access too the hard drive is time expensive; hence move these lines from draw into setup

       IDs=loadStrings("EmployeeID.txt");
       Names=loadStrings("EmployeeName.txt");
       Hours=loadStrings("EmployeeHours.txt");
    

    You have to delete String[] in all three lines!!!

    This: text(IDs[0],10,10,80,80); better IDs[i] !!!!!!

    Your for loops are not ok. Since all arrays are parallel they have the same length.

    for (int i=0; i<= IDs.length; i++) {
    
        //prints the IDs and Names from the 2 arrays
    
        text(IDs[i],10,10,80,80);
        text(Names[i],10,10,80,80);
    
    }
    
  • this is very wrong:

    void calculatePay() {
      float TimeAndHalf= 1.5;
      float NormalPay=1;
    }
    

    first you need to pass the hours to it as a parameter

    void calculatePay( float hours ) {
    

    Second you need to return the result

    float calculatePay() {
      float result; 
      float TimeAndHalf= 1.5;
      float NormalPay=1;
      result = 300 * 2; // ?????
      return result; 
    }
    

    so you can call calculatePay in draw like

    text (calculatePay(Hours[i]), 300, i*60);

    Gotta go

    see you tomorrow

  • hit F5 here to see discussion

    Bye

  • ok i do have one more question so dropping the string[] gives a error that the variables do not exist?

    Thank you for all the help today!

  • You need to create your variables for them to exist, and you need to specify what their types are when you create them! If you remove String[] from the declaration of your variables, how is your sketch going to know what type of variable you want?

    For example, this defines a variable that is a String:

    String i_am_a_string = "This is what I store.";
    

    If you leave off the String part of that line:

    i_am_a_string = "This is what I store";
    

    It no longer looks like a declaration - instead it becomes an assignment! And it's an assignment to a variable that doesn't exist, because it hasn't been declared!

    The same is true with arrays.

    String[] i_am_many_strings;
    i_am_many_strings = loadStrings("from_some_file.txt");
    

    This has a declaration - that there is an array of strings - and then an assignment - it assigns values to those strings.

    If you leave the type out of the declaration, it's NOT a declaration!

  • I am sorry.

    In one of your previous versions you had

       String[] IDs;
       String[] EmployeeName;
    

    Before setup

    Hence it was declared globally

    Now you mustn’t repeat the String [] part because then you would declare a variable locally

  • @tfguy44 thank you for clearing that up @chrissir no issues

    now im still confused to why i cannot get thre text statement you were saying to use to work.. for any statement that tries to print the array it gets a ArrayOutOfBoundsException:1 error on every statement, the array's data still prints to the console though which confuses me.

    i will attach what i currently have, maybe someone else can see what im missing; why it wont print to the sketch and giving me errors still

    PFont font;
    final float MINIMUM_WAGE=9.84;
    String[] IDs;
    String[] Names;
    String[] Hours;
    
    void setup() {
      size(800, 600);
      background(255);
       IDs=loadStrings("EmployeeID.txt");
       Names=loadStrings("EmployeeName.txt");
       Hours=loadStrings("EmployeeHours.txt");
      font= loadFont("ComicSansMS-48.vlw");
      textFont(font, 32);
      fill(0);
      text("Sam's Payroll", 250, 50);
    }
    
    void draw() {
      //print text from arrays onto sketch
    
      //prints the employee ids, names, and hours worked from the array
      for (int i=0; i<= IDs.length; i++) {
        //println(IDs[i]);
          //println(Hours[i]);
          //println(Names[i]);
         text(IDs[i],10,10,80,80);
         text(Names[i],20,20,85,95);
        }
      }
    
  • Line 23 < instead of <=

  • You can improve the text command: multiply the y value with i so that you have a new line per employee

    X value is the column so that value you can choose freely

  • Also display Hours and the resulting payment

  • After line 16 try printArray(IDs);

    Does the loading work? Or do you get any error message?

  • edited May 2018

    my data file for EmployeeID.txt it has 1,2,3,4 in it exactly like that

    No, that won’t work. Instead replace comma with return

    The numbers must be under each other, one number per line

    Same for names and hours!!!

    loadStrings works in a way that it puts each line of the file in one slot of the array IDs etc.

  • @chrissir you are the best. really thank you for all the help with this!

  • i do have another question now, it displays the array from the second position of the array not the first

  •   //prints the employee ids, names, and hours worked from the array
      for (int i=0; i< IDs.length; i++) {
        println(IDs[i]);
        println(Hours[i]);
        println(Names[i]);
        textFont(font,16);
        text(IDs[i], 100, 150*i,250, 150*i);
        text(Names[i], 125, 150*i, 200, 50*i);
      }
    }
    
  • Add 60 to the y value for the text()

  • Make sure first line of the files aren’t empty ;-)

  • 60 is an example number and represents the distance from the upper screen border

  • @chrissir i try changing the values and it still skips right to the second value all files are formatted to the top with no line above em

  • Does it skip the first also with println - or only with text() ?

  • Please post your entire code again and the content of data files

    Also try text without the last 2 parameters

    After line 16 try printArray(IDs);

    What does that give you?

  • edited May 2018

    @chrissir without the last two parameters it still prints the array skipping the first one, when i use the printArray statement it shows all items that are in my data file

    here is my current code

     PFont font;
            final float MINIMUM_WAGE=9.84;
            String[] IDs;
            String[] Names;
            String[] Hours;
    
            void setup() {
              size(800, 600);
              background(255);
              IDs=loadStrings("EmployeeID.txt");
              Names=loadStrings("EmployeeName.txt");
              Hours=loadStrings("EmployeeHours.txt");
              font= loadFont("ComicSansMS-48.vlw");
              textFont(font, 32);
              fill(0);
              text("Sam's Payroll", 250, 50);
              printArray(IDs);
            }
    
            void draw() {
              //print text from arrays onto sketch
    
              //prints the employee ids, names, and hours worked from the array
              for (int i=0; i< IDs.length; i++) {
                println(IDs[i]);
                println(Hours[i]);
                println(Names[i]);
                textFont(font, 16);
                text(IDs[i], 100, 150*i);
                text(Names[i], 125, 150*i);
                noLoop();
              }
            }
    
    
    
    
            void calculatePay(float hours) {
              float result;
              float TimeAndHalf= 1.5;
              float NormalPay=1;
              //result = (Hours[]*MINIMUM_WAGE);
              //return result;
            }
    

    here is my EmployeeHours.txt 40 25.5 45 42 here is my EmployeeID.txt 1 2 3 4 and here is my EmployeeName.txt Alabaster Snowball Bush Evergren Pepper Minstix Sugerplum Mary

  • This

    text(IDs[i], 100, 150*i);

    Better

    text(IDs[i], 100, 150*i + 60);

  • @chrissir perfect! thank you now i just need to work on a function and make it look better and i am done!

  • Yes! Well done.

  • @chrissir sooo im working on this function and im aware that i cant use > to compare with a string but i cant seem to find something equivalent, also for my function it wants floats not strings, maybe im missing something else.. hopefully my function is actually some what correct, it makes sense to me and comparing to previous functions ive made it looks pretty accurate

    //Carmine 
    //
    //Lab 5 Payroll Lab
    //
    
    PFont font;
    final float MINIMUM_WAGE=9.84;
    String[] IDs;
    String[] Names;
    String[] Hours;
    
    void setup() {
      size(800, 600);
      background(255);
      IDs=loadStrings("EmployeeID.txt");
      Names=loadStrings("EmployeeName.txt");
      Hours=loadStrings("EmployeeHours.txt");
      font= loadFont("ComicSansMS-48.vlw");
      textFont(font, 32);
      fill(0);
      text("Sam's Payroll", 250, 50);
      printArray(IDs);
    }
    
    void draw() {
      //print text from arrays onto sketch
    
      //prints the employee ids, names, and hours worked from the array
      for (int i=0; i< IDs.length; i++) {
        println(IDs[i]);
        println(Hours[i]);
        println(Names[i]);
        textFont(font, 16);
        text(IDs[i], 100, 150*i+60);
        text(Names[i], 125, 150*i+60);
        noLoop();
        text (calculatePay(Hours[i]), 300, i*60));
      }
    }
    
    
    
    
    void calculatePay(float hours) {
      float result;
      float rate=0;
      float TimeAndHalf= 1.5;
      float NormalPay=1;
    
      if (Hours[i]>40) {
        rate=MINIMUM_WAGE*TimeAndHalf;
        result= Hours[i]*rate
      } else if (Hours[i]<=40) {
        rate=MINIMUM_WAGE;
        result=Hours[i]*rate;
      }
    }
    

    so here it all is again lol

  • text (calculatePay(Hours[i]), 300, i*60));

    Better

    text(calculatePay(float (Hours......

    instead of void calculatePay you want float calculatePay

    Last line in function = return result;

  • Hours over 40 receive time-and-a-half pay. All employees are paid minimum wage of Alaska 9.84)

    I think when it’s >40 you want only the amount of hours over 40 to be multiplied with a higher factor and not all hours

  • so i think im getting further still have errors tho on calculatePay in the draw and processing doesnt like my operators in my function

    //Carmine
    //
    //Lab 5 Payroll Lab
    //
    
    PFont font;
    final float MINIMUM_WAGE=9.84;
    String[] IDs;
    String[] Names;
    String[] Hours;
    
    void setup() {
      size(800, 600);
      background(255);
      IDs=loadStrings("EmployeeID.txt");
      Names=loadStrings("EmployeeName.txt");
      Hours=loadStrings("EmployeeHours.txt");
      font= loadFont("ComicSansMS-48.vlw");
      textFont(font, 32);
      fill(0);
      text("Sam's Payroll", 250, 50);
      printArray(IDs);
    }
    
    void draw() {
      //print text from arrays onto sketch
    
      //prints the employee ids, names, and hours worked from the array
      for (int i=0; i< IDs.length; i++) {
        println(IDs[i]);
        println(Hours[i]);
        println(Names[i]);
        textFont(font, 16);
        text(IDs[i], 100, 150*i+60);
        text(Names[i], 125, 150*i+60);
        noLoop();
        text (calculatePay(float(Hours[i]), 300, i*60));
      }
    }
    
    
    
    
    float calculatePay(float hours) {
      float result;
      float rate=0;
      float TimeAndHalf= 1.5;
      float NormalPay=1;
      float overTime;
      float overTimeRate;
      float totalOverTime;
    
      if (Hours[i]>40) {
        overTimeRate=MINIMUM_WAGE*TimeAndHalf;
        overTime=((Hours[i])-(40));
        totalOverTime= overTime*overTimeRate;
        result= (Hours[i]*rate)+(totalOverTime);
      } else  {
        rate=MINIMUM_WAGE;
        result=Hours[i]*rate;
        return result;
      }
    }
    
  • This after line 62

    return result;

    Line 57 : define rate first!

    Don’t use Hours[i] in the function, use the parameter hours!!!!!!!

    Line 37 one missing )

    Post your entire code

  • @chrissir alright its a lot better now but im not seeing where the missing ) needs to be in line 37?

    //Carmine
    //
    //Lab 5 Payroll Lab
    //
    
    PFont font;
    final float MINIMUM_WAGE=9.84;
    String[] IDs;
    String[] Names;
    String[] Hours;
    
    void setup() {
      size(800, 600);
      background(255);
      IDs=loadStrings("EmployeeID.txt");
      Names=loadStrings("EmployeeName.txt");
      Hours=loadStrings("EmployeeHours.txt");
      font= loadFont("ComicSansMS-48.vlw");
      textFont(font, 32);
      fill(0);
      text("Sam's Payroll", 250, 50);
      printArray(IDs);
    }
    
    void draw() {
      //print text from arrays onto sketch
    
      //prints the employee ids, names, and hours worked from the array
      for (int i=0; i< IDs.length; i++) {
        println(IDs[i]);
        println(Hours[i]);
        println(Names[i]);
        textFont(font, 16);
        text(IDs[i], 100, 150*i+60);
        text(Names[i], 125, 150*i+60);
        noLoop();
        fill(255, 0, 0);
        text(calculatePay(float(Hours[i]), 300, i*60));
      }
    }
    
    
    
    
    float calculatePay(float hours) {
      float result;
      float rate=MINIMUM_WAGE;
      float TimeAndHalf= 1.5;
      float NormalPay=1;
      float overTime;
      float overTimeRate;
      float totalOverTime;
    
      if (hours>40) {
        overTimeRate=MINIMUM_WAGE*TimeAndHalf;
        overTime=((hours)-(40));
        //why isnt nfc liking this 
        totalOverTime= (overTime)*(overTimeRate));
        result= (hours*rate)+(totalOverTime);
      } else {
        rate=MINIMUM_WAGE;
        result=(hours*rate);
      }
      return result;
    }
    
  • Does the code run?

    ) after]

    Not at end of line...

  • Answer ✓

    ok i figured something out on my own finally it works just like it should thank you so much @chrissir you should work at my school

    //Carmine 
    //
    //Lab 5 Payroll Lab
    //
    
    PFont font;
    final float MINIMUM_WAGE=9.84;
    String[] IDs;
    String[] Names;
    String[] Hours;
    float pay;
    
    void setup() {
      size(800, 600);
      background(255);
      IDs=loadStrings("EmployeeID.txt");
      Names=loadStrings("EmployeeName.txt");
      Hours=loadStrings("EmployeeHours.txt");
      font= loadFont("ComicSansMS-48.vlw");
      textFont(font, 32);
      fill(0);
      text("Sam's Payroll", 250, 50);
    }
    
    void draw() {
      //print text from arrays onto sketch
      //prints the employee ids, names, and hours worked from the array
      for (int i=0; i< IDs.length; i++) {
        //println(IDs[i]);
        //println(Hours[i]);
        //println(Names[i]);
        textFont(font, 16);
        fill(0);
        text(IDs[i], 100, 160*i+70);
        text(Names[i], 125, 160*i+70);
        noLoop();
        fill(255, 0, 0);
        pay=calculatePay(float(Hours[i]));
        text(pay,300,160*i+70);
        //text(calculatePay(float(Hours[i]), 300, i*60));
      }
    }
    
    
    
    
    float calculatePay(float hours) {
      float result;
      float rate=MINIMUM_WAGE;
      float TimeAndHalf= 1.5;
      float NormalPay=1;
      float overTime;
      float overTimeRate;
      float totalOverTime;
    
      if (hours>40) {
        overTimeRate=MINIMUM_WAGE*TimeAndHalf;
        overTime=((hours)-(40));
        //why isnt nfc liking this 
        totalOverTime= (overTime)*(overTimeRate);
        result= (hours*rate)+(totalOverTime);
        println(result);
      } else {
        rate=MINIMUM_WAGE;
        result=(hours*rate);
      }
      return result;
    }
    
  • Congratulations

Sign In or Register to comment.