I need help with this assignment. It's due Tuesday at 8 AM. Please follow the instructions thoroughly as to not use any advanced material we may not have gone over in class. The instructions let you know what all should be used. Thanks!
Please find the required program along with the comments and output:
import java.lang.reflect.Array; import java.util.Arrays; import java.util.Scanner; class TopBuyers { public static void main(String[] args) { String[] buyers; double[] sales; Scanner console = new Scanner(System.in); System.out.println("How many buyers do you want to enter? "); //read the no:of buyers int noOfBuyers = console.nextInt(); buyers = fillBuyersArray(console,noOfBuyers); //read all buyers name System.out.println("\n"); sales = fillSalesArray(console,noOfBuyers); //read all buyers sales System.out.println("\n"); System.out.println("How many top buyers should display? "); int top = console.nextInt(); //read top buyers to dsiplay String[] topBuyers = getTopBuyers(buyers,sales,top); //find top buyers System.out.println("\n"); printTopBuyers(topBuyers,sales); //print all the sales and top buyers } private static String[] fillBuyersArray(Scanner console, int buyers) { String[] buyersArray = new String[buyers]; for(int i=0; i<buyers; i++){ System.out.println("Enter the buyer "+(i+1)+" last name: "); String name = console.next(); buyersArray[i] = name; } return buyersArray; } private static double[] fillSalesArray(Scanner console, int buyers) { double[] salesArray = new double[buyers]; for(int i=0; i<buyers; i++){ System.out.println("Enter the buyer "+(i+1)+" sales: "); double sale = console.nextDouble(); salesArray[i] = sale; } return salesArray; } private static String[] getTopBuyers(String[] buyers, double[] sales, int top) { String[] topBuyers = new String[top]; double[] tempSales = Arrays.copyOf(sales,sales.length); for(int i=0; i < top; i++){ int topIndex = maxIndex(tempSales); topBuyers[i] = buyers[topIndex]; tempSales[topIndex] = 0.0; } return topBuyers; } private static int maxIndex(double[] sales){ double max = sales[0]; int index = 0; for(int i=0; i < sales.length; i++){ if(max < sales[i]){ max = sales[i]; index = i; } } return index; } private static void printTopBuyers(String[] topBuyers, double[] sales) { System.out.println("The list of sales:"); for(double sale : sales){ System.out.print(sale+" "); } System.out.println("\nThe top buyers in order are:"); for(String buyer : topBuyers){ System.out.println(buyer); } } }
--------------------------------------------------------------------------------
OUTPUT:
I need help with this assignment. It's due Tuesday at 8 AM. Please follow the instructions thorou...
JavaScript - Sorting Assignment (arrays, classes, functions and higher order functions) Note: Please make sure to use the ES6 keyword style => instead of the older function. For variables please use keyword let, not var, class and within the constructor, not function. Instructions: - Create a new JavaScript file and name it “Objects.js” - Create a class and make sure to use “names” as the identifier. - Create a constructor with the following elements: first ( value passed will be...
Please follow the instructions carefully. Thank you! For the second activity, I outputted the superhero class below. SUPERHERO CLASS public class Superhero{ private String alias; private String superpower; private int health; public Superhero(){ alias= "unkown"; superpower= "unknown"; health= 50; //Realized I did not use default constructor while going through instructions of lab } public Superhero(String alias1, String superpower1,int health1 ){ alias=alias1; superpower=superpower1; if(health1>=0 && health1<=50) health= health1; else if(health1<0||health1>50) health=25; } public void setalias(String alias1){ alias=alias1; } public void setsuperpower(String...
CT143 : Intro to C++ Lab 15: Array Practice Instructions Complete each of the C++ activities described below in a single source file Label each activity with its own heading using comments. Activities: 1) Favorite numbers a. Declare and initialize an array of 10 integers as a single statement using a name of your choice. b. Output the result of adding the 1st and 5th members of the array. C. Subtract the 4h member from 3 times the 10th member...
Assignment 11 – Exceptions, Text Input/Output - Random Numbers Revised 9/2019 Chapter 12 discusses Exception Handling and Input/Output. Using try/catch/finally statement to handle exceptions, or declare/throw an exception as needed, create the following program: Create an array of 25 random numbers between 0 & 250 formatted to a field width of 10 & 4 decimal places (%10.4f). Use the formula Math.random() * 250. Display the array of random numbers on the console and also write to a file. Prompt the...
Your assignment is to write a grade book for a teacher. The teacher has a text file, which includes student's names, and students test grades. There are four test scores for each student. Here is an example of such a file: Count: 5 Sally 78.0 84.0 79.0 86.0 Rachel 68.0 76.0 87.0 76.0 Melba 87.0 78.0 98.0 88.0 Grace 76.0 67.0 89.0 0.0 Lisa 68.0 76.0 65.0 87.0 The first line of the file will indicate the number of students...
I need a C++ program like this please! and please follow all instructions! Thanks so much! A menu-driven program with 3 choices: Names Rearranger, Number Validator, or Exit Menu Option 1: Name Rearranger: 1. Input ONE STRING from the user containing first name, middle name, and last name. ie, "John Allen Smith". USE THE GETLINE function. (Not cin) 2. Loop through the string and validate for a-z or A-Z or . If the name has any other characters, then ask...
Can someone please help, third time I'm asking. I need a basic javascript with no push or splice command. Please don't post a picture of the code,because my vision is poor and I won't be able to see it. Also, I need breakdown of what's in HTMLand what' s in javascript. All requirements are below. Thanks for your help. This is a 2 part assignment, but both parts can be completed in one program. Also, please follow ALL Required Programming...
COSC 1437 C++ Project Assignment 2 Poll Summary Utilize a dynamic array of structure to summarize votes for a local election Specification: Write a program that keeps track the votes that each candidate received in a local election. The program should output each candidate’s name, the number of votes received, and the percentage of the total votes received by the candidate. Your program should also output the winner of the election. To solve this problem, you will use one dynamic...
Please need help, programming in C - Part A You will need to create a struct called Team that contains a string buffer for the team name. After you've defined 8 teams, you will place pointers to all 8 into an array called leaguel], defined the following way: Team leaguel8]. This must be an aray of pointers to teams, not an array of Teams Write a function called game) that takes pointers to two teams, then randomly and numerically determines...
please answer correctly and follow the code structure given [JavaFX/ Exception handing and text I/O] 1. Write a program for the following. NOTE that some of these steps are not dependent on each other. Using methods is mandatory. Make sure to use methods where it makes sense. a. Ask the user for a series of integers entered from the keyboard. Use a sentinel value such as 999 to end the input process. If the entered values are not integers, throw...