Answer:
See Explaination
Explanation:
// CircleOverlap.java
import java.util.Random;
import javafx.application.Application;
import static javafx.application.Application.launch;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.paint.Paint;
import javafx.scene.shape.Circle;
import javafx.stage.Stage;
public class CircleOverlap extends Application {
atOverride //Replace the at with at symbol
public void start(Stage primaryStage) {
//creating a Random number generator object
Random random = new Random();
//setting window size
int windowWidth = 500;
int windowHeight = 500;
//initializing array of circles
Circle array[] = new Circle[20];
//looping for 20 times
for (int i = 0; i < array.length; i++) {
//generating a value between 10 and 50 for radius
int radius = random.nextInt(41) + 10;
//generating a random x,y coordinates, ensuring that the circle fits
//within the window
int centerX = random.nextInt(windowWidth - 2 * radius) + radius;
int centerY = random.nextInt(windowHeight - 2 * radius) + radius;
//creating Circle object
Circle circle = new Circle();
circle.setCenterX(centerX);
circle.setCenterY(centerY);
circle.setRadius(radius);
//adding to array
array[i] = circle;
//flag to check if circle is overlapping any previous circle
boolean isOverlapping = false;
//looping through the previous circles to see if they are overlapping
for (int j = 0; j < i; j++) {
//finding x, y and radius of current circle under check
double x2 = array[j].getCenterX();
double dx = x2 - centerX;
double y2 = array[j].getCenterY();
double dy = y2 - centerY;
double r2 = array[j].getRadius();
//finding distance between this circle and the circle under check
double distance = Math.sqrt((dx * dx) + (dy * dy));
//checking if distance<radius1+radius2
if (distance <= (radius + r2)) {
//overlapping, setting transclucent blue color
Paint c = new Color(0, 0, 1.0, 0.3);
array[i].setFill(c);
isOverlapping = true;
//also changing the color of other circle
array[j].setFill(c);
}
}
if (!isOverlapping) {
//not overlapping, setting black color
array[i].setFill(Color.BLACK);
}
}
//creating a pane and adding all circles
Pane root = new Pane();
root.getChildren().addAll(array);
Scene scene = new Scene(root, windowWidth, windowHeight);
primaryStage.setScene(scene);
primaryStage.setTitle("");
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
Create a public non-final class named Larger parameterized by a type T that implements Comparable. (Please use T or the test suite will fail.) You should provide a single instance method named larger that accepts an array of the parameterized type as the first argument and a single value of the parameterized type as the second argument. larger should return true if the second argument is larger than or equal to every value of the array and false otherwise. If either the array or the value are null you should throw an IllegalArgumentException. As an ungraded bonus challenge, see if you can make the compiler warning about unchecked operations go away… (Note that normally we would write this as a class method. Java does support type parameters for static methods, but we aren’t going to cover that in class. So we’ll use an instance method here instead.) Note also that this homework is not due until Friday but was accidentally released Thursday. It does rely on material we will cover Friday. Feel free to wait to complete it then.
Answer:
see explaination
Explanation:
class Larger<T extends Comparable<T>> {
public boolean larger(T[] arr, T item) {
if (arr == null || item == null)
throw new IllegalArgumentException();
for (int i = 0; i < arr.length; i++) {
if (item.compareTo(arr[i]) < 0) {
return false;
}
}
return true;
}
}
Which of the following is a possible disadvantage of recursion? Question 10 options: Recursive solutions can be less efficient than their iterative counterparts Recursive solutions tend to be longer than their iterative counterparts Recursive solutions are more likely to go into infinite loops than their iterative counterparts Recursive solutions tend to have more local variables than their iterative counterparts
Answer:
Recursive solutions can be less efficient than their iterative counterparts
Explanation:
Recursion can be defined or described as a method of solving a problem where the solution depends on solutions to smaller instances of the same problem.
It entails using iteration to ensure that smaller parts of a solution are satisfied towards solving thw overall problem.
Ita major disadvantage seems to be that it seem to be less efficient than their iterative counterparts. This is as a result of concentrating on trying to solve a smaller instances.
A user in the accounting department reports he or she cannot access the invoices that the sales department has placed on the shared drive. This points toward a possible problem with which component of the computer’s operating system? Networking Time-sharing Interrupts Device Driver
Answer:
Networking.
Explanation:
An operating system which was developed in the 1950s, is a software which acts as an intermediary between the computer hardware and end users.
The functions of an Operating System are; Memory, Device, Process, File, Secondary-Storage and Input/Output management.
The networking component of the computer's operating system ensures that a group of processors don't share memory, clock and hardware devices, instead the processors communicate with each other through the network.
Basically, the network Operating System (OS) runs on a server and provides the capability to serve to manage groups, user, application or program, data, security and any other networking functions.
Hence, the accountant couldn't access the invoices that the sales department placed on the shared drive because of a networking component problem of the computer’s operating system.
The electric company gives a discount on electricity based upon usage. The normal rate is $.60 per Kilowatt Hour (KWH). If the number of KWH is above 1,000, then the rate is $.45 per KWH. Write a program (L4_Ex1.cpp) that prompts the user for the number of Kilowatt Hours used and then calculates and prints the total electric bill. Please put comment lines, same as in Lab3, at the beginning of your program. According to your program in Lab 4.1, how much will it cost for: 900 KWH? 1,754 KWH? 10,000 KWH?
Answer:
The cpp program for the given scenario is shown below.
#include <stdio.h>
#include <iostream>
using namespace std;
int main()
{
//variables to hold both the given values
double normal_rate = 0.60;
double rate_1000 = 0.45;
//variable to to hold user input
double kwh;
//variable to hold computed value
double bill;
std::cout << "Enter the number of kilowatt hours used: ";
cin>>kwh;
std::cout<<std::endl<<"===== ELECTRIC BILL ====="<< std::endl;
//bill computed and displayed to the user
if(kwh<1000)
{
bill = kwh*normal_rate;
std::cout<< "Total kilowatt hours used: "<<kwh<< std::endl;
std::cout<< "Rate for the given usage: $"<<normal_rate<< std::endl;
std::cout<< "Total bill: $" <<bill<< std::endl;
}
else
{
bill = kwh*rate_1000;
std::cout<< "Total kilowatt hours used: "<<kwh<< std::endl;
std::cout<< "Rate for the given usage: $"<<rate_1000<< std::endl;
std::cout<< "Total bill: $" <<bill<< std::endl;
}
std::cout<<std::endl<< "===== BILL FOR GIVEN VALUES ====="<< std::endl;
//computing bill for given values of kilowatt hours
double bill_900 = 900*normal_rate;
std::cout << "Total bill for 900 kilowatt hours: $"<< bill_900<< std::endl;
double bill_1754 = 1754*rate_1000;
std::cout << "Total bill for 1754 kilowatt hours: $"<< bill_1754<< std::endl;
double bill_10000 = 10000*rate_1000;
std::cout << "Total bill for 10000 kilowatt hours: $"<< bill_10000<< std::endl;
return 0;
}
OUTPUT
Enter the number of kilowatt hours used: 555
===== ELECTRIC BILL =====
Total kilowatt hours used: 555
Rate for the given usage: $0.6
Total bill: $333
===== BILL FOR GIVEN VALUES =====
Total bill for 900 kilowatt hours: $540
Total bill for 1754 kilowatt hours: $789.3
Total bill for 10000 kilowatt hours: $4500
Explanation:
1. The program takes input from the user for kilowatt hours used.
2. The bill is computed based on the user input.
3. The bill is displayed with three components, kilowatt hours used, rate and the total bill.
4. The bill for the three given values of kilowatt hours is computed and displayed.
When composing an email message:a.ideas should be organized inductively when the message contains good news or routine information.b.just be direct, since such communications are routine.c.present the information in the order it is likely needed or will be best received.d.avoid repeating information that is in the subject line in the opening sentence.
Question:
When composing an email message:
A) ideas should be organized inductively when the message contains good news or routine information.
B) just be direct, since such communications are routine.
C) present the information in the order it is likely needed or will be best received.
D) avoid repeating information that is in the subject line in the opening sentence.
Answer:
The correct answer is C)
When writing emails, it helps to put ones self in the shoes of the recipient. This helps us to present our thoughts in the way that the recipient will best receive them.
In addition to the above, one must ensure that they go directly to the point, use a courteous tone, and ensure that the message is free from typographical errors whenever he or she is writing an email.
Cheers!
Create a public non-final class named Partitioner. Implement a public static method int partition(int[] values) that returns the input array of ints partitioned using the last array value as the pivot. All values smaller than the pivot should precede it in the array, and all values larger than or equal to should follow it. Your function should return the position of the pivot value. If the array is null or empty you should return 0.
Answer:
See Explaination
Explanation:
public class Partitioner {
public static int partition(int[] values){
if(values==null || values.length==0)return 0;
// storing the pivot value
int pivot = values[values.length-1];
//sorting the array
for(int i=0;i<values.length-1;i++){
int m_index = i;
for (int j=i+1;j<values.length;j++)
if(values[j]<values[m_index])
m_index = j;
int tmp = values[m_index];
values[m_index] = values[i];
values[i] = tmp;
}
int i = 0;
// first finding the index of pivot
// value in sorted order and recording index in i
while (i<values.length){
if(pivot==values[i]){
if(i==values.length-1)break;
int j=0;
// finding the location for inserting the
while (j<values.length){
if(pivot<=values[j]){
// inserting the values
values[i] = values[j];
values[j] = pivot;
break;
}
j++;
}
break;
}
i++;
}
return i;
}
// main method for testing can be removable
public static void main(String[] args) {
int a[] = {4,1,6,2};
System.out.println(partition(a));
}// end of main
}