Question

In: Computer Science

pseudocode please! Assignment 5B: Moneyball: Part 2. Similar to the previous assignment, you’re going to read...

pseudocode please!

Assignment 5B: Moneyball: Part 2. Similar to the previous assignment, you’re going to read in the number of years the player played and the starting year of that player – followed by the statistics for those years. This time, however, you’re going to print out the years from worst to best in sorted order. Hint: this will require a second array to store years. If you can sort one array, can you sort both?

Sample Output #1: Enter the number of years: 5 Enter the starting year: 2003 Enter stat for year 2003: 5 Enter stat for year 2004: 4 Enter stat for year 2005: 7 Enter stat for year 2006: 1 Enter stat for year 2007: 3 2006|2007|2004|2003|2005| Sample Output #2: Enter the number of years: 6 Enter the starting year: 1879 Enter stat for year 1879: 70 Enter stat for year 1880: 89 Enter stat for year 1881: 111 Enter stat for year 1882: 65 Enter stat for year 1883: 105 Enter stat for year 1884: 98 1882|1879|1880|1884|1883|1881|

Solutions

Expert Solution

Pseudocode and sample source code:

Output:

Code in text format (See above images of code for indentation):

/****************PseudoCode************************ */

/*

import libraries

class definition begin

{

    Main

    {

        Scanner object initalize to read data from input

        initialize or declare a variables start,n etc

        prompt the user to enter number of years

        read n

        prompt the user to enter start year

        read start

        declare arrays for stats[n] and years[n]

        for(i=0 to n-1)do

        {

            read stat for year

            add data to stat array

            add start to years array

            increment start++

        }end for

        for(i=0 to n-1)do

        {

            for(j=i+1 to n-1)do

            {

                compare

                if(stat[i]>stat[j])

                {

                    swap stat[i] and stat[j]

                    swap years[i] and years[j]

                }

            }end inner for

        }end outer for

        for(i=0 to n-1)do

            print years[i]+"|"

    }end main

}end class

*****************************************************/


import java.util.*;

/*class definition*/

public class Assignment5B

{

    /*main method*/

    public static void main(String[] args)

    {

        /*Scanner object to read data from the user*/

        Scanner scnr=new Scanner(System.in);

        int n,start;

        /*read number of years from the user*/

        System.out.print("Enter the number of years: ");

        n=scnr.nextInt();

        /*read starting from the user*/

        System.out.print("Enter starting year: ");

        start=scnr.nextInt();

        /*arrays declarations*/

        int[] stat=new int[n];

        int[] years=new int[n];

        for(int i=0;i<n;i++)

        {

            /*enter stats for year by year*/

            System.out.print("Enter stat for year "+start+": ");

            stat[i]=scnr.nextInt();

            /*add year to years array*/

            years[i]=start;

            start++;

        }

        /*using nested loops sort the arrays*/

        for(int i=0;i<n;i++)

        {

            for(int j=i+1;j<n;j++)

            {

                /*compare stats*/

                if(stat[i]>stat[j])

                {

                    /*swap years*/

                    int temp=years[i];

                    years[i]=years[j];

                    years[j]=temp;

                    /*swap stats for correct comparsion*/

                    temp=stat[i];

                    stat[i]=stat[j];

                    stat[j]=temp;

                }

            }

        }

        /*print years*/

        for(int i=0;i<n;i++)

            System.out.print(years[i]+"|");

    }

}


Related Solutions

I need this in pseudocode: Similar to the previous assignment, you’re going to read in the...
I need this in pseudocode: Similar to the previous assignment, you’re going to read in the number of years the player played and the starting year of that player – followed by the statistics for those years. This time, however, you’re going to print out the years from worst to best in sorted order. Hint: this will require a second array to store years. If you can sort one array, can you sort both? Sample Output #1: Enter the number...
Buh-RING IT! For this assignment, you’re going to simulate a text-based Role-Playing Game (RPG). Design (pseudocode)...
Buh-RING IT! For this assignment, you’re going to simulate a text-based Role-Playing Game (RPG). Design (pseudocode) and implement (source) for a program that reads in 1) the hero’s Hit Points (HP – or health), 2) the maximum damage the hero does per attack, 3) the monster’s HP and 4) the maximum monster’s damage per attack.   When the player attacks, it will pick a random number between 0 and up to the maximum damage the player does, and then subtract that...
MBA 5010 Week 4 Integrative Assignment This week, you’re going to build on the knowledge you...
MBA 5010 Week 4 Integrative Assignment This week, you’re going to build on the knowledge you gained. Your assignment is to deconstruct the economics underlying Airbnb. Specifically, I want you to answer the following questions: • Does Airbnb capture a sufficient amount of any value generated to remain a viable business? The purpose of this question is to provide you an opportunity to demonstrate your understanding of the economics of value creation. So, emphasize this aspect of your answer. Try...
C# PLEASE Lab7B: For this lab, you’re going to write a program that prompts the user...
C# PLEASE Lab7B: For this lab, you’re going to write a program that prompts the user for the number of GPAs to enter. The program should then prompt the user to enter the specified number of GPAs. Finally, the program should print out the graduation standing of the students based on their GPAs. Your program should behave like the sample output below. Sample #1: Enter the number of GPAs: 5 GPA #0: 3.97 GPA #1: 3.5 GPA #2: 3.499 GPA...
Pseudocode please: Assignment6B: For this assignment, you should ask the user for a day and a...
Pseudocode please: Assignment6B: For this assignment, you should ask the user for a day and a month, then determine what season it is based on that input. Write a method that takes in a month and day and returns which season it is (“Spring”, “Summer”, “Fall”, “Winter”). Your main method should be the only one that includes a print statement. Note the first days of each season: • March 19th – Spring • June 20st – Summer • September 22nd...
PLEASE READ ALL OF THESE INSTRUCTIONS BEFORE BEGINNING THIS ASSIGNMENT. For this assignment, you need to...
PLEASE READ ALL OF THESE INSTRUCTIONS BEFORE BEGINNING THIS ASSIGNMENT. For this assignment, you need to analyze the information below from BOTH the management AND the employee perspective. This information pertains to a labor union in a simulated/made up/not real firm in Glen Ellyn. The first part of your information relates to Management – the second part relates to the Labor Union employees. I have provided you with information from the last union negotiations at the plant in 2016. It...
Hello. If you’re going to hand write the solution, please do so legibly. Thank you. Determine...
Hello. If you’re going to hand write the solution, please do so legibly. Thank you. Determine the amount of sales units that would be necessary under break-even sales under present and proposed conditions. Johnson & Sons Company, operating at full capacity, sold 101,250 units at a price of $129 per unit during the current year. Its income statement for the current year is as follows: Sales $13,061,250 Cost of goods sold 6,450,000 Gross profit $6,611,250 Expenses: Selling expenses $3,225,000 Administrative...
Assignment #2: Individual Macronutrient Requirements and Diet Report Required to Submit: Previous assignment #1 and …....
Assignment #2: Individual Macronutrient Requirements and Diet Report Required to Submit: Previous assignment #1 and …. Your Individual Macronutrient Requirements for: Total kcals, Protein, Fat, Carbohydrate & Fiber Completed Diet Report Complete the Report Questions Completing the Diet Report Once you have recorded your 3-day diet, . You can also access the website in the Diet Project Resources module in Canvas. Instructions on how to generate the Cronometer nutrition analysis report can be found in the Diet Project Resources module....
Read Anderson, Narus, & van Rossum, (2006). In a 2-3 page assignment response, please include a...
Read Anderson, Narus, & van Rossum, (2006). In a 2-3 page assignment response, please include a high-level and general review of the concepts and content in the article.
Week 10 Assignment - Fiscal Planning and Management Presentation Read and use this for this part...
Week 10 Assignment - Fiscal Planning and Management Presentation Read and use this for this part of the assignment and do as directed please. You are a regional healthcare administrator for a long-term care organization. You have been asked to provide training to a new group of healthcare administrators, who just completed their degree. They have no work experience in healthcare administration or financial management. For this assignment, you are to: 1. Develop a presentation using PowerPoint slides that explain...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT