write a Java program that splits a text and computes the sum of values. Your program...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
write a Java program that splits a text and computes the sum of values. Your program reads a single text from the user. The text consists of string representation of decimals that are split by '-' symbol and it is in the following format 12-13-45-2-560-...-4-234. The program will split the given text into string decimals and obtain integer values (you can use Integer.parseInt(str) ). It computes the sum of odd numbers and the sum of even numbers. At this point, you are expected to write a method called isEven, which gets a single integer as parameter and returns true if the number is even and false otherwise. Use this method as a helper method as you compute sums whenever you think is appropriate to call. For instance, the text entered by the user is 20-30-400-1-13-10, then the program returns 460 (-20+30+400+10) as the sum of even numbers 14 (=1+13) as the sum of odd numbers ● Sample outputs of the program must look like as below: Enter Text:78562-3456 Sum of Even: 82018 Sum of Odd:0 Enter Text: 23-40-3 Sum of Even: 40 Sum of Odd: 26 Enter Text:1-1-1-10-20-1-0-6-3-3 Sum of Even: 36 Sum of Odd:10 Enter Text:20-30-400-1-13-10 Sum of Even: 460 Sum of Odd:14 Activate W Go to Settings write a Java program that splits a text and computes the sum of values. Your program reads a single text from the user. The text consists of string representation of decimals that are split by '-' symbol and it is in the following format 12-13-45-2-560-...-4-234. The program will split the given text into string decimals and obtain integer values (you can use Integer.parseInt(str) ). It computes the sum of odd numbers and the sum of even numbers. At this point, you are expected to write a method called isEven, which gets a single integer as parameter and returns true if the number is even and false otherwise. Use this method as a helper method as you compute sums whenever you think is appropriate to call. For instance, the text entered by the user is 20-30-400-1-13-10, then the program returns 460 (-20+30+400+10) as the sum of even numbers 14 (=1+13) as the sum of odd numbers ● Sample outputs of the program must look like as below: Enter Text:78562-3456 Sum of Even: 82018 Sum of Odd:0 Enter Text: 23-40-3 Sum of Even: 40 Sum of Odd: 26 Enter Text:1-1-1-10-20-1-0-6-3-3 Sum of Even: 36 Sum of Odd:10 Enter Text:20-30-400-1-13-10 Sum of Even: 460 Sum of Odd:14 Activate W Go to Settings
Expert Answer:
Answer rating: 100% (QA)
Heres a Java program that fulfills your requirements java import javautilScanner public cla... View the full answer
Related Book For
Java An Introduction To Problem Solving And Programming
ISBN: 9780134462035
8th Edition
Authors: Walter Savitch
Posted Date:
Students also viewed these programming questions
-
You must decide whether to buy, build or lease a building for your business needs over the next 10 years. If you decide to build, you must determine if it is better to buy an existing building and...
-
1. Review the six (6) goals of performance based acquisition(s); choose two and discuss how your choices can be implemented for effective management of contracts, using an actual or theoretical...
-
Give four general examples of the use of threads in a single-user multiprocessing system.
-
Use the graph of the function g shown below in Exercises (a) Graph: y = g(|x|). (b) Graph: y = |g(x)|. g(x) -4,0 (4,0) 5-4 2 34 5 x 2,-1) 20,-1) -4
-
Show that during the early part of the electron-positron annihilation era, the ratio of the electron number density to the photon number density scaled with temperature as \[\frac{n_{-}}{n_{\gamma}}...
-
Prepare journal entries to record the transactions in E12- 3. In E12- 3. For each of the following transactions, identify the net asset classification ( unrestricted, temporarily restricted,...
-
An 80 kg person stands in an elevator which is ascending towards the top of a building. A) As the elevator begins its ascent, it accelerates at the rate of 1 m/s2 . Draw the free body diagram showing...
-
Ivanhoe Machinery Corporation, a private company following ASPE sold manufacturing equipment for $2,500 each. Each machine carried with it a 2-year warranty against manufacturing defects. From...
-
On January 1. Alan King decided to deposit $60,600 in a savings account that will provide funds four years later to send his son to college. The savings account will earn 9% annually. Any Interest...
-
Blue Coral Breweries (BCB) is planning an IPO. Its underwriters have said the stock will sell at $20 per share. The direct costs (legal fees, printing, etc.) will be $800,000. The underwriters will...
-
When banks become reluctant to lend to each other the 3-month LIBOROIS spread increases. Explain this statement.
-
Explain what is meant by (a) the 3-month LIBOR rate and (b) the 3-month OIS rate. Which is higher? Why?
-
The challenges arising in designing the reactor with core outlet temperature of the order of \(1273 \mathrm{~K}\) ?
-
An April 2014 study by researchers at University College London found that people who ate seven or more portions of fruits and vegetables a day had a \(42 \%\) lower risk of death at any point in...
-
A linear system H has the input-output pairs depicted in Fig p2. Answer the following questions and explain why. (do not refer to the solution manual because the solution given there is wrong)...
-
In exchange for land, the company received a 12-month note on January 1. The face amount of the note is $1,000, and the stated rate of interest is 13%, compounded annually. The 13% rate is equal to...
-
Define a variation on StringLinkedListSelfContained from Listing 12.7 that stores objects of type Species, rather than of type String. Write a program that uses that linked-list class to create a...
-
Consider a class BasketballGame that represents the state of a basketball game. Its attributes are The name of the first team The name of the second team The score of the first team The score of the...
-
Suppose you are writing a program that asks the user to give a yes-or-no response. Assume that the program reads the users response into the Stringvariableresponse. a. If response is yes or y, set...
-
Given the following information, answer the questions about this project: a. Draw the network as a Gantt chart. b. What is the critical path? Which activities have slack time? c. What would happen if...
-
Develop a Gantt chart with the following information. What is the expected duration of the project? What is the critical path? Activity Expected Duration Predecessors A BL 12 8 None None C 5 None D...
-
Consider a project with the following information. Construct the project activity network using AOA methodology and label each node and arrow appropriately. Identify all dummy activities required to...
Study smarter with the SolutionInn App