Question

Here is a bit of Java code: Thing t = new Thing(); t.method( (int i)-> i...

  1. Here is a bit of Java code:
    Thing t = new Thing();
    t.method( (int i)-> i + 1 );
    

    Here is a skeleton for class Thing:

    class Thing {
        public interface Mystery {
            ?????
        }
        public void method( Mystery param ) {
            // body of method omitted
        }
    }
    

    Which text below would work where ????? is given above:
    a) void method( int i );
    b) int method( int i );
    c) abstract int method( int i );
    d) abstract void method( int i );
    e) private int method( int i );

  2. Consider the final simulation framework given at the end of the notes for Oct. 13. Suppose the following code is used in the initialization:
    Simulator.schedule( 8.0*hour, (double t)->w.open(t) );
    
    Assume that w is a workplace, and every workplace has a method open(double t) that simulates the workplace opening for business at time t.

    The value 8.0*hour is passed as t to w.open(t) through the following steps that are not given in order (and some steps are omitted):
    v) e is removed from eventSet.
    w) 8.0*hour is put in e.time for some Event e.
    x) w.open(t) is called.
    y) e.act.trigger(e.time) is called.
    z) e drifts to the head of eventSet.

    What is the correct order for these steps?
    a) vwyzx
    b) xwyvz
    c) ywzvx
    d) wzvyx
    e) zywvx

  3. Assume that time zero is midnight on day zero of the simulation, so 8*hour is 8AM on day zero. Given that w is a workplace with methods open(t) and close(t), and given that the work day is 8 hours long, a workplace that opens at 8AM should close at 5PM. This requires the following code:
    public void open(double time) {
        Simulator.schedule( time + 8*hour, ------- );
    }
    
    What code belongs where the above shows -------?
    a) ()-> open( time )
    b) (double t)-> open( t )
    c) this.open( time )
    d) ()-> this.open( time );
    e) (double t)-> this.open( t )
  4. Given that we are using type double to represent time, we could define day = 1.0 so that hours are fractional days. If we do this, we should define hour as:
    a) final double hour = 0.4166;
    b) double hour = 1 / 24;
    d) final double hour = day * 0.4166;
    c) double hour = day * 0.4166;
    e) final double hour = day / 24.0;
  5. Suppose we want to model weekends? To do this, when a workplace closes at 5PM on a normal weekday, it schedules itself to reopen 16 hours later at 8AM, but on Friday afternoon, it should schedule itself to open 54 hours later, that is, skipping an extra 48 hours. Assume that day zero begins at the midnight separating Sunday from Monday. What expression below is true only on Friday?

    a) (Double.intValue( time ) % 7) == 4
    b) ( time % 7) == 4
    c) (Double.intValue( time ) % 7) == 5
    d) ( time % 7) == 5
    e) (Double.intValue( time ) / 7) == 0.5

Homework Answers

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
I have a 2 class code and it works everything is fine and runs as it...
I have a 2 class code and it works everything is fine and runs as it supposed too. What will the UML be for both classes. Here's the code, any help will be awsome, Thanks. import java.util.Scanner; public class PayRollDemo { public static void main(String[] args) { double payRate; int hours; PayRoll pr = new PayRoll(); Scanner keyboard = new Scanner(System.in); for (int index = 0; index < 7 ; index++ ) { System.out.println(); System.out.println("EmployeeID:" + pr.getEmployeeID(index)); System.out.println(); System.out.println("Enter the...
I am trying to solve the following C++ problem over structures. I am having trouble with...
I am trying to solve the following C++ problem over structures. I am having trouble with the very last structure and I made a comment next to where I am confused. I included the assignment instructions and my current code. I would appreciate if anyone can help me explain what I need to do for the last structure. Thank you. Assignment Instructions Create a program that will prompt me for each of the following items: 1. Date of Birth 2....
I need this before the end of the day please :) In Java 10.13 Lab 10...
I need this before the end of the day please :) In Java 10.13 Lab 10 Lab 10 This program reads times of runners in a race from a file and puts them into an array. It then displays how many people ran the race, it lists all of the times, and if finds the average time and the fastest time. In BlueJ create a project called Lab10 Create a class called Main Delete what is in the class you...
[Java] I'm not sure how to implement the code. Please check my code at the bottom....
[Java] I'm not sure how to implement the code. Please check my code at the bottom. In this problem you will write several static methods to work with arrays and ArrayLists. Remember that a static method does not work on the instance variables of the class. All the data needed is provided in the parameters. Call the class Util. Notice how the methods are invoked in UtilTester. public static int min(int[] array) gets the minimum value in the array public...
I have written working code for this problem however it is not producing an output and...
I have written working code for this problem however it is not producing an output and it states is a wrong answer. Please just fix my code below and make it work for the sample test cases and all test cases. You are given a pointer to the root of a binary search tree and values to be inserted into the tree. Insert the values into their appropriate position in the binary search tree and return the root of the...
In this code, I build a single-linked list using a node class that has been created....
In this code, I build a single-linked list using a node class that has been created. How could I change this code to take data of type T, rather than int. (PS: ignore the fact that IOHelper.getInt won't work for the type T... ie second half of main). Here's my code right now: public class SLList { public SLNode head = null; public SLNode tail = null; public void add(int a) {// add() method present for testing purposes SLNode newNode...
Java question, Please answer everything. Thank you Answer the following questions as briefly (but completely) as...
Java question, Please answer everything. Thank you Answer the following questions as briefly (but completely) as possible: What is a checked exception, and what is an unchecked exception? What is NullPointerException? Which of the following statements (if any) will throw an exception? If no exception is thrown, what is the output? 1: System.out.println( 1 / 0 ); 2: System.out.println( 1.0 / 0 ); Point out the problem in the following code. Does the code throw any exceptions? 1: long value...
The ability to read through Java™ code and predict the results, given specific inputs, is an...
The ability to read through Java™ code and predict the results, given specific inputs, is an extremely useful skill. For this assignment, you will be analyzing the Java™ code in the linked zip file, and predicting the results given specific input. Carefully read through the code line by line, then answer the following questions in a Microsoft® Word document: What is the output of the program as it is written? What would the output of the program be if you...
vThere are 3 steps in a laundry shop: i) Washing, ii) Drying, iii) Folding. If we...
vThere are 3 steps in a laundry shop: i) Washing, ii) Drying, iii) Folding. If we assume the time to do each load is 25, 50 and 35 minutes, respectively. We can assume that there is no variability in the process and all operations work fully efficiently. a) What is the Lead Time of the laundry shop? b) What is the Cycle Time? What is the throughput rate (loads per hour) of the laundry? c) What is the utilization %...
Hi, I'm writing a Java program that prints a grid with circles and squares that have...
Hi, I'm writing a Java program that prints a grid with circles and squares that have letters in them and it is also supposed to print the toString() function to the console window each time the application runs. This toString() function is supposed to show the tile's shape, letter, and color component (or components). Could someone please review and debug my code to help me figure out why my toString() function is not working? import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JButton;...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT