Question

In: Computer Science

What would an example of java code look like? Producer class - Declaring toolsPerHour as an...

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

Solutions

Expert Solution

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");


    }
}

====================================================================


Related Solutions

What are the Signature lines of a Java class code? With an example. and the UML...
What are the Signature lines of a Java class code? With an example. and the UML diagram.
What would the pseudocode look like for this UML class diagram? Class - oranges: String -...
What would the pseudocode look like for this UML class diagram? Class - oranges: String - bananas: String - grapes: String - apples: String + Class(String bananas, String grapes, String apples) + oranges( ): void + isValidGrapes( ): boolean + isValidApples( ): boolean + getOranges( ): String + getBananas( ): String + setBananas(String bananas): void + getGrapes( ): String + setGrapes(String grapes): void + getApples( ): String + setApples(String apples): void
How would I get this java code to work and with a main class that would...
How would I get this java code to work and with a main class that would demo the rat class? class rat { private String name; private String specialAbility; private int TotalHealth; private int shieldedHealth; private int cooldown; public rat() { } public rat(String n,String SA,int TH,int SH,int cd) { name=n; specialAbility=SA; TotalHealth=TH; shieldedHealth=SH; cooldown=cd; } public void setname(String n) { name=n; } public String getname() { return name; } public void setability(String SA) { specialAbility=SA; } public String getability()...
What would the code look like if you weren't using hash maps and array lists (only...
What would the code look like if you weren't using hash maps and array lists (only using scanner import) and solving using a partition algorithm?
If you wanted to store a birthday within code, what class would you use in Java?...
If you wanted to store a birthday within code, what class would you use in Java? and why??
I actually would like you to take a look at my code and point it out...
I actually would like you to take a look at my code and point it out if there is anything wrong with it. I think there might be because there are some values that are the same in different arrays. QUESTION: C++ Use the random number generator in class Random to store a list of 1000 random integer values in an array. Create 3 arrays using this method. Apply each of the insertion, bubble, selection and shell sort algorithms to...
What would a more democratic United States look like?
What would a more democratic United States look like?
write the code based on this pseudocode //Create Class any name (ex: aQ) //Declaring private integer...
write the code based on this pseudocode //Create Class any name (ex: aQ) //Declaring private integer array empty one ex: name arrQ[] //Declare private integers front, rear, size and len (example, but you call any other names) //Write constructors Called public and same name of the class (parameters integer n) Inside Declare where: size is equal to n len is equal to zero arrQ is equal to new integer[size] front is equal minus 1 rear is equal minus 1 //Declare...
What would the spectrum of a classical particle in a box look like, and what does...
What would the spectrum of a classical particle in a box look like, and what does this imply concerning the importance of quantum mechanics in understanding optical spectroscopy of atoms and molecules?
Explain what saturation of the glucose transporter means and what this would look like on a...
Explain what saturation of the glucose transporter means and what this would look like on a graph showing glucose transport rate vs. concentration of glucose (as was shown in the previous question). How can you increase the rate of glucose transport when you have reached saturation?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT