Question: I need help with this code. In the place where I'm asking the user to choose which of the places that are hardcoded for them

I need help with this code. In the place where I'm asking the user to choose which of the places that are hardcoded for them to display, after displaying the chosen place, ask if the user wants to display another place. After this is done ask the user whether one wants to plan another vacation

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

namespace ConsoleApp

{

class Program

{

static void Main(string[] args)

{

string howToUse = "Decide if you want to add a trip, if so add info.";

Console.WriteLine(howToUse);

Console.WriteLine();

List trips = new List();

string result = GetInfo("Add a trip [Y/N]");

while (string.Compare(result, "Y", true) == 0)

{

Trip trip = AddTrip();

trips.Add(trip);

result = GetInfo("Add a trip [Y/N]");

}

foreach (Trip trip in trips)

{

Console.WriteLine(trip.ToString());

}

Console.ReadLine();

}

private static Trip AddTrip()

{

string name = GetInfo("Name of Place");

string location = GetInfo("Location");

string thingstodo = GetInfo("Things to do");

string arrival = GetInfo("Arrival");

string departure = GetInfo("Departure");

if (!string.IsNullOrEmpty(name) && !string.IsNullOrEmpty(location) && !string.IsNullOrEmpty(arrival) && !string.IsNullOrEmpty(departure) && !string.IsNullOrEmpty(thingstodo))

{

Trip trip = new Trip(name, location, arrival, departure, thingstodo);

return trip;

}

else if (!string.IsNullOrEmpty(name) && !string.IsNullOrEmpty(arrival))

{

Trip trip = new Trip(name, arrival);

return trip;

}

else

{

Trip trip = new Trip();

trip.Location = location;

trip.NameOfPlace = name;

trip.Arrival = arrival;

trip.Departure = departure;

trip.ThingsToDo = thingstodo;

return trip;

}

}

static string GetInfo(string infoType)

{

string userInput;

Console.Write("Enter {0} : ", infoType);

userInput = Console.ReadLine();

return userInput;

}

}

}

// Trip.cs class

namespace ConsoleApp

{

public class Trip

{

public string NameOfPlace { get; set; }

public string Location { get; set; }

public string ThingsToDo { get; set; }

public string Arrival { get; set; }

public string Departure { get; set; }

public Trip()

{

}

public Trip(string nameOfPlace, string arrivalDate) : this()

{

this.NameOfPlace = nameOfPlace;

this.Arrival = arrivalDate;

}

public Trip(string nameOfPlace, string location, string arrivalDate, string departureDate, string thingsToDo) : this(nameOfPlace, arrivalDate)

{

this.Location = location;

this.Departure = departureDate;

this.ThingsToDo = thingsToDo;

}

public override string ToString()

{

string str = string.Empty;

if (!string.IsNullOrEmpty(this.NameOfPlace))

str += "Name Of Place : " + this.NameOfPlace + ";";

if (!string.IsNullOrEmpty(this.Location))

str += "Location : " + this.Location + ";";

if (!string.IsNullOrEmpty(this.ThingsToDo))

str += "Things To Do : " + this.ThingsToDo + ";";

if (!string.IsNullOrEmpty(this.Arrival))

str += "Arrival : " + this.Arrival + ";";

if (!string.IsNullOrEmpty(this.Departure))

str += "Departure : " + this.Departure + ";";

return str;

}

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!