1. Consider the following Java program, which consists of the class Spends. Notice this defines getSpend,...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
1. Consider the following Java program, which consists of the class Spends. Notice this defines getSpend, is Amount and tostring methods. Remember that Integer.parseInt applied to a string representation of an integer returns the integer in question. public class Spends { private String[] d = {"P1", "10", "15", "P2", "12", "23", "38", "P3", "3", "P4"}; } public int getSpend (String id) { int spend = 0; boolean done = false; } } for (int i = 0; i < d.length && !done; i++) { if (d[i].equals(id)) { for (int j=i-1; j >= 0 &&isAmount (d[j]); j--) { spend +Integer.parseInt (d[j]); } done= true; public boolean isAmount (String s) { return s.charAt(0) != 'P'; } } return spend; } public String toString () { String s= ""; int i = 0; while (i < d.length) { if (!isAmount (d[i]) && getSpend (d[i]) > 0) { s += d[i] + "=" + getSpend (d[i]) + " "; } i++; } return s; a) Specify all the data types (including classes) used in the program, giving one of the values used for each type. [5 marks] b) List all the loop constructs used in the program and give the keywords and syntax required in each case. Where there is the possibility to use an alternative construct, say what this is. [5 marks] 1. Consider the following Java program, which consists of the class Spends. Notice this defines getSpend, is Amount and tostring methods. Remember that Integer.parseInt applied to a string representation of an integer returns the integer in question. public class Spends { private String[] d = {"P1", "10", "15", "P2", "12", "23", "38", "P3", "3", "P4"}; } public int getSpend (String id) { int spend = 0; boolean done = false; } } for (int i = 0; i < d.length && !done; i++) { if (d[i].equals(id)) { for (int j=i-1; j >= 0 &&isAmount (d[j]); j--) { spend +Integer.parseInt (d[j]); } done= true; public boolean isAmount (String s) { return s.charAt(0) != 'P'; } } return spend; } public String toString () { String s= ""; int i = 0; while (i < d.length) { if (!isAmount (d[i]) && getSpend (d[i]) > 0) { s += d[i] + "=" + getSpend (d[i]) + " "; } i++; } return s; a) Specify all the data types (including classes) used in the program, giving one of the values used for each type. [5 marks] b) List all the loop constructs used in the program and give the keywords and syntax required in each case. Where there is the possibility to use an alternative construct, say what this is. [5 marks]
Expert Answer:
Related Book For
Guide To Java A Concise Introduction To Programming
ISBN: 978-3031228414
2nd Edition
Authors: James T. Streib, Takako Soma
Posted Date:
Students also viewed these programming questions
-
IN DETAILED - Pseudo code for findLCS() appears after the pseudo code for cutRod(). int cutRod( int [] p ) Initialize. Set n to the length of the prices array p. Allocate space for an array r from 0...
-
Consider implementing the natural logarithm function ln(t) for floating-point numbers using the McLaurin series: ln (i) List all special behaviours the natural logarithm function should have in...
-
Discuss the different sampling procedures and techniques that you will apply to the qualitative and quantitative phases of the study.
-
The first moment of the shaded area with respect to the x-axis is denoted by Qx. (a) Express Qx in terms of b, c, and the distance y from the base of the shaded area to the x-axis. (b) For what value...
-
A sheet of steel must be 0.6 inches thick with a tolerance of 0.05 inches. Write this specification as an absolute value inequality using x to represent the thickness of the sheet.
-
Design a 1-4 shell-and-tube heat exchanger to cool \(60,000 \mathrm{lb} / \mathrm{hr}\) of \(42^{\circ} \mathrm{API}\) kerosene from 400 to \(220^{\circ} \mathrm{F}\) by heating a \(35^{\circ}...
-
Copper tubing is joined to the absorber of a flat-plate solar collector as shown. The aluminum alloy (2024- T6) absorber plate is 6 mm thick and well insulated on its bottom. The top surface of the...
-
A single AC source with a peak voltage of 22.56 V and an operational angular frequency of 67.9 rad/s powers a circuit with a single 321 F capacitor. Determine the peak value of the current in this...
-
What would be the consequences of an increase in fertility in economy? Are these consequences good or bad?
-
Briefly describe the organization of this book.
-
Being a product and industry expert implies that the salesperson has knowledge of the most common product information categories. List the categories of product and industry knowledge a salesperson...
-
How do you convey this information to the other departments within your company to prepare for this meeting? Will you invite your boss to the meeting? Why? You work for the sales department of an...
-
On what theoretical basis are cost drivers chosen?
-
Select a multinational company you would like to work for. Research its mission statement and organizational culture. Identify the values and practices that make it a great place to work. Why do...
-
1. Jonathan Jordan is a salaried employee earning $9,100 per month. What is Jonathan's weekly salary? 2. Melissa Stewart is a bookkeeper who is paid $8 per hour on a biweekly basis. Compute her gross...
-
Represent each of the following combination of units in the correct SI form using an appropriate prefix: (a) m/ms, (b) k m, (c) k s /mg, and (d) k m N.
-
The Fibonacci sequence is the series of numbers which can be found by adding up the two numbers before it as shown below: \[ 0,1,1,2,3,5,8,13,21,34, \ldots \] Write a complete program to compute the...
-
Consider a program that reads data from an input file named in.dat, performs calculations, and outputs the results to a file named result. out. A. What would happen if the file in. dat did not exist...
-
Repeat Exercise 15 in Chap. 3 to allow the user to find the hottest city for any number of sets of 3 cities. Use input, message, and confirmation dialog boxes. Confirmation dialog boxes are discussed...
-
Remmers Travel Agency purchased land for 85,000 cash on December 10, 2025. At December 31, 2025, the lands value has increased to 93,000. What amount should be reported for land on Remmers statement...
-
As of December 31, 2025, Stoneland AG has assets of 3,500 and equity of 2,000. What are the liabilities for Stoneland AG as of December 31, 2025? a. 1,500. b. 1,000. c. 2,500. d. 2,000.
-
Performing services on account will have the following effects on the components of the basic accounting equation: a. increase assets and decrease equity. b. increase assets and increase equity. c....
Study smarter with the SolutionInn App