Examine the following code snippet. Add the necessary code…
Examine the following code snippet. Add the necessary code to do the following tasks, in order: Shuffle the airport code names. Add a new airport code (real or fake) to the collection. Sort the collection in reverse order. Locate the index of the code you added to the collection. Print the contents of the collection, as List objects. Indicate what the output of the program would be once it’s run. import java.util.ArrayList;import java.util.Collections;import java.util.List;public class AirportCodes { public static void main(String[] args) { List airportCodes = new ArrayList(); airportCodes.add(“JFK”); // New York airportCodes.add(“LHR”); // London Heathrow airportCodes.add(“LAX”); // Los Angeles airportCodes.add(“HND”); // Tokyo Haneda //Your code here }}
Read DetailsExamine the following code snippet. Add the necessary code…
Examine the following code snippet. Add the necessary code to do the following tasks, in order: Shuffle the list. Add a new fruit to the list. You may choose the fruit. Sort the list. Locate the index of “Orange” in the list. Print the list as an array. Indicate what the output of the program would be once it’s run. import java.util.ArrayList;import java.util.Collections;import java.util.List;public class Main{ public static void main(String[] args) { List fruits = new ArrayList(); fruits.add(“Banana”); fruits.add(“Mango”); fruits.add(“Orange”); fruits.add(“Apple”); /* your code here */ }
Read DetailsYou’re building a system for a library, and you want to ensu…
You’re building a system for a library, and you want to ensure that the number of pages in a book is always a positive value. Write a simple class named `Book` with the following specifications: 1. It should have two private member variables: `String title` and `int pages`.2. The class should have a constructor that accepts a title (a `String`) and pages (an `int`) as parameters.3. If the `pages` parameter in the constructor is less than or equal to zero, throw an exception of type `InvalidPageCountException` with the message “Page count must be positive.”.4. Write the custom exception class `InvalidPageCountException` that extends `Exception`. Do not overthink your solution – it should be around 15-20 lines of code.
Read Details