Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

import java.util.ArrayList; import java.util.InputMismatchException; import java.util.Scanner; public class FindCorruptData { /** Reads a set of floating-point values from a string. The first number is an

import java.util.ArrayList;
import java.util.InputMismatchException;
import java.util.Scanner;

public class FindCorruptData
{
/**
Reads a set of floating-point values from a string. The first number is an integer that indicates how
many floating point numbers follow. Some of the floating point numbers may be corrupt. This program uses exceptions
to count the number of bad floating (i.e. double) numbers and prints them.
 */
public static void printCorruptDataValues()
{
String numbers = "6 3.14 7.25 8,23 6.99 9.2w 6.34";
Scanner console = new Scanner(numbers);
int numDoubles = console.nextInt();

//-----------Start below here. To do: approximate lines of code = 5
// Use a for loop to loop through numDoubles double number strings.
// Get the next double number string using the scanner then use Double.parseDouble() to determine
// if the current double number string is corrupt in some way. If it is, print "Corrupt Double Number: "
// followed by the number string.  
// Hint: use try{..} catch{..} such that you catch any NumberFormatException and print out the bad double number
// making use of the getMessage() method of the exception class to print the corrupt number string.











//-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions.
}

public static void main(String[] args)
{
printCorruptDataValues();
System.out.println("Expected:");
System.out.println("Corrupt Double Number: For input string: "8,23"");
System.out.println("Corrupt Double Number: For input string: "9.2w"");
}
}


P.S: Please include screenshots of the output so all is working as expected. Thank you!

Step by Step Solution

3.59 Rating (153 Votes )

There are 3 Steps involved in it

Step: 1

Hi Please find code below as requested in comment section import javautilArrayList import javautilIn... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

College Physics

Authors: Jerry D. Wilson, Anthony J. Buffa, Bo Lou

7th edition

9780321571113, 321601831, 978-0321601834

More Books

Students also viewed these Programming questions

Question

What is meant by the internal validity of an experiment?

Answered: 1 week ago

Question

What is a wage bracket withholding table

Answered: 1 week ago

Question

Describe ERP and how it can create efficiency within a business

Answered: 1 week ago