Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a complete program in a single class called Airports, which works this way

ID: 3619759 • Letter: W

Question

Write a complete program in a single class called Airports, which works this way.

Include in your program this array of airport codes:
String[] airports = {"bdl","pit","sfo","lax","stl","bos","jfk","dfw","den","msp"}

Your program should read in a non-negative int value - say n - from the keyboard and then print one of the airport codes from the array using n as the index into the array. If n is 0, for example, your program should print bdl; if n is 1, print pit, if n is 2, print sfo, and so forth. The airport code you print out is determined by the array index you enter. If n is bigger than 9, then the airport code you print is the one determined by the last digit of n. Thus if n is 911 (or 12341) print pit -- the airport code with index 1; if n is 1002 print sfo - the airport code with index 2. In general, use the mod operator "%" to figure the last digit, and then select that airport code. (Thus 911%10 = 1, 12345%10 = 5, and so forth).

A final requirement: your solution must make explicit use of the airports array (in other words, don't solve the problem by usine 10 if statements).

Explanation / Answer

Dear, Here is the complete code import java.io.*; // needed for file classes import java.util.Scanner;// Needed for the Scanner class public class Airports { // main method begins execution of Java application public static void main( String args[] ) { String[] airports = {"bdl","pit","sfo","lax","stl","bos","jfk","dfw","den","msp"}; int n; // Create a Scanner object for keyboard input. Scanner keyboard = new Scanner(System.in); System.out.println("Enter non- negative integer Value:" ); n= keyboard.nextInt(); if(n>9) n=n%10; //outputting Airport code System.out.println("Airport Code:"+airports[n]); //exit program System.exit(0); }//end main }//end class Hope this will help you...

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote