Question

In: Computer Science

Arrays Assignment in Java 1. Suppose you are doing a report on speeding. You have the...

Arrays Assignment in Java

1. Suppose you are doing a report on speeding. You have the data from 10 different people who were speeding and would like to find out some statistics on them. Write a program that will input the speed they were going. You may assume that the speed limit was 55. Your program should output the highest speed, the average speed, the number of people who were between 0-10 miles over, the number between 10 and 20, and the number over 20. Your program should print out these results.

2. Create a list of 100 randomly generated numbers (between 1 and 100). Print the list out in order, print the list out in reverse order, print out how many of each number was generated.

Solutions

Expert Solution

JAVA PROGRAM

1

import java.util.*;
import java.util.Scanner;

public class Main
{
   public static void main(String[] args) {
   Scanner sc = new Scanner(System.in);
   // array declaration
       int speed[] = new int[10];
       int i = 0,c1=0,c2=0,c3=0,highspeed = 0;
       float avg = 0;
       // runs the loop
   for(i=0;i<10;i++)
   {
   // reads the input from user and store it in array
   speed[i] = sc.nextInt();
   }  
   // runs the loop
   for(i=0;i<10;i++)
   {
   // checks the conditon for number between 0 - 10
   if(speed[i]>=0 && speed[i]<=10)
   {
   // keeps track of 0 - 10
   c1++;
   }
   // checks the conditon for number between 10 - 20
   if(speed[i]>10 && speed[i]<=20)
   {
   // keeps track of 10 - 20
   c2++;
   }
   // checks the conditon for number over 20
   if(speed[i]>20)
   {
   // keeps track of over 20
   c3++;
   }
   // checks the conditon to find highspeed
   if(highspeed<speed[i])
   {
   highspeed = speed[i];
   }
   // calculating sum of all
   avg+=speed[i];
   }
   // calculating Average
   avg = avg/10;
   // prints the statement
   System.out.println("The Number Between:0-10:"+c1);
   System.out.println("The Number Between:10-20:"+c2);
   System.out.println("The Number Over 20:"+c3);
   System.out.println("Average Speed:"+avg);
   System.out.println("Highest Speed:"+highspeed);
     
   }
}

OUTPUT

2.

import java.util.*;
import java.util.Scanner;
import java.util.Random;
public class Main
{
   public static void main(String[] args) {
   Scanner sc = new Scanner(System.in);
   ArrayList<Integer> array = new ArrayList<Integer>(100);
   Random rand = new Random();
   int i=0,j=0,count=0,temp=0;
   for(i=0;i<100;i++)
   {
   temp = rand.nextInt(101 - 1) + 1;
   array.add(temp);
  
   }
   System.out.println("List Inorder:");
   // runs the loop to print in in order
   for(i=0;i<100;i++)
   {
   // prints the element of list
   System.out.print(array.get(i)+" ");
   }
   System.out.println("\nList In Reverse:");
   for(i=99;i>=0;i--){
   System.out.print(array.get(i)+" ");
   }
  
  
   System.out.println("\nEach Number Generated:");
   //boolean array
boolean visited[] = new boolean[100];
// fills the boolean array with false
Arrays.fill(visited, false);
  
// runs the loop
for ( i = 0; i < 100; i++) {
  
// checks the condition
//Skip this element if already processed
if (visited[i] == true)
continue;
  
// keeps track of Count frequency
count = 1;
// runs the loop
for ( j = i + 1; j < 100; j++)
{
if (array.get(i) == array.get(j))
{
visited[j] = true;
count++;
}
}
System.out.println(array.get(i) + " " + count);
}
     
   }
}

output

thumbs up

.


Related Solutions

answer in JAVA language please In this assignment you will use: one-dimensional arrays; strings and various...
answer in JAVA language please In this assignment you will use: one-dimensional arrays; strings and various string-handling methods; file input and output; console input and output; loops; and conditional program statements. Instruction You are asked to write a program that translates a Morse code message into English language. The program will ask the user to enter filenames for two input files, one for the code translation table data and the other for the coded message data, as well as an...
Your task is to modify the program from the Java Arrays programming assignment to use text...
Your task is to modify the program from the Java Arrays programming assignment to use text files for input and output. I suggest you save acopy of the original before modifying the software. Your modified program should: contain a for loop to read the five test score into the array from a text data file. You will need to create and save a data file for the program to use. It should have one test score on each line of...
Java program problem 1 Come up with an idea for parallel arrays Create the arrays to...
Java program problem 1 Come up with an idea for parallel arrays Create the arrays to hold 5 items in each In the main(), load the arrays with data Then output the entire contents of the arrays Create a method called find1() and pass the 2 arrays to that method. problem 2 In the find1() method, ask the user to enter a value to search for Write logic to search the first array and then output the related data from...
Project 1 - Arrays - Grader The purpose of this assignment is to practice dealing with...
Project 1 - Arrays - Grader The purpose of this assignment is to practice dealing with arrays and array parameters. Arrays are neither classes nor objects. As a result, they have their own way of being passed as a parameter and they also do not support the dot operator ( .), so you cannot determine how full they are. This results in some pain and suffering when coding with arrays. It is this awareness that I am trying to get...
This is a JAVA assignment and i dont have the SinglyLinkedList class   Exercise 1 In this...
This is a JAVA assignment and i dont have the SinglyLinkedList class   Exercise 1 In this exercise, you will add a method swapNodes to SinglyLinkedList class. This method should swap two nodes node1 and node2 (and not just their contents) given references only to node1 and node2. The new method should check if node1 and node2 are the same node, etc. Write the main method to test the swapNodes method. Hint: You may need to traverse the list. Exercise 2...
Program Assignment 1 C++ please Instructions This assignment will require the use of three arrays, which...
Program Assignment 1 C++ please Instructions This assignment will require the use of three arrays, which will be used in parallel. Create a program that keeps track of the sales of BBQ sauces for a company. The company makes several different types of sauces, Original, Sticky Sweet, Spicy, Sweet Heat, Hickory Bourbon and Smokey Mesquite. One array will contain the names of the different BBQ sauces. This array will be initialized from a text file with the 6 different names....
*JAVA* For this assignment you have been given two classes, a Main.java and a Coin.java. The...
*JAVA* For this assignment you have been given two classes, a Main.java and a Coin.java. The coin class represents a coin. Any object made from it will have a 1) name, 2) weight and 3) value. As of now, the instance variables in Coin.java are all public, and the main function is calling these variables directly for the one coin made in it. Your goal is to enforce information hiding principles in this project. Take Coin.java, make all instance variables...
Homework Arrays and Tables In this assignment you are to create an algorithm, flowchart, and pseudocode...
Homework Arrays and Tables In this assignment you are to create an algorithm, flowchart, and pseudocode for a solution of the following problem. This solution will include the use of arrays needed to complete all parts of the logic. You have requested to develop a program that will record and process the rainfall totals of a 12 month period. You would use an array to store each months total. Once all 12 months amounts are entered then your solution need...
java by using Scite Objectives: 1. Create one-dimensional arrays and two-dimensional arrays to solve problems 2....
java by using Scite Objectives: 1. Create one-dimensional arrays and two-dimensional arrays to solve problems 2. Pass arrays to method and return an array from a method Problem 2: Find the largest value of each row of a 2D array             (filename: FindLargestValues.java) Write a method with the following header to return an array of integer values which are the largest values from each row of a 2D array of integer values public static int[] largestValues(int[][] num) For example, if...
java by using Scite Objectives: 1. Create one-dimensional arrays and two-dimensional arrays to solve problems 2....
java by using Scite Objectives: 1. Create one-dimensional arrays and two-dimensional arrays to solve problems 2. Pass arrays to method and return an array from a method Problem 1: Find the average of an array of numbers (filename: FindAverage.java) Write two overloaded methods with the following headers to find the average of an array of integer values and an array of double values: public static double average(int[] num) public static double average(double[] num) In the main method, first create an...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT