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
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started