Question

In: Computer Science

Create a program that determines the name of the person with the highest or lowest number...

Create a program that determines the name of the person with the highest or lowest number of votes. The data will be in two arrays. The first array is of type String and has the following names in it: Mike Muldune Justin Meiber Clark Kent Ana Karina The second array is of type integer and has the following numbers in it: 2324, 2425, 3344 and 2526. Ask the user to enter a 1 for highest and 2 for lowest. If the user enters a 1, print the name of the person with the highest number of votes and the number of votes received. It the user enters a 2, print the name of the person with the lowest number of votes and the number of votes received.

Solutions

Expert Solution

import java.util.Scanner;

public class HighestPerson {
   public static void main(String[] args) {
       String names[]= {"Mike Muldune","JustinMelber","Clark Kent","Ana Karina"};
       int votes[]= {2324,2425,3344,2526};
       Scanner sc = new Scanner(System.in);
       System.out.println("Press 1 for highest votes 0 for lowest votes");
       int ch=sc.nextInt();
       if(ch==1) {
           int index=getHighest(votes);
           System.out.println(names[index]+" got highest votes "+votes[index]);
       }
       else {
           int index=getLowest(votes);
           System.out.println(names[index]+" got lowest votes "+votes[index]);
       }
   }

   // returns the index of highest votes in votes array
   private static int getHighest(int[] arr) {
       int m=0;
       for(int i=1;i<arr.length;i++) {  
           if(arr[m]<arr[i])
               m=i;
       }
       return m;
   }
   // returns the index of lowest votes in votes array
   private static int getLowest(int[] arr) {
       int m=0;
       for(int i=1;i<arr.length;i++) {  
           if(arr[m]>arr[i])
               m=i;
       }
       return m;
   }
}

Note : Please comment below if you have concerns. I am here to help you

If you like my answer please rate and help me it is very Imp for me


Related Solutions

IN JAVA Write a program that uses a two-dimensional array to store the highest and lowest...
IN JAVA Write a program that uses a two-dimensional array to store the highest and lowest temperatures for each month of the year. Prompt the user for 12 months of highest and lowest.   Write two methods : one to calculate and return the average high and one to calculate and return the average low of the year. Your program should output all the values in the array and then output the average high and the average low. im trying to...
Write a program that uses a two-dimensional array to store the highest and lowest temperatures for...
Write a program that uses a two-dimensional array to store the highest and lowest temperatures for each month of the year. Prompt the user for 12 months of highest and lowest.   Write two methods : one to calculate and return the average high and one to calculate and return the average low of the year. These methods MUST be your original code.   Your program should output all the values in the array and then output the average high and the...
Write a program that uses a two dimensional array to store the highest and lowest temperatures...
Write a program that uses a two dimensional array to store the highest and lowest temperatures for each month of the calendar year. The temperatures will be entered at the keyboard. This program must output the average high, average low, and highest and lowest temperatures of the year. The results will be printed on the console. The program must include the following methods: A method named inputTempForMonth whose purpose is to input a high and a low temperature for a...
The Anxiety Correlation Coefficient is a number that determines the level of anxiety that a person...
The Anxiety Correlation Coefficient is a number that determines the level of anxiety that a person has toward stressful situations. Scores in the range: (5,7.5) are considered normal and do not impede performance on the job among Federation members. Scores below this range indicate possible pathological tendencies, and scores above this range indicate excessive anxiety which may impede job performance and over-all mental health. The random sample of 10 crew members were given the Anxiety Correlation Coefficient test before their...
4. Write a program that reads all numbers from a file and determines the highest and...
4. Write a program that reads all numbers from a file and determines the highest and lowest numbers. You must NOT use arrays to solve this problem! Write functions where appropriate. Programming language should be C
Exercise 7: Name that Shape Write a program that determines the name of a shape from...
Exercise 7: Name that Shape Write a program that determines the name of a shape from its number of sides. Read the number of sides from the user and then report the appropriate name as part of a meaningful message. Your program should support shapes with anywhere from 3 up to (and including) 10 sides. If a number of sides outside of this range is entered then your program should display an appropriate error message. language use : python
Using JAVA Write a program that uses a 2-D array to store the highest and lowest...
Using JAVA Write a program that uses a 2-D array to store the highest and lowest temperatures for each month of the year. The program should output the average high, average low, and highest and lowest temperatures of the year. Your program must consist of the following methods with their appropriate parameters: a.) getData: This method reads and stores the data in the 2-D array. b.) averageHigh: This method calculates and returns the average high temperature of the year. c.)...
Program 5A: Determine which student has the highest grade Write a Java program that determines which...
Program 5A: Determine which student has the highest grade Write a Java program that determines which student has the highest grade. You will ask the user to enter the number of students. Then you will ask for each student and their grade. You will output the name and grade of the student with the highest grade. You will NOT use an array for this assignment. Call your class Program5A, so your filename will be Program5A.java. It is essential for grading...
1) Create a "Can I be President?" program. The program determines if the user meets the...
1) Create a "Can I be President?" program. The program determines if the user meets the minimum requirements for becoming the President of the United States. Use user input. The rules for being president of the U.S. are: Older than 35 Resident of US for 14 Years Natural born citizen Print True if the person could be president and False if they can't be president. 2) Alter one line of that program to be a "I can't be President?" game....
IN C++ PLEASE!!! Design and implement a program (name it Coins) that determines the values of...
IN C++ PLEASE!!! Design and implement a program (name it Coins) that determines the values of coins in a jar. The program prints out the total dollars and cents in the jar. The program prompts the user to enter the number of coins (quarters, dimes, nickels, and pennies). Print out the number of coins entered for each coin type on separate lines followed by the total amount of money in the jar as dollars and cents as shown below.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT