Skip to content

Instantly share code, notes, and snippets.

@Dyrits
Forked from codecademydev/Profile.cs
Last active May 10, 2023 08:08
Show Gist options
  • Save Dyrits/cb13484a2835b2a508c8c44e15701dd4 to your computer and use it in GitHub Desktop.
Save Dyrits/cb13484a2835b2a508c8c44e15701dd4 to your computer and use it in GitHub Desktop.
The Object of Your Affection

The Object of Your Affection

Your friend is building a new match-making service: The Object of Your Affection or OOYA for short (don’t worry, you still have time to convince them to change the name).

With your new understanding of C# objects and classes, your friend thought you could build a pretty well-organized system of dating profiles.

Your first step? Build a Profile class that allows users to generate profile objects.

The Profile should store the following information:

  • User’s name
  • User’s age
  • User’s city
  • User’s country
  • User’s pronouns
  • User’s hobbies

And this is how users should be able to interact with their own profiles:

  • Create a new profile with some information
  • Add hobbies
  • View profile

Let’s get started!

using System;
namespace DatingProfile
{
class Profile
{
private string name;
private int age;
private string city;
private string country;
private string pronouns;
private string[] hobbies;
public Profile(string name, int age, string city, string country, string pronouns = "they/them")
{
this.name = name;
this.age = age;
this.city = city;
this.country = country;
this.pronouns = pronouns;
}
public string ViewProfile()
{
string hobbies = "";
foreach (string hobbie in this.hobbies) {
hobbies += $"{hobbie}, ";
}
hobbies = hobbies.Remove(hobbies.Length - 2);
return $"Name: {this.name} \nAge: {this.age} \nCity: {this.city} \nCountry: {this.country} \nHobbies: {hobbies}";
}
public void SetHobbies(string[] hobbies)
{
this.hobbies = hobbies;
}
}
}
using System;
namespace DatingProfile
{
class Program
{
static void Main(string[] args)
{
Profile sam = new Profile("Sam Drakkila", 30, "New York", "USA", "he/hom");
sam.SetHobbies(new string[]{"Video games", "Board games"});
Console.WriteLine(sam.ViewProfile());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment