Question

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!

Use only what you have learned in Chapters 1 - 7. Use of advanced material, material not in the text, or project does not fPART 1: Name the class file TopBuyers.java In the main) method, declare and initialize the console and prompt the user for thPART 5 1. Write a method getTopBuyers that takes the buyers array, the sales array, and and the mumber of top users to displa

Use only what you have learned in Chapters 1 - 7. Use of "advanced" material, material not in the text, or project does not follow the instructions, will result in a GRADE OF 0% for the project. Write a java program that produces the following output using methods,_parameters, for loops, if/else, while loops,_doubles, return statements, Scanners,and Arrays "A business owner likes to keep track of her top buyers according to their sales so she may recognize them each month Write a program that will accept a given number of buyers with their sales and then output the number of top buyers requested" Sample Output: jGRASP exec: java TopBuyers How many buyers do you want to enter? 5 Enter the 1st buyer's last name: Smith Enter the 2st buyer's last name: Jones Enter the 3st buyer's last name: Howard Enter the 4st buyer's last name: Anderson Enter the 5st buyer's last name: Meyers Enter the 1st buyer's sales: 48.52 Enter the 2st buyer's sales: 78.45 Enter the 3st buyer's sales: 100.00 Enter the 4st buyer's sales: 25.98 Enter the 5st buyer's sales: 88.35 How many top buyers should display? 3 The list of sales: 48.52 78.45 100.00 25.98 88.35 The top buyers in order are: Howard Meyers Jones GRASP: operation complete.
PART 1: Name the class file TopBuyers.java In the main) method, declare and initialize the console and prompt the user for the number of buyers (see sample output). Store this integer in a variables o We will comple the main method in Part XXX PART 2: 1. Create a new method fillBuyerArray that takes the console and the number of buyers as parameters and returns an array of type String contann the last names of the buyers 2. Create a array for the buyer's names. The size of the array should use your parameter value do not hardcode! 3. Use a for loop to store the entries from the console into the array (see p. 454). This is similar to your Grades code except you are not summing values - just storing in the array. 4. return the array of buyers names. PART 3: 1. Create a new method fillSalesArray that takes the console and the number of buyers as parameters and returns an array of type double containing the sales of the buyers. 2. Create an array for the buyers sales. The size of the array should use your parameter value - do not hardcode! 3. Use a for loop to store the entries from the console into the array (see p. 454). This is similar to Part 2 4. return the array of buyer's sales. PART 4 . Back in the main method, call the fillBuyerArray and fillsalesArray methods and store the returning arrays in arrays declared in main (just like we do int value -getValue (console), etc, just with an array.) 2. Prompt the user for how many top buyer's they would like to display (see Sample Output) .Store the number to display in an int variable.
PART 5 1. Write a method getTopBuyers that takes the buyers array, the sales array, and and the mumber of top users to display as parameters and returns an array of type String containing only the top buyers 2. Create an array to hold the top buyers. The size of the array should use your number parameter - do not hardcode. 3. Create a copy of the sales array called tempSales. This will prevent us from deleting items in the original array. Please see: https://www.tutorialspoint.com/java/util/arrays_copyof int.htm for help with this. 4. Inside a for loop: . call the maxIndex method (a "Thelper" method see Part 6) to find the index of the buyer(s) with the highest sales 2. store this buyer in your array of top buyers. 3. So that we don't keep receiving the same index from out helper method, we must "zero out" the value at each index received in our tempSales array. This is why we made a copy of the array. You can do this by: tempSales [topIndex]-0.0: This will overwrite the data and you will be able to get the "next" top buyer. 5. return the top buyer array PART 6 1. Create a new method maxIndex that takes an array of type double as a parameter (our tempSales) and returns an int containing the index of the top buyer. 2. Use a for loop to compare each element to the next element in the array and store the index of the location of the largest value. See: http: //java.candidjava.com/tutorial/find-the-index-of-the-largest-number-in-an-array.htm for help with this. 3. return this max index. PART 7: . Write method printTopBuyers that takes the buyer's array and the sales array as parameters. It has not return value. Output the list of all of the sales and then the names of the top buyers. (See Sample Output) PART 8: 1. Call the getTopBuyers method passing the sales, buyers and number of top buyers to display and store the returning array in an array variable (as you did for buyers and sales). 2. Call the printBuyers method passing the array of top buyers and the sales.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

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:

How many buyers do you want to enter? 5 Enter the buyer 1 last name: Smith Enter the buyer 2 last name: Jones Enter the buyer

How many top buyers should display? 3 The list of sales: 48.52 78.45 100.0 25.98 88.35 The top buyers in order are: Howard Me

Add a comment
Know the answer?
Add Answer to:
I need help with this assignment. It's due Tuesday at 8 AM. Please follow the instructions thorou...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • JavaScript - Sorting Assignment (arrays, classes, functions and higher order functions) Note: Please make sure to...

    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...

    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...

    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...

    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 includ...

    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!...

    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...

    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...

    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...

    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....

    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...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT