CREATE A CONSOLE APPLICATION USING ECLIPSE.
import java.util.ArrayList;
import java.util.Random;
/* Computer Science and Information Systems
* Programming and Problem Solving II
* Code Practice and Review
* Stockton University
*
* The following exercise will walk you through a lot of the
* topics covered in the first installment of the series.
*
* This specific exercise uses climate data.
*
* Topics include:
*
CLASSES AND METHODS
ARRAY/ARRAYLIST
CONDITIONAL LOGIC (IF/ELSE-IF/SWITCH)
ITERATION (FOR/DO/WHILE)
STRING MANIPULATION (SUBSTR/LENGTH/CHARAT)
FUNDAMENTAL TOOLS (RANDOM/SCANNER)
FORMATTED OUTPUT (PRINTF/STDOUT/STDERR)
*
*/
public class Student {
// The insertion point for this application
public static void main(String[] args) {
// Create some arrays to store possible conditions
double[] aryWaveHeight = new double[5];
double[] aryTemperature = new double[5];
String[] aryWeather = new String[5];
// ------------------------------------------------------------------------
// CREATE YOUR ARRAYLIST HERE
// Populate the arrays with data
aryWaveHeight[0] = 36;
aryWaveHeight[1] = 14;
aryWaveHeight[2] = 25;
aryWaveHeight[3] = 48;
aryWaveHeight[4] = 9;
aryTemperature[0] = 92;
aryTemperature[1] = 87;
aryTemperature[2] = 65;
aryTemperature[3] = 72;
aryTemperature[4] = 83;
aryWeather[0] = "Heavy rain and cloud cover.";
aryWeather[1] = "Partly cloudy, chance of rain later.";
aryWeather[2] = "Warm and dry. Clear skies all day.";
aryWeather[3] = "Scattered T-Storms and showers.";
aryWeather[4] = "Sunny and hazy. Light clouds in the mid-afternoon.";
// ---------------------------------------
// CREATE A RANDOM NUMBER GENERATOR OBJECT
// -------------------------------------------------------------------------------------
// PUT A LOOPING CONSTRUCT HERE: FILL YOUR ARRAYLIST WITH 1000 RANDOM WEATHER CONDITIONS
// CREATE A TEMPORARY RANDOM WEATHER CONDITION
WeatherInstance randomCondition = new WeatherInstance();
randomCondition.temperature = aryTemperature[generator.nextInt(5)];
randomCondition.waveHeight = aryWaveHeight[generator.nextInt(5)];
randomCondition.weather = aryWeather[generator.nextInt(5)];
// OUTPUT THE RANDOMLY GENERATED CONDITION'S PARAMETERS
System.out.println("Temp: " + randomCondition.temperature);
System.out.println("Wave: " + randomCondition.waveHeight);
System.out.println(randomCondition.weather);
// POPULATE THE ARRAYLIST
weatherConditions.add(randomCondition);
// --------------------------------------------------------------------------------------
// PUT A LOOPING CONSTRUCT HERE: COUNT HOW MANY TIMES A TEMPERATURE ABOVE 75 WAS OBSERVED
int tempsAbove75 = 0;
if (weatherConditions.get(i).getTemperature() > 75) tempsAbove75++;
System.out.println(tempsAbove75 + " specific occurences out of 1000, or approx. " + (tempsAbove75/10.0) + "% of observations were above 75 degrees");
// -----------------------------------------------------------------------------------------
// PUT A NESTED CONTROL STRUCTURE HERE: COUNT HOW MANY TIMES
// SCATTERED T-STORMS OCCURED AT THE SAME TIME THAT WAVE HEIGHT WAS BELOW 30
int tStormsWaveHeightBelow30 = 0;
for (int i=0; i<1000; i++) {
}
System.out.println(tStormsWaveHeightBelow30 + " specific occurences out of 1000, or approx. " + (tStormsWaveHeightBelow30/10.0) + "% of observations were during scattered T-Storms with waves below 30");
}
}Program:





Code:
Note: Changes and new additions made to the code are in bold text.
import java.util.ArrayList;
import java.util.Random;
/* Computer Science and Information Systems
* Programming and Problem Solving II
* Code Practice and Review
* Stockton University
*
* The following exercise will walk you through a lot of the
* topics covered in the first installment of the series.
*
* This specific exercise uses climate data.
*
* Topics include:
*
CLASSES AND METHODS
ARRAY/ARRAYLIST
CONDITIONAL LOGIC
(IF/ELSE-IF/SWITCH)
ITERATION (FOR/DO/WHILE)
STRING MANIPULATION
(SUBSTR/LENGTH/CHARAT)
FUNDAMENTAL TOOLS
(RANDOM/SCANNER)
FORMATTED OUTPUT
(PRINTF/STDOUT/STDERR)
*
*/
//class weather instance
class WeatherInstance{
//variable to store temperature
double temperature;
//variable to store
waveHeight
double waveHeight;
//variable to store weather
String weather;
//getters for the above variables
double getTemperature(){
return this.temperature;
}
double getWaveHeight(){
return this.waveHeight;
}
String getWeather(){
return this.weather;
}
}
public class Student {
// The insertion point for this application
public static void main(String[] args)
{
// Create some arrays to store
possible conditions
double[] aryWaveHeight = new
double[5];
double[] aryTemperature = new
double[5];
String[] aryWeather = new
String[5];
//
------------------------------------------------------------------------
// CREATE YOUR ARRAYLIST HERE
//creating array list
//ArrayList is created as
below
//ArrayList is created by
specifying the type of objects it contains
ArrayList<WeatherInstance>
weatherConditions = new ArrayList<WeatherInstance>();
// Populate the arrays with
data
aryWaveHeight[0] = 36;
aryWaveHeight[1] = 14;
aryWaveHeight[2] = 25;
aryWaveHeight[3] = 48;
aryWaveHeight[4] = 9;
aryTemperature[0] = 92;
aryTemperature[1] = 87;
aryTemperature[2] = 65;
aryTemperature[3] = 72;
aryTemperature[4] = 83;
aryWeather[0] = "Heavy rain and
cloud cover.";
aryWeather[1] = "Partly cloudy,
chance of rain later.";
aryWeather[2] = "Warm and dry.
Clear skies all day.";
aryWeather[3] = "Scattered T-Storms
and showers.";
aryWeather[4] = "Sunny and hazy.
Light clouds in the mid-afternoon.";
//
---------------------------------------
// CREATE A RANDOM NUMBER GENERATOR
OBJECT
//Random generator object
is created by calling its constructor
Random generator = new
Random();
//
-------------------------------------------------------------------------------------
// PUT A LOOPING CONSTRUCT HERE:
FILL YOUR ARRAYLIST WITH 1000 RANDOM WEATHER CONDITIONS
//for loop is created by
specifying initialization,condition,updation statements
//seperated by semicolons(;)
for(int i=0;i<1000;i++){
// CREATE A
TEMPORARY RANDOM WEATHER CONDITION
WeatherInstance
randomCondition = new WeatherInstance();
randomCondition.temperature =
aryTemperature[generator.nextInt(5)];
randomCondition.waveHeight =
aryWaveHeight[generator.nextInt(5)];
randomCondition.weather = aryWeather[generator.nextInt(5)];
// OUTPUT THE
RANDOMLY GENERATED CONDITION'S PARAMETERS
System.out.println("Temp: " + randomCondition.temperature);
System.out.println("Wave: " + randomCondition.waveHeight);
System.out.println(randomCondition.weather);
// POPULATE
THE ARRAYLIST
weatherConditions.add(randomCondition);
}
//
--------------------------------------------------------------------------------------
// PUT A LOOPING CONSTRUCT HERE:
COUNT HOW MANY TIMES A TEMPERATURE ABOVE 75 WAS OBSERVED
int tempsAbove75 =
0;
//size() is a method of ArrayList
class which returns count of elements present in it
for(int
i=0;i<weatherConditions.size();i++){
if
(weatherConditions.get(i).getTemperature() > 75)
tempsAbove75++;
}
System.out.println(tempsAbove75 + " specific occurences out of
1000, or approx. " + (tempsAbove75/10.0) + "% of observations were
above 75 degrees");
//
-----------------------------------------------------------------------------------------
// PUT A NESTED CONTROL STRUCTURE
HERE: COUNT HOW MANY TIMES
// SCATTERED T-STORMS OCCURED AT
THE SAME TIME THAT WAVE HEIGHT WAS BELOW 30
int tStormsWaveHeightBelow30 =
0;
for (int i=0; i<1000; i++) {
//if
condition to check weather as SCATTERED T-STORMS OCCURED
//equals()
method checks for equality of two strings(It is a method in class
String)
if(weatherConditions.get(i).getWeather().equals("Scattered T-Storms
and showers."))
//if condition to check whether wave height is
less than 30
if(weatherConditions.get(i).getWaveHeight()<30)
tStormsWaveHeightBelow30++;
}
System.out.println(tStormsWaveHeightBelow30 + " specific occurences
out of 1000, or approx. " + (tStormsWaveHeightBelow30/10.0) + "% of
observations were during scattered T-Storms with waves below
30");
}
}
Output:

CREATE A CONSOLE APPLICATION USING ECLIPSE. import java.util.ArrayList; import java.util.Random; /* Computer Science and Information Systems...
import java.util.Random; import java.util.ArrayList; /** * */ public class hw5_task8 { public static void main(String[] args) { int[] grades = randomIntArr(10); printIntArray("grades", grades); ArrayList<Integer> indexesF_AL = selectIndexes_1(grades); System.out.println(" indexesF_AL: " + indexesF_AL); int[] indexesF_Arr = selectIndexes_2(grades); printIntArray("indexesF_Arr",indexesF_Arr); } public static int[] randomIntArr(int N){ int[] res = new int[N]; Random r = new Random(0); for(int i = 0; i < res.length; i++){ res[i] = r.nextInt(101); // r.nextInt(101) returns an in in range [0, 100] } return res; } public static void...
Can I get help with implementing a quick sort in my program? Starter Code: import java.util.Random; import java.util.Scanner; import java.util.Arrays; import java.util.Collections; import java.util.ArrayList; public class RQS { public static int[] prepareData(int[] patients){ /* Data is prepared by inserting random values between 1 and 1000. Data items may be assumed to be unique. Please refer to lab spec for the problem definiton. */ // what is our range? int max = 1000; // create instance of Random class Random randomNum...
I created this program using the Java-oriented programming application known as Eclipse for a lottery system, however it's not giving me the output I want. The output should look something like this: Trial Sum Count of Occurrence 3 150 4 170 5 1100 6 1460 ... 83 240 84 90 Any help with the following program would be appreciated /* Simulate a Pick 3 lottery system and conduct 100,000 independent lottery trials* reporting out aggregate statistical data based on your...
the RollDie.java:
import java.util.Random;
import java.util.Scanner;
/*
* HEADER HERE !!
*/
public class RollDie {
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
// Step 1: Declare and initialize array and
// initialize random number generator
int[] rollValueCounts = new int[7];
Random randGen = new Random();
// Step 2: Determine the number of rolls
System.out.print("How many times do you want to roll the die?");
System.out.print(" [Max value is 100] ");
int numRolls = scnr.nextInt();
// TODO:...
Write code for RSA encryption package rsa; import java.util.ArrayList; import java.util.Random; import java.util.Scanner; public class RSA { private BigInteger phi; private BigInteger e; private BigInteger d; private BigInteger num; public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); System.out.println("Enter the message you would like to encode, using any ASCII characters: "); String input = keyboard.nextLine(); int[] ASCIIvalues = new int[input.length()]; for (int i = 0; i < input.length(); i++) { ASCIIvalues[i] = input.charAt(i); } String ASCIInumbers...
import java.util.Iterator; import java.util.LinkedList; import java.util.TreeMap; import java.util.ArrayList; public class MultiValuedTreeMap<K, V> extends TreeMap<K, LinkedList<V>> implements Iterable<Pair<K, V>> { private static final long serialVersionUID = -6229569372944782075L; public void add(K k, V v) { if (!containsKey(k)) { put(k, new LinkedList<V>()); } get(k).add(v); } public V removeFirst(K k) { if (!containsKey(k)) { return null; } V value = get(k).removeFirst(); if (get(k).isEmpty()) { super.remove(k); } return value; }...
Can someone help me with my Java code error! Domain package challenge5race; import java.util.Random; public class Car { private int year; private String model; private String make; int speed; public Car(int year, String model, String make, int speed) { this.year = year; this.model = model; this.make = make; this.speed = speed; } public Car() { } public int getYear() { return year; } public void setYear(int year) { this.year = year; } public String getModel() { return model; }...
How do i rewrite this code only using the list below? import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.Set; import java.util.HashSet; public class RotationCheck { /** * Rotates the elements in the specified list by the specified distance. After calling this * method, the element at index {@code i} will be the element previously at index * {@code (i - distance) % list.size()}, for all values of {@code i} between {@code 0} and * {@code...
Open BlueJ and create a new project (Project->New
Project...).
Create a new class named ListsDemo.
Open the source code and delete all the boilerplate code.
Type in the code to type (code to type with bigger font)
exactly as shown, filling in your name and the date in the places
indicated.
The code is provided as an image because you should type it in
rather than copy-paste. If you need the code as text for
accessibility, such as using a...
Language is Java, any help is appreciated. Thank you! WHERE TO START FROM: import java.util.ArrayList; //PartTest.java //package simple; public class PartTest { public static void main(String[] args) { ArrayList<ExpendablePart> system=new ArrayList<ExpendablePart>(); // creating Part Object Part part1 = new ExpendablePart("Last, First"); part1.setNumber("AX-34R"); part1.setNcage("MN34R"); part1.setNiin("ABCD-RF-WDE-KLJM"); // printing information System.out.println(part1.toString()); //Create a part2 object of class Part Part part2=new ConsumablePart("Widget, purple"); part2.setNumber("12345"); part2.setNcage("OU812"); part2.setNiin("1234-12-123-1234"); // printing information System.out.println(part2.toString()); //checking equality of two Part class objects if(part1.equals(part2)) System.out.println("part1 and...