1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
lara31 [8.8K]
3 years ago
7

Write a program that asks the user to input a set of floating-point values. When the user enters a value that is not a number, g

ive the user a second chance to enter the value. After two chances, quit reading input. Add all correctly specified values and print the sum when the user is done entering data. Use exception handling to detect improper inputs.
Computers and Technology
2 answers:
forsale [732]3 years ago
4 0

Answer:

See Explaination for program code

Explanation:

Code below

import java.io.*;

import java.util.*;

// Declare a class

public class DataReader

{

// Start the main method.

public static void main(String[] args)

{

// create the object of scanner class.

Scanner scan = new Scanner(System.in);

// Declare variables.

boolean done = false;

boolean done1 = false;

float sum = 0;

double v;

int count = 0;

// start the while loop

while (!done1)

{

// start the do while loop

do

{

// prompt the user to enter the value.

System.out.println("Value:");

// start the try block

try

{

// input number

v = scan.nextDouble();

// calculate the sum

sum = (float) (sum + v);

}

// start the catch block

catch (Exception nfe)

{

// input a character variable(\n)

String ch = scan.nextLine();

// display the statement.

System.out.println(

"Input Error. Try again.");

// count the value.

count++;

break;

}

}

// end do while loop

while (!done);

// Check whether the value of count

// greater than 2 or not.

if (count >= 2)

{

// display the statement on console.

System.out.println("Sum: " + sum);

done1 = true;

}

}

}

}

Lady_Fox [76]3 years ago
3 0

Answer:

Check the explanation

Explanation:

// include the necessary packages

import java.io.*;

import java.util.*;

// Declare a class

public class DataReader

{

// Start the main method.

public static void main(String[] args)

{

// create the object of scanner class.

Scanner scan = new Scanner(System.in);

// Declare variables.

boolean done = false;

boolean done1 = false;

float sum = 0;

double v;

int count = 0;

// start the while loop

while (!done1)

{

// start the do while loop

do

{

// prompt the user to enter the value.

System.out.println("Value:");

// start the try block

try

{

// input number

v = scan.nextDouble();

// calculate the sum

sum = (float) (sum + v);

}

// start the catch block

catch (Exception nfe)

{

// input a character variable(\n)

String ch = scan.nextLine();

// display the statement.

System.out.println(

"Input Error. Try again.");

// count the value.

count++;

break;

}

}

// end do while loop

while (!done);

// Check whether the value of count

// greater than 2 or not.

if (count >= 2)

{

// display the statement on console.

System.out.println("Sum: " + sum);

done1 = true;

}

}

}

}

Sample Output:

Value:

12

Value:

12

Value:

ten

Input Error. Try again.

Value:

5

Value:

nine

Input Error. Try again.

Sum: 29.0

You might be interested in
Which code will allow Joe to print Coding is fun. on the screen? print("Coding is fun.") print(Coding is fun.) print = (Coding i
ludmilkaskok [199]

Answer:

print(“Coding is fun.”)

Explanation:

The proper format for a print statement is usually you have the print statement followed by the string in quotes in parentheses.

Hope this helped!

7 0
3 years ago
Read 2 more answers
The Company management has asked that you compare the OSSTMM and the PTES to determine which methodology to select for internal
Sonbull [250]

Answer:

The basic comaprism of OSSTMN and PTES includes the following: OSSTMN is more theoretical, security assessment methodology, and Metrics based why PTES is technology oriented, penetration testing methodology ,  extended analysis of all stages

Explanation:

Solution

Penetration testing has several methodologies which include :OSSTMM and PTES  

The comparison between OSSTMM and PTES is stated as follows:

OSSTMM:                                                

Security assessment methodology

More Theoretical  

Metrics based

PTES :

Technology oriented

Penetration testing methodology

Extended analysis of all stages

Now,

There are 7 stages which is used to define PTES for penetration testing.(Penetration Testing Execution Standard)

  • Pre-engagement Interactions
  • Intelligence Gathering
  • Threat Modeling
  • Vulnerability Analysis
  • Exploitation
  • Post Exploitation
  • Reporting

Now,

The OSSTMM is used to obtain security metrics and performing penetration testing .The OSSTMM provides transparency to those who have inadequate security policies and configurations.

The OSSTMM includes the entire risk assessment process starting from requirement analysis to report creation.

Six areas are covered by OSSTMM which are:

  • Information security
  • Process security
  • Internet technology security
  • Communications security
  • Wireless security
  • Physical security
7 0
2 years ago
Why it is so important for all application builders to always check data received from unknown sources, such as web applications
Aleks04 [339]
The already-long problem on hacking and other security-related cases necessitates for the application builders to check the data received from unknown sources. To further strengthen the security, even data received from known sources also need to be check as these may also contain harmful viruses creating critical problem to the application. 
6 0
3 years ago
How is a transaction verified on a cryptocurrency network?.
Agata [3.3K]

Answer:

By being a part of a block to a block chain and each block in the block chain is precisely connected to the block that was before it.

Explanation:

I Hope This Helps You

6 0
2 years ago
In addition to format commands that are found in the ribbon, which option is available for more extensive formatting?
eimsori [14]

Answer:

A

Explanation:

5 0
3 years ago
Other questions:
  • What's the risk or effect of software piracy?
    12·2 answers
  • You have just installed a new sound card in your system, and Windows says the card installed with no errors. When you plug up th
    5·1 answer
  • On a piano, a key has a frequency, say f0. Each higher key (black or white) has a frequency of f0 * r^n, where n is the distance
    10·1 answer
  • In C++ write a program that prints out PI as a type double and a type float EXACTLY as shown below. Your program should have ONE
    13·1 answer
  • Write a program to read 10 integers from an input file and output the average, minimum, and maximum of those numbers to an outpu
    14·1 answer
  • It’s Saturday and you’re looking forward to hanging out with friends and having some fun. However, you get two phone calls early
    10·1 answer
  • QueSUUN TU
    15·1 answer
  • Which conditions make using an array a better choice than a list? Select 3 options.
    12·2 answers
  • . Question 2 Fill in the blank: R Markdown notebooks can be converted into HTML, PDF, and Word documents, slide presentations, a
    9·1 answer
  • Thirty percent of a magazine's subscribers are female. A random sample of 50 subscribers Answer the following questions using Ex
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!