Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help organizing an array of my vacation objects in this code. I need to retrieve a neede object by it's name(when the user

I need help organizing an array of my vacation objects in this code. I need to retrieve a neede object by it's name(when the user is selecting what to display) .Classes are travel and trip.

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

namespace ConsoleApp

{

class Travel

{

static void Main(string[] args)

{

string howToUse = "Choose the country that you want to travel to.";

Console.WriteLine(howToUse);

Console.WriteLine();

Console.WriteLine("Then enter your trip information.");

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 = GetPlaceInfo("Which 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 GetPlaceInfo(string quest)

{

string userInput;

Console.Write("India,Switzerland,Mexico,North America,Australia,Europe,Japan.");

userInput = GetInfo(quest);

return userInput;

}

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Transact SQL Cookbook Help For Database Programmers

Authors: Ales Spetic, Jonathan Gennick

1st Edition

1565927567, 978-1565927568

More Books

Students also viewed these Databases questions