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...
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...
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 %...
Complete a Java program named ARMgr that maintains customer accounts receivable in a database. The code...
Complete a Java program named ARMgr that maintains customer accounts receivable in a database. The code to initialize the CustomerAccountsDB database table and add a set of customer accounts is provided. Finish the code in these 3 methods in CustomerAccountDB.java to update or query the database: -purchase(double amountOfPurchase) -payment(double amountOfPayment) -getCustomerName() Hint: For getCustomerName(), look at the getAccountBalance() method to see an example of querying data from the database. For the purchase() and payment() methods, look at the addCustomerAccount() method...
THIS IS FOR JAVA I have to write a method for a game of Hangman. The...
THIS IS FOR JAVA I have to write a method for a game of Hangman. The word the user is trying to guess is made up of hashtags like so " ###### " If the user guesses a letter correctly then that letter is revealed on the hashtags like so "##e##e##" If the user guesses incorrectly then it increments an int variable named count " ++count; " String guessWord(String guess,String word, String pound) In this method, you compare the character(letter)...
this is the book name. Data Structures and Abstractions with Java 1) Description: The sample programs...
this is the book name. Data Structures and Abstractions with Java 1) Description: The sample programs in Chapter 1 of your textbook are not complete. They are used for illustration purpose only. The implementation of Listing 1-1 on page 39 is explained in Chapter 2. And, in order to see the result of using it, we will need the following set of files: i. BagInteface.java – the specification only. ii. ArrayBag.java – the implementation of BagInerface.java. iii. ArrayBagDemo.java – a...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT