Extra Credit Programming Assignment(7points)Due May 1, midnightWrite a JavaFX application that presents 20 circles, each with a random radius and location. If a circle does not overlap any other circle, fill in the circle with black. Fill in overlapping circles with a translucent blue. Use an array to store the circle objects,and check each new circle to see if it overlaps any previous created circle. Two circles overlap is the distance between their center points is less than the sum of their radii

Answers

Answer 1

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);

}

}


Related Questions

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.

Answers

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

Answers

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

Answers

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?

Answers

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.

Answers

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.

Answers

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

}

Other Questions
5 people made the following grades on the last math test: 45, 83, 45, 77, 99. Use this information to find the mean. what is the mean?what is the range?what is the median?i will mark brainliest Find the perimeter of each polygon. Assume that lines which appear to be tangent are tangent. Harold Manufacturing produces denim clothing. This year, it produced 5,220 denim jackets at a manufacturing cost of $42.00 each. These jackets were damaged in the warehouse during storage. Management investigated the matter and identified three alternatives for these jackets. 1) Jackets can be sold to a secondhand clothing shop for $7.00 each. 2) Jackets can be disassembled at a cost of $32,700 and sold to a recycler for $12.00 each. 3) Jackets can be reworked and turned into good jackets. However, with the damage, management estimates it will be able to assemble the good parts of the 5,220 jackets into only 2,970 jackets. The remaining pieces of fabric will be discarded. The cost of reworking the jackets will be $101,900, but the jackets can then be sold for their regular price of $44.00 each.Required:Calculate the incremental income. Sales increased by 1/2 last month. If the sales from the previous month were $152,850 what were last months sales? 16-year-old high school student Gregory thinks of himself as a member of the "musical clique" at school and feels that the musicians are the best group of students. He thinks poorly of athletes and spends most of his time with peers who share similar interest. This is an example of __________ theory. what kind of ecosystem is the thorn scrubA. wetlandB. grasslandc. badlandd. shrubland What causes the formation of ionic bonds? Which is the main goal of HIV treatmentto completely cure the person of the HIV infectionto keep the person's immune system functioningto rid the body of all viruses and gain immunity against AIDSto keep the person's T cell count as low as possible 6th grade math please help ! c; What is the greatest common factor and least common multiple of 4 and 10? Fiona says that 7% of the model is shaded.Do you agree? Why or why not?O Yes, because 7 parts are shaded.O Yes, because 7 of 10 parts are shaded.O No, becauseparts shaded equals 70%.O No, because 6 parts are shaded.PLEASE HELP IM BEING TIMED ILL GIVE THE BRAINLIEST What are the four areas of the treaty of Versailles A student sits on a rotating stool holding two 5 kg objects. When his arms are extended horizontally, the objects are 0.9 m from the axis of rotation, and he rotates with angular speed of 0.66 rad/sec. The moment of inertia of the student plus the stool is 8 kg m2 and is assumed to be constant. The student then pulls the objects horizontally to a radius 0.31 m from the rotation axis. Calculate the final angular speed of the student. Which states should be labeled as West Coast states? Washington, Oregon, Alaska, California California, Oregon, Washington, Hawaii California, Oregon, Washington Washington, California, Hawaii What was the reaction of Japan to the protest over their invasion of Manchuria? True or false: 4 (2x + y + 6) is equivalent to 8x + 4y + 24.A trueB false Name 1 way a biotic factor interacts with another biotic Factor. Solve the equation below showing all steps.3/4 (x + 3) = 9 Use a graphing utility to find the sum of the geometric sequence.15n56n=1The sum is- (Round to three decimal places as needed.)phony ___ probability is the predicted ratio of favorable outcomes to the total number of outcomes. Steam Workshop Downloader