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...
Java - Text File to Arrays and output ------------------------------------------------------------------------------ I need to have a java program...
Java - Text File to Arrays and output ------------------------------------------------------------------------------ I need to have a java program read an "input.txt" file (like below) and store the information in an respective arrays. This input.txt file will look like below and will be stored in the same directory as the java file. The top line of the text represents the number of people in the group for example. the lines below it each represent the respective persons preferences in regards to the other...
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...
Assignment 1: JAVA Classes, Objects, and Constructors The goal of this assignment is to get you...
Assignment 1: JAVA Classes, Objects, and Constructors The goal of this assignment is to get you familiar with some of the most used JAVA syntax, as well as constructors objects, objects calling other objects, class and instance attributes and methods. You will create a small program consisting of Musician and Song classes, then you will have Musicians perform the Songs. Included is a file “Assignment1Tester.java”. Once you have done the assignment and followed all instructions, you should be able to...
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...
Suppose you have two sorted arrays of n integers: X0[1..n] and X1[1..n]. Devise and analyze an...
Suppose you have two sorted arrays of n integers: X0[1..n] and X1[1..n]. Devise and analyze an efficient algorithm for finding the median of all numbers in arrays X0 and X1. Now, suppose you have not two, but three such arrays, each with n elements. Devise and analyze an efficient algorithm for finding the median. Do the same for n arrays, each with n elements.
Read a text file into arrays and output - Java Program ------------------------------------------------------------------------------ I need to have...
Read a text file into arrays and output - Java Program ------------------------------------------------------------------------------ I need to have a java program read an "input.txt" file (like below) and store the information in an respective arrays. This input.txt file will look like below and will be stored in the same directory as the java file. The top line of the text represents the number of people in the group for example. the lines below it each represent the respective persons preferences in regards...
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....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT