Question: java Program 1 , Histogram , takes an integer n, and two integers left and right, and uses StdDraw to plot a histogram of the
java
-
Program 1, Histogram, takes an integer n, and two integers left and right, and uses StdDraw to plot a histogram of the count of the numbers in the standard input stream that fall in each of the n intervals defined by dividing (left, right) into n equal-sized intervals.
Note: The program is to read the values from an input file whose first line would contain n, left, and right values. The remaining lines would contain the sequence of integer values.
A sample run would be as follows.
>more data.txt
4 40 80
52 41 72 61
71 60 50 52 61
77 41 61 70 79 41
67 60 50 61 76
>java Histogram < data.txt
It should plot a histogram where the x-axis points are 40, 50, 60, 70, 80 and the intervals are 40-50, 50-60, 60-70, 70-80. The height of the rectangles for the intervals should be 3, 4, 7, 6 respectively.
-
Program 2, Hamming, will read in an integer k and a bit string s from the command line, calculate the Hamming Distances, and prints all bit strings that have Hamming distance of k from s.
Note: The Hamming Distance is equal to the number of bits in which the two strings differ.
A sample run would be as follows.
>java Hamming 2 0011 1111 1001 1010 0101 0110 0000
-
Program 3, Square, will implement a data type Square that represents squares with the x and y coordinates of their upper-left corners and the length.
The API should be as follows.
Square(double x, double y, double length) //constructor
double area() //returns the area of the square
double perimeter() //returns the perimeter of the square
boolean intersects(Square b) //does this square intersect b? Two squares would intersect if they share one or more common points
boolean contains(Square b) //does this square contain b?
void draw() //draw this square on standard drawing
Note: The program should include a main method to test that it does the following.
-
Instantiate a Square object whose upper-left corner coordinates and length are given as command-line arguments. It should print out the area and perimeter of the square.
-
Prompt the user for a second squares upper-left corner coordinates and length, and indicate whether it intersects with the square specified earlier and also whether it contains the square specified earlier.
-
Provide a pop-up window that displays the two squares.
A sample run would be as follows.
>java Square 0.2 0.7 0.3
The area is 0.09
The perimeter is 1.2
Enter the upper-left coordinates and the length of a square: 0.3 0.6 0.4
It intersects the first square.
It does not contain the first square.
Also a window should pop up that displays both the squares.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
