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

I need help with my Java class, i saw another response to this lab in Chegg, but

ID: 3783824 • Letter: I

Question

I need help with my Java class, i saw another response to this lab in Chegg, but is waay bad.

I'm stuck, make sure that the output prints the name of the cities in upper case with the "to" in lower case between the city string. This is what I have so far

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

public class Itinerary
{

public static void main(String[] args)
{
List<String> itinerary = new ArrayList<>();
String travelRoute;
StringBuilder sb;
Scanner input = new Scanner(System.in);
String city;
boolean flag = true;

while(flag)
{
System.out.println("Destination: ");
//
city = input.next();

if(city.equalsIgnoreCase("done"))
{
flag= false;
//
}
itinerary.add(city);
  
}
//     starts at index 0| until the list's size minus 1| one at a time
for (int i = 0; i < itinerary.size()-1; i++) {
  
   String s = itinerary.get(i).toUpperCase();
           sb = new StringBuilder(s);

Lab Itinerary CSIS-1410 Instructions: Sample output: Write a program that does the following: Destination London Create an ArrayList of Strings and call it itinerary Destination: Paris Read in destinations from the user until the user enters done (or DONE, Destination: Rome 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 Destination done route as shown in the output Use a StringBuilder called sb to create the String travelRoute travel route Loop through all the elements of the ArrayList itinerary LONDON to PARIS to ROME 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

solution:

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

public class Itinerary
{

    public static void main(String[] args)
    {
        // declaration and assignment of varibales
        List<String> itinerary = new ArrayList<>();
        String travelRoute;
        StringBuilder sb;
        Scanner input = new Scanner(System.in);
        String city;
        int i=0;
        boolean flag = true;
        // while loop which runs untill input entered by user is Done,donE..etc.
        while(flag)
        {
            System.out.println("Destination: ");
            city = input.next();
            if(city.equalsIgnoreCase("done"))
            {
                flag= false;
                break;
            }
            itinerary.add(city);
        }
        //StringBuilder object is created
        sb = new StringBuilder();
        //while loop which takes one by one value from itinerary and adds to
        //StringBuilder object with uppercase
        while(i < itinerary.size())
        {
           String s = itinerary.get(i).toUpperCase();
           sb.append(s);
           i++;
           if (i != itinerary.size())
           {
               sb.append(" to ");
           }
        }
        System.out.println("travel route: " + " " + sb);
    }
}

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