Question

In: Computer Science

Java program. The Spacely Sprocket company has expanded operations and is now producing 50 different kinds...

Java program. The Spacely Sprocket company has expanded operations and is now producing 50 different kinds of sprockets. The different sprockets are numbered 1 though 50. During the month of November, orders have been taken for the different sprockets. The following input file contains records where each record contains a sprocket number (1-50) followed by the quantity ordered: November Orders.txt (this will be at the bottom)

Using the below input file of orders, rewrite the Spacely Sprocket program to produce a summary report for all 50 sprockets produced. Rather than using 50 separate accumulator variables, you must use a single array to represent the 50 different accumulators. Use the array and loops in your program to summarize the orders and output the report. Don't forget to initialize each of the array locations to 0 (because they are accumulators). For full credit, be sure to display the report in a Scrolling Pane in a Window.

November_Orders.txt (below)

38       53 
3        17 
29       69 
42       2 
30       88 
31       76 
6        84 
33       30 
42       38 
37       96 
17       67 
37       32 
23       88 
4        63 
10       93 
33       47 
17       59 
39       48 
34       44 
13       49 
50       84 
13       59 
19       100 
20       91 
43       70 
41       25 
11       85 
47       100 
23       70 
34       72 
25       37 
26       50 
39       63 
14       3 
45       63 
8        85 
27       3 
25       89 
6        20 
40       70 
16       99 
28       57 
21       21 
41       6 
38       21 
26       12 
7        52 
35       13 
47       65 
34       36 
38       60 
9        92 
18       6 
13       46 
32       44 
14       6 
16       19 
11       12 
45       58 
28       42 
10       64 
10       61 
17       4 
5        47 
39       53 
34       25 
26       87 
8        49 
14       46 
50       96 
4        42 
31       4 
20       46 
49       6 
5        73 
26       39 
1        88 
47       48 
6        48 
23       65 
22       45 
29       97 
47       48 
18       94 
22       95 
8        99 
26       75 
13       85 
25       21 
28       42 
25       39 
47       91 
48       36 
21       25 
4        6 
19       88 
46       60 
22       83 
31       62 
38       18 
4        92 
25       45 
29       28 
5        59 
2        38 
50       21 
15       42 
46       15 
37       13 
49       57 
24       73 
37       90 
34       13 
30       91 
9        44 
34       84 
27       21 
48       8 
50       84 
15       26 
16       9 
38       86 
28       29 
37       30 
36       30 
47       51 
30       41 
3        54 
36       29 
12       11 
8        18 
33       69 
35       10 
34       36 
37       11 
27       98 
6        39 
5        82 
22       84 
10       63 
42       65 
14       95 
15       59 
24       57 
42       94 
25       44 
35       50 
26       30 
21       57 
11       53 
4        80 
18       48 
28       35 
26       48 
33       20 
22       76 
43       48 
27       32 
47       4 
34       88 
1        21 
27       46 
42       9 
35       100 
19       80 
3        93 
8        5 
45       85 
14       39 
37       33 
20       8 
48       24 
34       78 
43       56 
18       92 
11       76 
18       44 
5        15 
43       51 
50       100 
8        94 
23       64 
32       8 
40       54 
36       81 
32       31 
11       17 
37       35 
7        61 
26       31 
15       2 
2        59 
43       37 
5        86 
48       30 
14       91 
29       7 
16       24 
36       14 
15       56 
42       67 
35       50 
20       93 
40       14 
45       67 
23       37 
48       31 
19       67 
43       59 
33       62 
6        30 
31       31 
9        53 
29       94 
17       62 
38       1 
46       77 
25       1 
23       52 
45       74 
29       28 
11       43 
43       73 
31       32 
20       26 
13       64 
15       30 
35       76 
4        36 
34       88 
31       50 
15       78 
36       7 
28       9 
45       3 
28       92 
17       40 
3        1 
47       20 
39       27 
2        99 
13       7 
43       83 
22       93 
2        8 
14       76 
30       99 
33       59 
43       17 
21       56 
15       98 
12       86 
18       10 
16       67 
41       96 
47       26 
41       7 
25       6 
6        31 
36       4 
38       70 
18       62 
10       47 
22       19 
18       16 
49       45 
25       100 
42       24 
49       15 
8        47 
24       6 
2        92 
27       93 
16       99 
19       35 
32       55 
21       95 
21       97 
20       61 
23       84 
33       72 
4        89 
13       87 
23       52 
35       89 
16       67 
6        14 
49       86 
12       80 
36       2 
49       40 
39       6 
27       82 
50       7 
41       80 
26       9 
30       36 
14       25 
43       65 
18       50 
39       38 
16       71 
5        52 
44       5 
46       66 
42       84 
37       56 
43       50 
48       30 
24       57 
14       84 
11       76 
42       9 
48       54 
18       24 
7        11 
40       78 
44       40 
25       43 
31       44 
29       45 
34       71 
33       69 
29       59 
14       37 
1        31 
45       78 
7        14 
27       13 
33       8 
31       6 
16       48 
34       96 
23       36 
25       57 
33       82 
24       47 
48       69 
36       77 
33       44 
12       26 
45       40 
10       17 
18       52 
8        5 
34       34 
2        4 
1        23 
38       40 
14       79 
18       89 
2        91 
28       14 
22       22 
6        46 
16       55 
36       99 
50       57 
34       39 
49       92 
29       8 
40       14 
12       83 
46       2 
19       32 
16       35 
24       66 
35       77 
13       87 
13       85 
32       2 
41       96 
31       7 
29       73 
21       36 
9        6 
27       63 
23       1 
5        27 
27       36 
23       5 
41       43 
33       69 
3        35 
24       30 
37       26 
17       34 
14       65 
17       54 
11       86 
9        46 
14       64 
9        18 
3        88 
1        15 
34       65 
20       65 
42       57 
42       92 
37       45 
44       74 
13       57 
19       31 
43       28 
9        22 
10       100 
25       64 
12       79 
49       27 
26       90 
25       13 
8        50 
21       81 
10       18 
40       18 
32       72 
14       82 
22       79 
13       44 
4        4 
15       21 
45       67 
9        86 
12       81 
43       89 
4        66 
44       1 
42       26 
41       99 
29       51 
17       25 
13       12 
24       49 
35       66 
9        69 
20       89 
32       65 
32       40 
4        78 
35       19 
25       98 
22       55 
19       17 
40       85 
41       76 
47       85 
28       12 
10       48 
13       18 
41       64 
35       54 
7        95 
16       71 
35       59 
49       62 
19       84 
3        31 
2        41 
19       33 
43       76 
17       46 
6        96 
27       53 
50       39 
30       24 
3        18 
31       42 
27       21 
10       87 
24       57 
44       34 
41       54 
49       50 
33       43 
46       48 
12       43 
16       8 
39       85 
2        79 
7        29 
8        64 
8        23 
10       21 
6        40 
32       40 
6        97 
21       8 
1        74 
5        36 
8        29 
26       13 
33       73 
4        36 
24       64 
36       76 
16       87 
5        92 
47       6 
25       18 
15       24 
28       14 
12       25 
31       77 
16       50 
4        44 
37       55 
11       80 
25       79 
50       21 
6        86 
22       17 
4        63 
49       37 
47       19 
2        100 
13       81 
41       46 
45       59 
39       8 
30       77 
50       89 
3        32 
38       70 
12       7 
26       33 
26       84 
41       18 
28       81 
4        49 
21       77 
36       16 
2        23 
35       59 
47       92 
40       56 
37       83 
10       47 
47       13 
12       72 
14       61 
11       7 
19       46 
6        10 
23       45 
43       64 
23       2 
50       54 
43       65 
38       4 
21       30 
30       9 
10       9 
23       90 
8        8 
41       70 
44       66 
20       56 
17       10 
16       49 
24       80 
38       4 
26       1 
13       27 
41       33 
44       42 
21       47 
39       46 
49       2 
16       43 
25       25 
37       82 
20       40 
31       12 
21       82 
22       41 
37       87 
4        92 
4        73 
21       79 
32       14 
27       41 
3        69 
34       37 
40       42 
37       64 
5        33 
32       38 
36       4 
35       87 
33       86 
8        96 
35       38 
19       99 
29       31 
49       26 
43       22 
24       4 
38       85 
26       55 
27       91 
47       53 
4        51 
4        78 
4        11 
45       61 
49       32 
31       9 
1        80 
43       11 
35       55 
50       11 
6        88 
19       15 
36       76 
47       16 
42       68 
29       81 
10       67 
14       71 
50       3 
20       93 
15       12 
30       61 
3        75 
9        23 
34       71 
32       90 
44       81 
49       21 
37       75 
31       46 
3        43 
1        49 
9        70 
11       64 
26       85 
43       65 
1        23 
37       47 
13       60 
19       62 
7        52 
37       44 
5        49 
22       26 
7        53 
17       76 
24       68 
3        68 
39       22 
43       53 
32       39 
26       37 
26       9 
10       33 
3        35 
10       26 
50       44 
36       11 
28       87 
40       21 
7        21 
7        52 
33       18 
39       68 
27       42 
32       85 
7        48 
10       44 
9        35 
26       32 
41       74 
27       58 
30       19 
41       48 
1        31 
43       33 
15       72 
40       78 
7        73 
30       27 
28       25 
18       72 
24       53 
47       98 
22       83 
34       9 
11       60 
12       37 
15       53 
18       14 
47       71 
10       1 
14       32 
27       86 
17       12 
36       30 
28       78 
7        48 
5        31 
24       38 
9        70 
20       7 
39       48 
2        99 
50       26 
28       83 
17       100 
28       74 
44       45 
2        22 
40       36 
37       49 
10       86 
34       34 
41       7 
18       82 
22       96 
41       6 
28       49 
40       79 
14       51 
14       74 
41       77 
15       39 
14       84 
29       64 
23       21 
24       51 
33       2 
42       38 
33       75 
50       24 
11       13 
13       94 
18       47 
6        84 
21       24 
15       14 
1        25 
13       74 
30       82 
29       66 
23       90 
7        31 
26       61 
20       79 
38       59 
9        41 
32       24 
20       77 
46       28 
47       84 
49       4 
33       25 
7        39 
41       15 
30       89 
12       18 
1        10 
35       64 
38       20 
3        32 
30       93 
37       34 
18       1 
24       6 
21       48 
30       32 
23       11 
15       28 
43       40 
11       66 
37       61 
29       42 
29       19 
24       91 
4        20 
38       100 
29       24 
22       88 
9        31 
4        28 
20       13 
7        9 
12       57 
2        84 
21       35 
5        20 
19       59 
31       8 
10       74 
3        26 
29       81 
10       13 
31       43 
12       65 
48       87 
38       69 
35       98 
34       92 
38       96 
32       48 
48       12 
16       7 
19       93 
40       71 
18       24 
17       84 
23       11 
29       52 
12       39 
32       11 
37       26 
16       33 
41       77 
16       51 
2        2 
14       61 
7        60 
50       76 
40       71 
40       42 
35       8 
50       42 
9        48 
35       92 
36       84 
25       99 
5        6 
1        33 
20       86 
48       64 
14       68 
7        51 
3        6 
43       90 
48       89 
21       78 
15       83 
3        17 
37       25 
7        75 
34       32 
39       90 
43       35 
13       47 
2        13 
34       65 
46       39 
18       75 
10       88 
37       53 
31       34 
42       93 
5        69 
39       76 
12       60 
44       13 
34       51 
45       20 
46       41 
19       91 
21       5 
10       10 
38       57 
12       79 
50       47 
23       61 
30       21 
2        7 
26       24 
38       66 
41       66 
3        4 
15       82 
5        14 
21       66 
35       27 
22       6 
31       75 
22       45 
23       75 
13       41 
43       79 
23       52 
30       7 
19       43 
17       69 
29       98 
46       82 
18       14 
6        24 
5        89 
48       90 
46       19 
19       73 
6        4 
48       61 
7        93 
4        37 
28       95 
27       40 
7        84 
9        87 
48       11 
12       87 
17       93 
8        92 
49       70 
44       43 
14       91 
30       96 
25       41 
34       48 
9        52 
7        61 
13       95 
34       28 
11       13 
8        50 
21       53 
36       69 
11       48 
2        39 
10       24 
47       52 
32       26 
25       90 
46       23 
39       25 
34       92 
38       19 
27       9 
50       9 
38       80 
27       41 
5        78 
41       1 
15       50 
32       75 
12       13 
26       95 
5        23 
7        43 
43       52 
1        39 
19       29 
22       98 
34       59 
18       6 
24       20 
12       59 
49       88 
39       34 
32       93 
29       40 
8        68 
13       86 
14       30 
25       10 
32       69 
25       12 
10       57 
35       7 
13       23 
27       13 
43       71 
28       98 
11       94 
47       65 
16       94 
11       66 
20       35 
31       31 
8        41 
32       52 
20       78 
19       67 
19       25 
34       98 
24       34 
21       17 
29       32 
47       56 
35       7 
9        37 
18       28 
37       64 
29       49 
36       5 
1        99 
12       8 
12       3 
11       95 
44       23 
50       19 
34       23 
19       34 
7        26

Solutions

Expert Solution

//Java code

import javax.swing.*;
import java.awt.*;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class Sprocket extends JFrame {
    public static void main(String[] args)
    {
        int[] sprockets = new int[50];
        try {
            Scanner scanFile = new Scanner(new File("November_Orders.txt"));
            while (scanFile.hasNextLine())
            {
                String line  = scanFile.nextLine();
                Scanner numbers = new Scanner(line);
                int sprocketNumber = numbers.nextInt();
                int quantity = numbers.nextInt();
                sprockets[sprocketNumber-1]+=quantity;
            }
            //Print stats
            String result ="";
            for (int i = 0; i <sprockets.length ; i++) {
                result+="Sprocket["+(i+1)+"]  quantity ordered = "+sprockets[i]+"\n";
            }
            //GUI
            JFrame frame = new JFrame("Spacely Sprocket company ");
            frame.setSize(500,500);
            frame.setLayout(new FlowLayout());
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

            JTextArea textArea = new JTextArea(20,25);
            textArea.setEditable(false);
            textArea.setText(result);
            JScrollPane scrollPane = new JScrollPane(textArea);
            scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);

            frame.getContentPane().add(scrollPane);
            frame.setVisible(true);
        }
        catch (FileNotFoundException ex)
        {
            System.err.println("File not found...");
        }
    }
}

//=======================================//

//File

//Output

//If you need any help regarding this solution..... please leave a comment...... thanks


Related Solutions

Programming Problem Design a program in java that can perform three different arithmetic operations based on...
Programming Problem Design a program in java that can perform three different arithmetic operations based on the user’s input. The three operations are 1. Summation of integers from 1 to m 2. Factorial of a given number n (n!) 3. Finding the leftmost digit of a given integer (note: you have to use int) This program should prompt the user a menu including four options, ask the user for one option, and perform the corresponding computation. This process will repeat...
What is a company with international operations, what kinds of entry strategies the firm has used,...
What is a company with international operations, what kinds of entry strategies the firm has used, the nature of the company’s international operations, its motivations, its entry strategies, the kinds of implementation problems the firm has run into, and how those problems have been dealt with?
1) The “I can’t believe it’s not meth” (ICBINM) diet company has now expanded their business...
1) The “I can’t believe it’s not meth” (ICBINM) diet company has now expanded their business model to include the energy drink market! The label on the can says that consuming one serving of the drink (the entire can) will keep you alert and energetic for 7 hours, guaranteed! As a sleep deprived college student, who has multiple tests coming up, you are excited about this claim. Before investing in several cases of ICBINM drink, you and the rest of...
Stock has a 25% chance of producing a 36% return, a 50% chance of producing a...
Stock has a 25% chance of producing a 36% return, a 50% chance of producing a 12% return, and a 25% chance of producing a -18% return. What is the firm's standard deviation?  Do not round your intermediate calculations.
Big Grouper Fishing Company has expanded and now also catches and sells big snappers. Big groupers...
Big Grouper Fishing Company has expanded and now also catches and sells big snappers. Big groupers still sell for $25 with variable costs per unit of $9. Big snappers sell for $18 with variable costs per unit of $10. Fixed costs are $4,200 for the Company. 75% of the fish sold are big groupers and 25% are big snappers. a. What is the weighted average contribution margin per unit? b. Using the weighted average contribution margin per unit, how many...
in java Write a Java Program that displays a menu with five different options: 1. Lab...
in java Write a Java Program that displays a menu with five different options: 1. Lab Test Average Calculator 2. Dice Roll 3. Circle Area Calculator 4. Compute Distance 5. Quit The program will display a menu with each of the options above, and then ask the user to enter their choice. There is also a fifth option to quit, in which case, the program will simply display a goodbye message. Based on the user’s choice, one of the options...
WRITE CODE IN JAVA it is now your turn to create a program of your choosing....
WRITE CODE IN JAVA it is now your turn to create a program of your choosing. If you are not sure where to begin, think of a task that you repeat often in your major that would benefit from a program. For example, chemistry unit conversions, finding the area for geometric shapes, etc. You can also create an interactive story that changes based on the user input/decisions. The possibilities are endless. The program must include instructions for the user. Be...
Dorsey Co. has expanded its operations by purchasing a parcel of land with a building on...
Dorsey Co. has expanded its operations by purchasing a parcel of land with a building on it from Bibb Co. for $89,000. The appraised value of the land is $24,000, and the appraised value of the building is $102,000. information Required: a. Assuming that the building is to be used in Dorsey Co.’s business activities, what cost should be recorded for the land? (Do not round intermediate calculations.) b. Indicate why, for income tax purposes, management of Dorsey Co. would...
SuperDry Manufactures and sells T-shirts for all kinds of events. The company has two manufacturing operations-...
SuperDry Manufactures and sells T-shirts for all kinds of events. The company has two manufacturing operations- shirt-making and printing. When the company receives an order, the shirt-making department obtains the materials requested and has the fabric cut and sewn to sizes. The ready T-shirts are then sent to the printing department where the customer labels or design are prepared and printed onto the surface with hot press machines. SuperDry has three support departments- Building Maintenance, Human Resources and Design &...
A producer of various kinds of batteries has been producing "D" size batteries with a life...
A producer of various kinds of batteries has been producing "D" size batteries with a life expectancy of 87 hours. Due to an improved production process, management believes that there has been an increasein the life expectancy of their "D" size batteries. A sample of 36 batteries showed an average life of 88.5 hours. It is known that the standard deviation of the population is 9 hours. a. Give the null and the alternative hypotheses. b. Compute the test statistic....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT