Question: Consider the following method (and class variables), that are intended to enforce the following rules: The bridge is single track, so cars can only use

 Consider the following method (and class variables), that are intended toenforce the following rules: The bridge is single track, so cars can

Consider the following method (and class variables), that are intended to enforce the following rules: The bridge is single track, so cars can only use the bridge in one direction at once; Only three cars can travel eastbound at once; Only one car can travel westbound at once. int carCount = 0; boolean westbound = false; public synchronized void enterBridge (Vehicle v) ! //block westbound = v.getWestbound(); //set direction to your direction ++ carCount; //increment cars using bridge System.out.println(v + " entering the bridge"); } Which of the following variants if put in place of //block could be used to correctly enforce these conditions? You may assume that the remainder of the code is correctly implemented. block 1: while((v.getWestbound() != westbound && carCount > 0) || (!v.getWestbound() && carCount > 2) || (v.getWestbound() fe & carCount > 0)) try! wait(); } catch (InterruptedException e) { e.printStackTrace(); } 1 block 2: while((v.getWestbound() !- westbound && carCount > 0) && (!v.getWestbound()&& carCount > 2) && (v.getWestbound() && carCount > 0)) { try wait(); } catch (InterruptedException e) { e.printStackTrace(); } block 3: if((v.getWestbound() !- westbound && carCount > 0) 11 (!v.getWestbound() && carCount > 2) || (v.getWestbound() && carCount > 0)) { try! wait(); } catch (InterruptedException e) { e.printStackTrace(); } block 4: if((v.getWestbound() != westbound && carCount > 0)) { if (!v.getWestbound() 66 carCount > 2) { if (v.getWestbound() && carCount > 0) { tryt wait(); } catch (InterruptedException e) { e.printStackTrace(); } 1 block 5: if((v.getWestbound() != westbound && carCount > 0)) { try wait(); } catch (InterruptedException e) { e.printStackTrace(); } if(!v.getWestbound() && carCount > 2) { try{ wait(); } catch (InterruptedException e) { e.printStackTrace(); } } if (v.getWestbound () && carCount > 0) { try{ wait(); } catch (InterruptedException e) { e.printStackTrace(); } } block 6: while ((v.getWestbound() != westbound && carCount > 0)) { tryd wait(); } catch (InterruptedException e) { e.printStackTrace(); } } while (!v.getWestbound() && carCount > 2) { try{ wait(); } catch (InterruptedException e) { e.printStackTrace(); } } while (v.getWestbound() && carCount > 0) { tryd wait(); } catch (InterruptedException e) { e.printStackTrace(); } } Select one or more: a. block 1 b.block 2 c. block 3 d. block 4 e. block 5 f.block 6 Consider the following method (and class variables), that are intended to enforce the following rules: The bridge is single track, so cars can only use the bridge in one direction at once; Only three cars can travel eastbound at once; Only one car can travel westbound at once. int carCount = 0; boolean westbound = false; public synchronized void enterBridge (Vehicle v) ! //block westbound = v.getWestbound(); //set direction to your direction ++ carCount; //increment cars using bridge System.out.println(v + " entering the bridge"); } Which of the following variants if put in place of //block could be used to correctly enforce these conditions? You may assume that the remainder of the code is correctly implemented. block 1: while((v.getWestbound() != westbound && carCount > 0) || (!v.getWestbound() && carCount > 2) || (v.getWestbound() fe & carCount > 0)) try! wait(); } catch (InterruptedException e) { e.printStackTrace(); } 1 block 2: while((v.getWestbound() !- westbound && carCount > 0) && (!v.getWestbound()&& carCount > 2) && (v.getWestbound() && carCount > 0)) { try wait(); } catch (InterruptedException e) { e.printStackTrace(); } block 3: if((v.getWestbound() !- westbound && carCount > 0) 11 (!v.getWestbound() && carCount > 2) || (v.getWestbound() && carCount > 0)) { try! wait(); } catch (InterruptedException e) { e.printStackTrace(); } block 4: if((v.getWestbound() != westbound && carCount > 0)) { if (!v.getWestbound() 66 carCount > 2) { if (v.getWestbound() && carCount > 0) { tryt wait(); } catch (InterruptedException e) { e.printStackTrace(); } 1 block 5: if((v.getWestbound() != westbound && carCount > 0)) { try wait(); } catch (InterruptedException e) { e.printStackTrace(); } if(!v.getWestbound() && carCount > 2) { try{ wait(); } catch (InterruptedException e) { e.printStackTrace(); } } if (v.getWestbound () && carCount > 0) { try{ wait(); } catch (InterruptedException e) { e.printStackTrace(); } } block 6: while ((v.getWestbound() != westbound && carCount > 0)) { tryd wait(); } catch (InterruptedException e) { e.printStackTrace(); } } while (!v.getWestbound() && carCount > 2) { try{ wait(); } catch (InterruptedException e) { e.printStackTrace(); } } while (v.getWestbound() && carCount > 0) { tryd wait(); } catch (InterruptedException e) { e.printStackTrace(); } } Select one or more: a. block 1 b.block 2 c. block 3 d. block 4 e. block 5 f.block 6

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!