Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need your help with the second question in Java CS1113 Java and Object Oriente

ID: 3681125 • Letter: I

Question

I need your help with the second question in Java


CS1113 Java and Object Oriented Programming Homework due 3-21-16 7.2 Vote Tally Ten candidates, designated 0 to 9, are competing in a preliminary election for mayor. Write a program that counts the votes for each candidate. The input to your program is a list of numbers in the range 0- that a value of i signifies a vote for candidate i. Terminate the data with a flag. Use an array to keep a tally of the votes. Do not use 10 different variables. Discard all invalid votes. Output from your program should be 10 pairs (one pair per line) of the form: (candidate number, umber of votes) Typical input might be: 1133334126790231454478902-999 9 such 7.7 Top Two Largest (Modified) A matrix is a two dimensional array of 6 oolumns, with random numbers between 0 and 1. Store the random numbers of the matrix using a two numbers with n roms and m columns. Fill a dx6 matrix, 4 rows and dimensional array. Do not store the values using individual variables. Display the elements of the matrix. Next, find and display the two largest numbers in the matrix.

Explanation / Answer

7.7)

import java.util.Scanner;

class Matrix1

{

   public static void main(String args[])

   {

int I,j;

int first[][] = new int[4][6];

Random randomno = new Random();

for ( i = 0 ; i < 4 ; i++ )

         for ( j = 0 ; j < 6 ; j++ )

// generates float value between 0.0 and 1.0

            first[i][j] = randomno.nextFloat();

System.out.println("Displaying matrix");

for ( i = 0 ; i < 4 ; i++ )

{

         for ( j = 0 ; j < 6 ; j++ )

{

System.out.print(first[i][j]+" ");

         System.out.println();

}

}

//finding maximum two numbers in matrix

float maximumone = matrix[0][0];

float maximumtwo = matrix[0][0];

for ( i = 0 ; i < 4 ; i++ )

{

         for ( j = 0 ; j < 6 ; j++ )

{

if(maxOne < first[i][n]){

                maxTwo = maxOne;

                maxOne =first[i][n];

            } else if(maxTwo < first[i][n]){

                maxTwo = first[i][n];

}

}

}

System.out.println("First Max Number: "+maxOne);

   System.out.println("Second Max Number: "+maxTwo);

  }//main

}//class

7.2)

import java.util.Scanner;

class Vote

{

   public static void main(String args[])

   {

static final int UN = 0;

int c[10],v[10],n;

//initializing array with zero

for (int i = 0; i < 10; i++) {

    arr[i] = UN;

}

Scanner in = new Scanner(System.in);

System.out.println("Enter values first candidate number then corresponding votes ");

//terminating filag is -999

while(n== -999)

{

int n= in.nextInt();

int v[n]=v[n]+in.nextInt();

}

for(i=0;i<10;i++)

System.out.println(i+" "+v[i]);

}//main

}//class