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

What is the code in Java? Sample Output Destination: London Destination: Paris D

ID: 3881123 • Letter: W

Question

What is the code in Java?

Sample Output Destination: London Destination: Paris Destination: Rome Destination: done Instructions: Write a program that does the following Create an ArrayList of Strings and call it itinerary Read in destinations from the user until the user enters done (or DONE, or dOnE,..) As you read in the destinations add them to the itinerary Next You need to create a String called travelRoute that includes the travel route as shown in the output . Use a StringBuilder called sb to create the String travelRoute . tl route: LONDON to PARIS to ROME Loop through all the elements of the ArrayList itinerary -Change the destinations (e.g. Rome) to all uppercase letters (e.g. ROME) before adding them to sb -Add the word to (lowercase) between the destinations, but not at the end) When you are done create the string travelRoute based on the information stored in sb. Print the String travelRoute.

Explanation / Answer

TravelRoute.java

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

public class TravelRoute {

public static void main(String[] args) {

// Declaring variables
String str, travelRoute = "";

/*
* Creating an Scanner class object which is used to get the inputs
* entered by the user
*/
Scanner sc = new Scanner(System.in);

//Creating an ArrayList
ArrayList < String > arl = new ArrayList < String > ();

// Getting the input entered by the user
System.out.print("Destination :");
str = sc.next();

//Adding the Strings to ArrayList until the user enters "done"
while (!str.equalsIgnoreCase("done")) {
arl.add(str);
System.out.print("Destination :");
str = sc.next();
}

//Displaying the travel route
System.out.println("travel route:");
for (int i = 0; i < arl.size(); i++) {
travelRoute += arl.get(i).toUpperCase();
if (i < arl.size() - 1) {
travelRoute += " to ";
}
}

System.out.println(travelRoute);

}

}

________________

Output:

Destination :London
Destination :Paris
Destination :Rome
Destination :done
travel route:
LONDON to PARIS to ROME


_______________Could you plz rate me well.Thank 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