Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1) Suppose you want to write code that might throw an IllegalArgumentException. If the exception occurs, you want other code to run to handle the

1) Suppose you want to write code that might throw an IllegalArgumentException. If the exception occurs, you want other code to run to handle the problem. Fill in the blanks:! ) _________ { int items = transaction.process(data, values); // might throw exception account.incementCount(items); // only if processing above succeeded } ________________ (IllegalArgumentException iae) { transaction.log("Problem processing ID: " + transaction.getID()); displayAlert(iae.getMessage()); }

2) Consider a Java program called ActivateSystems with a main method declared as: public static void main(String[] data) Suppose that you execute this main method using the following command line from your operating system: java ActivateSystems -a tempLog inputFile outputFile Which of the following is NOT true about the data array upon launch? data[4] is "outputFile"

data.length is 4 data[0] is "-a" data[3] is "outputFile"

3) Suppose we want to reject a null parameter with an appropriate exception. Complete the code: public void process(String value) { if (value == null) { ________________ } // remainder of method } throws (NullPointerException npe) Catch (NullPointerException npe) throw NullPointerException(); throw new NullPointerException();

4) Suppose you have a text file with many three-line records of city name (as a String), latitude (as a double), and longitude (as a double). For example: Blacksburg 37.2294444 -80.4141667 Falls Church 38.8822222 -77.1713889 For the sake of this question, you may safely assume the data is well-formed and entirely valid. You've already constructed a Scanner called "input" with this data file, and you want to populate an ArrayList collection. City is a class with a constructor that takes a name, latitude, and longitude, such as: City city = new City("Blacksburg", 37.2294444, -80.4141667); Fill in the blanks below:

List cityList = new ________________ ; while (input.hasNextLine()) { String name = ______________________ ; double latitude = _______________________ ; ; double longitude = _________; cityList.add(new City(name, latitude, longitude)); }

5)Suppose you want to format a double variable for output with a total of 8 right-justified characters to the left of the decimal (with no leading zeroes) and 3 characters to the right of the decimal. For example: 12345678.999 or 123.000 What is the format specifier to use for the printf() method, as in: System.out.printf(" _______________ ", value);

Step by Step Solution

There are 3 Steps involved in it

Step: 1

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

Step: 3

blur-text-image

Ace Your Homework with AI

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

Get Started

Students also viewed these Databases questions