Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

For JAVA Describe the output for the ProductCodes program if a finally clause were added to the try statement that printed the string Got here!.

For JAVA

Describe the output for the ProductCodes program if a finally clause were added to the try statement that printed the string "Got here!".

import java.util.Scanner; public class ProductCodes { //----------------------------------------------------------------- // Counts the number of product codes that are entered with a // zone of R and and district greater than 2000. //----------------------------------------------------------------- public static void main (String[] args) { String code; char zone; int district, valid = 0, banned = 0; Scanner scan = new Scanner (System.in); System.out.print ("Enter product code (STOP to quit): "); code = scan.nextLine(); while (!code.equals ("STOP")) { try { zone = code.charAt(9); district = Integer.parseInt(code.substring(3, 7)); valid++; if (zone == 'R' && district > 2000) banned++; } catch (StringIndexOutOfBoundsException exception) { System.out.println ("Improper code length: " + code); } catch (NumberFormatException exception) { System.out.println ("District is not numeric: " + code); } System.out.print ("Enter product code (STOP to quit): "); code = scan.nextLine(); } System.out.println ("# of valid codes entered: " + valid); System.out.println ("# of banned codes entered: " + banned); } }

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

Recommended Textbook for

DATABASE Administrator Make A Difference

Authors: Mohciine Elmourabit

1st Edition

B0CGM7XG75, 978-1722657802

More Books

Students also viewed these Databases questions