Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

please help me on this task. the deadline is very soon. i will say thanku in advance. you can take 3 questions from my remaining

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

please help me on this task. the deadline is very soon. i will say thanku in advance. you can take 3 questions from my remaining question but please do this. Below is the pevious task 3 answer.

import java.util.ArrayList; class Vehicle { // base class

int capacity; String make;

Vehicle(int theCapacity, String theMake) { capacity = theCapacity; make = theMake; }

void print() { System.out.println("Vehicle Info:"); System.out.println(" capacity = " + capacity + "cc" ); System.out.println(" make = " + make ); } void setCapacity(int newCapacity) { capacity = newCapacity; System.out.println("New capacity = "+capacity); } }

class Car extends Vehicle {

// ... extra code here ... String carmodel = ""; String cartype = ""; Car(int theCapacity, String theMake, String theType, String theModel) { super(theCapacity,theMake); cartype = theType; carmodel = theModel; } void print() { super.print(); System.out.println(" type = " + cartype ); System.out.println(" model = " + carmodel ); } void setCapacity(int newCapacity) { System.out.println("Cannot change capacity of a car"); }

}

class VehicleDB {

ArrayList db = new ArrayList();

void addVehicle(Vehicle c){ db.add(c); }

void print(){ System.out.println("=== Vehicle Data Base ==="); for(Vehicle v: db){ v.print(); } } } class Task4 {

public static void main(String [] args) { VehicleDB db = new VehicleDB() ; db.addVehicle(new Car(1200,"Holden" ,"sedan" ,"Barina")) ; db.addVehicle(new Vehicle(1500,"Mazda")) ; db. print() ; } }

Question Task 4: Variable producer delay (30 marks) Copy your code from Task 3 into a new directory named task4 Stage 1 Modify your producer so the sleep interval can be controlled by the message content 1. Replace the sleep function with nanosleep. The default sleep interval should remain at 10 seconds. 2. Each time a message is read that begins with the control sequence $P:n, where n represents one or more integers, the sleep interval should be adjusted accordingly The number should be interpreted as milliseconds. The occurrence of a non-integer in the message terminates the number (this includes a space). Sleep intervals (numbers) less than 800 ms or greater than 20,000 ms should be ignored The message should still be passed through to the consumer. * See the table below for examples. Message SP:12000 P:3000qwerty $P:500qwerty P:25000qwerty SP :6000qwerty qwertySP:5800 SP:800 qwerty SP:20000a 12345 Sp:1500qwerty Sleep interval result Valid. Sleep interval updated to 12,000 ms Valid. Sleep interval updated to 3000 ms Invalid. The value (500) is below the minimum of 800 ms Invalid. The value (25,000) is above the maximum of 20,000 ms Invalid. The message does not confirm to the format $P:n (extra space) Invalid. The control message is not at the beginning of the line Valid. Sleep interval updated to 800 ms Valid. Sleep interval updated to 20,000 ms Invalid. The message does not begin with $P: owercase p Hint: The nanosleep function works a bit differently than sleep and accepts both a nanoseconds and seconds value. You will need to perform the necessary calculation to convert the milseconds value specified by the $P: control messages to the appropriate unit for nanosleep. Stage 2 Test your code with various sleep intervals based on the control message format. Utilise top to observe the effect of different producer sleep intervals on CPU usage. Is there a difference in utilisation when various sleep intervals are used? What happens if you run the producer without the consumer? . Our shared buffer currently has room for a single message at a time. Let the producer run for a while and then start the consumer. What happens? Are the producer and consumer synchronised Discuss your observations and question answers in your report. Contrast with the use of a fixed interval

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Pro Database Migration To Azure Data Modernization For The Enterprise

Authors: Kevin Kline, Denis McDowell, Dustin Dorsey, Matt Gordon

1st Edition

1484282299, 978-1484282298

More Books

Students also viewed these Databases questions

Question

When does the group seem to be apathetic?

Answered: 1 week ago