Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I am confused, professor wants us to use an array I believe it\'s to keep track

ID: 3797254 • Letter: I

Question

I am confused, professor wants us to use an array I believe it's to keep track of the time entries but I am not sure. Please help! COSC 210-object oriented and GUI Programming Assignment 3 Due: February 24th at 2:00 AM 30 points The objectives of this exercise are to: 1) Gain further experience with using the Eclipse IDE. 2) Gain an understanding of arrays and use of control statements. 3) Develop and test a small Java program applying the concepts of objective 2. AFTER YOU HAVE COMPLETED, put all your files into a zip file named lyour name]Assignment3.zip. Include all .class and java files. Upload your zip file to Moodle by the due date. Printout and turn-in all source files and output from your program.

Explanation / Answer

Yes, You are right. He wanted you to use an Array/ArrayList to store the list of time entries.

Date Entry will look like

class DateEntry{

// Along with getters and setters

String date;

int startHour;

int endHour;

}

So, In PayStub class you will be having an ArrayList field to which a DateEntry object is added through an add() method.

After which you will use that list to compute the normal/over time hours and all other computations.

import java.util.ArrayList;

class DateEntry{
  
   public DateEntry() {
       super();
   }
   public DateEntry(String date, int startHour, int endHour) {
       super();
       this.date = date;
       this.startHour = startHour;
       this.endHour = endHour;
   }
   String date;
   int startHour;
   int endHour;
   public String getDate() {
       return date;
   }
   public void setDate(String date) {
       this.date = date;
   }
   public int getStartHour() {
       return startHour;
   }
   public void setStartHour(int startHour) {
       this.startHour = startHour;
   }
   public int getEndHour() {
       return endHour;
   }
   public void setEndHour(int endHour) {
       this.endHour = endHour;
   }
  
}
class PayStub {
  
   private ArrayList<DateEntry> dateEntries = new ArrayList<DateEntry>();
  
   public void addEntry(DateEntry dateEntry){
       dateEntries.add(dateEntry);
   }
   // You will use dateEntries object for computation
   //It includes all other methods for computation and printing reports
}
class DriverProgram{
   public static void main(String args[]){
       DateEntry dateEntry = new DateEntry("01/14/2012/", 8, 17);
       PayStub payStub = new PayStub();
       payStub.addEntry(dateEntry);
       dateEntry = new DateEntry("01/15/2012/", 8, 20);
       payStub.addEntry(dateEntry);
       dateEntry = new DateEntry("01/16/2012/", 12, 19);
       payStub.addEntry(dateEntry);
   }
}