In: Computer Science
What would an example of java code look like?
Producer class
- Declaring toolsPerHour as an instance variable
- Creating constructor that takes toolsPerHour
- Creating getter for toolsPerHour
- Method for calculating days produced
Tester class
- Creating 3 producer objects using constructor
- Setting toolsPerHour
- Calling methods
- Displaying output
Thanks for the question. Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks =========================================================================== public class Producer { // Declaring toolsPerHour as an instance variable private int toolsPerHour; //- Creating constructor that takes toolsPerHour public Producer(int toolsPerHour) { this.toolsPerHour = toolsPerHour; } //- Creating getter for toolsPerHour public int getToolsPerHour() { return toolsPerHour; } //- Method for calculating days produced public int days(int tools) { if (toolsPerHour != 0) { // assumping the plan operates 8hrs a day int totalHoursNeeded = tools / toolsPerHour; return totalHoursNeeded / 8; // return the number of days } else { return 0; } } } ====================================================================== public class Tester { public static void main(String[] args) { //- Creating 3 producer objects using constructor Producer one = new Producer(10); // Setting toolsPerHour to 10 Producer two = new Producer(20); // Setting toolsPerHour t0 20 Producer three = new Producer(50); // Setting toolsPerHour to 50 //- Calling methods //- Displaying output System.out.println("Days needed to produce 1000 tools by Producer 1 = " + one.days(1000) + " days"); System.out.println("Days needed to produce 1000 tools by Producer 2 = " + two.days(1000) + " days"); System.out.println("Days needed to produce 1000 tools by Producer 3 = " + three.days(1000) + " days"); } }
====================================================================