*URGENT JAVA PROGRAMMING LAB*
so I need to write some classes for my lab if someone could give me an outline or just how I should so it that would be awesom
here is the questions please help ASAP
A. A histogram is used to plot tabulated frequencies. Create a Histogram class that can be used to maintain and plot the frequencies of numbers that fall within a specified range. The Histogram class contain will an array of counters with equal intervals within the specified range (For example, see Test 1 and Test 2). All counters are first initialized to zero. When the number added to the Histogram falls within the range of a particular counter that counter is incremented by one. The Histogram class should contain the following methods:
• A constructor that accepts the number of counters and the maximum and minimum limits of the numbers (.i.e., the range of numbers).
• A second constructor that accepts the maximum and minimum limits of the numbers and initializes the Histogram with 10 counters for the specified range.
• An add(double x) method that increments the corresponding counter.
• A reset() method that sets all counter frequencies to zero. • A plotFrequency method that plots the counter frequencies. (See below)
• A plotCumulative method that plots the cumulative frequencies. (See below) Sample frequency and cumulative frequency plots with 5 counters:
Frequency Plot: Counter 1 : ******************************** (987)
Counter 2 : *****************************************(1014)
Counter 3: ***************************(950)
Counter 4: *********************************************(1065)
Counter 5: **************************************(984)
Cumulative Frequency Plot: Counter 1 : ****** (987)
Counter 2 : ***************(2001)
Counter 3: ***************************(2951)
Counter 4: ***************************************(4016)
Counter 5: **************************************************(5000)
Please note that the above plots are no to scale. You program should be able to determine the appropriate scale from the counter frequencies and scale the plot to fit within a printable page. Use the maximum frequency and total counter frequencies to scale the frequency and cumulative frequency plots.
Test cases: Write a RandomNumberTester class that uses the Histogram class to test the Math.random() method provided in the java SDK.
Test 1: Create 10 counters with the following limits:
Bin Number Limit
Counter 0 0 <= x < 0.1
Counter 1 0.1 <= x < 0.2
Counter 2 0.2 <=x < 0.3
Counter 3 0.3 <=x < 0.4
Counter 4 0.4 <= x < 0.5
Counter 5 0.5 <= x < 0.6
Counter 6 0.6 <= x < 0.7
Counter 7 0.7 <= x < 0.8
Counter 8 0.8 <= x < 0.9
Counter 9 0.9 <= x < 1.0
Generate a random number between 0 and 1. Increment the corresponding counter by 1. For example if the random number is 0.57, increment counter 5 by 1. Repeat this 10,000 times. Print the counter frequencies and the cumulative frequencies.
Test 2: Create 10 counters with the following limits:
Bin Number Limit Counter 0 0 <= x < 1
Counter 1 1 <= x < 2
Counter 2 2 <= x < 3
Counter 3 3 <= x < 4
Counter 4 4 <= x < 5
Counter 5 5 <= x < 6
Counter 6 6 <= x < 7
Counter 7 7 <= x < 8
Counter 8 8 <= x < 9
Counter 9 9 <= x < 10
Generate 10 random numbers between 0 and 1 and add them up. Increment the corresponding bin by 1. Repeat this 1,000 times. Print the counter frequencies and the cumulative frequencies. Any surprises/comments?
B. It is said that if a deck of cards is given perfect shuffles enough times, it will return to its original order. A perfect shuffle is done by splitting the deck exactly in half and interleaving the cards from the two halves; that is, the first card is from the first half, the second from the second half, the third from the first half, and so on. For example, Initial State:
AH 2H 3H 4H 5H 6H 7H 8H 9H 10H JH QH KH
AC 2C 3C 4C 5C 6C 7C 8C 9C 10C JC QC KC
AD 2D 3D 4D 5D 6D 7D 8D 9D 10D JD QD KD
AS 2S 3S 4S 5S 6S 7S 8S 9S 10S JS QS KS
After first shuffle: AH AD 2H 2D 3H 3D 4H 4D 5H 5D 6H 6D 7H
7D 8H 8D 9H 9D 10H 10D JH JD QH QD KH KD
AC AS 2C 2S 3C 3S 4C 4S 5C 5S 6C 6S 7C
7S 8C 8S 9C 9S 10C 10S JC JS QC QS KC KS
Create a Deck class with the following methods
• Deck() constructor that creates an unshuffled deck.
• A shuffle() method that does a perfect shuffle.
• A toString() method that print the deck as shown above.
• An equals(Deck aDeck) method that compares itself with the given deck and returns true if all the cards in both decks are in the same order and false otherwise
Write a DeckTester and test the Deck class by doing perfect shuffles on a deck. Start with two new decks in the main tester program and shuffle one deck. After each shuffle compare the shuffled deck with the unshuffled deck and see if they are in the same order. Shuffle up to 20 perfect shuffles or until the shuffled deck returns to its original order. The program should display the current order after each shuffle.
Thank you so much!
import java.util.Random;
class Counter {
public double min;
public double max;
public double freq;
public Counter(double min, double max){
this.freq = 0.0;
this.min = min;
this.max = max;
}
public double getMin() {
return min;
}
public void setMin(double min) {
this.min = min;
}
public double getMax() {
return max;
}
public void setMax(double max) {
this.max = max;
}
public void increment() {
this.freq += 1.0;
}
public void addVal(double x){
this.freq += x;
}
public double getFrequency(){
return this.freq;
}
public void resetFrequency(){
this.freq = 0.0;
}
}
class Histogram {
public Counter[] counters;
public void setCounters(Counter[] counters) {
this.counters = counters;
}
public static final int pageSize = 10000; //assuming page size is fixed to 10000.
public Histogram(int size, double min[], double max[]){
counters = new Counter[size];
for(int i = 0;i<size;i++){
counters[i] = new Counter(min[i], max[i]);
}
}
public Histogram(double min[], double max[]){
counters = new Counter[10];
for(int i = 0;i<10;i++){
counters[i] = new Counter(min[i], max[i]);
}
}
public Counter[] getCounters() {
return counters;
}
public void add(Counter c, double x){
c.addVal(x);
}
public void reset(Counter c){
c.resetFrequency();
}
public double getMaxFreq(){
double max = Double.MIN_VALUE;
for(int i = 0;i<counters.length;i++){
if(counters[i].freq > max)
max = counters[i].freq;
}
return max;
}
public double getMinFreq(){
double min = Double.MAX_VALUE;
for(int i = 0;i<counters.length;i++){
if(counters[i].freq < min)
min = counters[i].freq;
}
return min;
}
public double getTotalFreq(){
double total = 0.0;
for(int i = 0;i<counters.length;i++){
total += counters[i].freq;
}
return total;
}
public String getBlockString(int size){
StringBuilder sb = new StringBuilder();
for(int i =1;i<=size;i++)
sb.append('*');
return sb.toString();
}
public void plotFrequency() {
//first find the bock size to utilize the whole page
int blockSize = (int) (pageSize/getMaxFreq());
for(int i =0;i<counters.length;i++){
int counterSize = (int)(blockSize * counters[i].getFrequency());
System.out.println("Counter " + (i+1) + ": " + getBlockString(counterSize));
}
}
public void plotCumulative() {
//first find the bock size to utilize the whole page
int blockSize = (int) (pageSize/getTotalFreq());
double cumFreq = 0.0;
for(int i =0;i<counters.length;i++){
cumFreq += counters[i].getFrequency();
int counterSize = (int)(blockSize * cumFreq);
System.out.println("Counter " + (i+1) + ": " + getBlockString(counterSize));
}
}
}
public class RandomNumberTester {
public static void main(String[] args){
//take test 1 data
double min[] = {0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9};
double max[] = {0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0};
Histogram test1 = new Histogram(min, max);
Random rand = new Random();
for(int i=1;i<=10000;i++) {
double n = rand.nextDouble();
Counter[] c = test1.getCounters();
for(int j = 0;j<c.length; j++) {
if(c[j].min <= n && n <= c[j].max) {
c[j].increment();
continue;
}
}
}
test1.plotFrequency();
test1.plotCumulative();
}
}
PROBLEM 2
======================
import java.util.List;
import java.util.ArrayList;
import java.util.Arrays;
class Deck {
private ArrayList<String> state;
public Deck(List<String> state) {
this.state = new ArrayList<String>(state);
}
public void shuffle() {
int len = state.size();
ArrayList<String> deck1 = new ArrayList<String>(state.subList(0, len/4));
ArrayList<String> deck2 = new ArrayList<String>(state.subList(len/4, 2*(len/4)));
ArrayList<String> deck3 = new ArrayList<String>(state.subList( 2*(len/4), 3*(len/4)));
ArrayList<String> deck4 = new ArrayList<String>(state.subList( 3*(len/4), len));
state = new ArrayList<String>();
for(int i =0;i<len/4;i++) {
state.add(deck1.get(i));
state.add(deck3.get(i));
state.add(deck2.get(i));
state.add(deck4.get(i));
}
}
public String toString() {
StringBuilder sb =new StringBuilder();
for(int i =0;i<state.size();i++) {
sb.append(state.get(i));
sb.append(" ");
}
return sb.toString();
}
public void setState(ArrayList<String> state) {
this.state = state;
}
public ArrayList<String> getState() {
return state;
}
public boolean equals(Deck d) {
return this.state.toString().equals(d.getState().toString());
}
}
public class Test {
public static void main(String[] args) {
List<String> state = Arrays.asList(
"AH", "2H", "3H", "4H",
"AC", "2C", "3C", "4C",
"AD", "2D", "3D", "4D",
"AS", "2S", "3S", "4S");
Deck deck1 =new Deck(state);
Deck deck2 = new Deck(state);
for(int i =0;i<20;i++) {
deck1.shuffle();
System.out.println("Shuffled Deck : " + deck1.toString());
if(deck1.equals(deck2)) {
System.out.println("Two decks are same. Returning from main method");
return;
}
}
}
}
*URGENT JAVA PROGRAMMING LAB* so I need to write some classes for my lab if someone...
hello there, i have to implement this on java processing. can someone please help me regarding that? thanks War is the name of a popular children’s card game. There are many variants. After playing War with a friend for over an hour, they argue that this game must never end . However! You are convinced that it will end. As a budding computer scientist, you decide to build a simulator to find out for sure! You will implement the logic...
*Java* Hi. I need some help with creating generic methods in Java. Write a program GenMethods that has the following generic methods: (1) Write the following method that returns a new ArrayList. The new list contains the nonduplicate (i.e., distinct) elements from the original list. public static ArrayList removeDuplicates(ArrayList list) (2) Write the following method that shuffles an ArrayList. It should do this specifically by swapping two indexes determined by the use of the random class (use Random rand =...
need letters (i), (j), (k), and (l), please and thank
you
Please write a 10 pages' statistical report how to study the length of sharks. You and use internet or other resources to obtain additional information. The basic information is given below Great white are big and hungry. Here are the lengths in feet of the following great whites: 18.7 12.3 18.6 15.7 18.3 14.6 15.8 14.9 17.6 12.1 16.4 16.7 17.8 16.2 12.6 17.8 13.8 12.2 15.2 14.7 12.4...
Need help with java programming. Here is what I need to do: Write a Java program that could help test programs that use text files. Your program will copy an input file to standard output, but whenever it sees a “$integer”, will replace that variable by a corresponding value in a 2ndfile, which will be called the “variable value file”. The requirements for the assignment: 1. The input and variable value file are both text files that will be specified in...
Needs Help with Java programming language For this assignment, you need to write a simulation program to determine the average waiting time at a grocery store checkout while varying the number of customers and the number of checkout lanes. Classes needed: SortedLinked List: Implement a generic sorted singly-linked list which contains all of the elements included in the unsorted linked list developed in class, but modifies it in the following way: • delete the addfirst, addlast, and add(index) methods and...
I need java code for the following problem.
Lab 7: Methods 1. Write a Java program called Numbers that calls the following methods and displays the returned value: Write a method called cubelt that accepts one integer parameter and returns the value raised to the third power as an integer. o Write a method called randominRange that accepts two integer parameters representing a range. The method returns a random integer in the specified range inclusive. 2. o Write a method...
1. Consider the following data: 18, 20, 25, 31, 32, 38, 39, 40, 43, 49, 51, 54, 65, 74 Use 4 classes. a. Class width : b. Complete the following table. ????? ?????? ????? − ????? Class Boundaries Midpoint Frequencies Relative Frequencies Cumulative Frequencies c. Draw a histogram. d. Draw a relative frequency histogram. e. Make a stem-and-leaf display. f. Find the interquartile range. g. Make a box-and-whisker plot. h. Determine the distribution shape. Please comment on all three plots....
Someone plz plz help with this Statistics Intro to R programming
question!!!
Here are the examples and follow by my question!!
Thank you so much!! I appreciate it
!!!!My question!!!!
Question Type 1: If possible, calculate the 90% confidence intervals for the temperature it takes for crickets to chirp 15 chirps per second. Code (you must copy and paste your code like below in blue color): # Reading in the data Crickets-read.table(C:/Desktop/CricketChirpsvsTemperature.csv', header TRUE, #View Data View Crickets) #Data analysis...
Could anyone help add to my python code? I now need to calculate the mean and median. In this programming assignment you are to extend the program you wrote for Number Stats to determine the median and mode of the numbers read from the file. You are to create a program called numstat2.py that reads a series of integer numbers from a file and determines and displays the following: The name of the file. The sum of the numbers. The...
identify the 25 correct statements in the set below
identify 25 correct statements
Please identify the 25 correct statements in the set below: Discovery analytics focuses on the question "Why did it happen?" Predicting a presidential candidate's percentage of the statewide vote from a sample of 800 voters would be an example of inferential statistics. This year, Oxnard University produced two football All-Americans. This is an example of continuous data. Sturges' Rule is merely a suggestion, not an ironclad requirement....