DotNet-101-CSharpFundamentals
  • Introduction
  • Part 0: Solution Setup
    • 1.0: Solution Setup
  • Part 1: Data Types
    • 1.0: Variables
    • 1.1: Data Types
    • 1.2: Data Types Table
    • 1.3: Challenge Answers
    • 1.4: Strings
    • 1.5: String Challenges
    • 1.6: Challenge Answers
    • 1.7: Integers
    • 1.8: Type Conversion
  • Part 2: Boolean Logic And Conditionals
    • 2.0: Boolean Type
    • 2.1: Boolean Logic
    • 2.2: Boolean Challenges
    • 2.3: Challenge Answers
    • 2.4: if, else if, else
    • 2.5: Switch Statements
    • 2.6: Ternary Operators
  • Part 3: Objects, Methods, C# Fundamentals
    • 3.0 Objects
    • 3.1 Properties
      • Challenge Answers
    • 3.2 Methods
      • Challenge Answers
    • 3.3 Method-Overloading
    • 3.4 Constructors
      • Challenge Answers
    • 3.5 Access Modifiers
  • Part 4: Collections Arrays Control Flow
    • 4.0 Arrays
    • 4.1 Loops
    • 4.2 Dictionaries
    • Challenge Answers
    • 4.3 List
    • 4.3a: Challenge Answers
  • Part 5: Inheritance/More On Object Oriented Programming
    • 5.0 Inheritance
    • 5.1 Polymorphism
    • 5.2 Encapsulation
    • 5.3 Getters And Setters
    • 5.4 Exception Handling
  • Part 6: Structs
    • 6.0 Structs
  • Part 7: Enums
    • 7.0 Enums
  • Part 8: Null Coalescing Operator
    • 8.0 Null Coalescing Operator
  • Part 9: Interfaces
    • 9.0 Interfaces
    • 9.1 Rules
    • 9.2 Code With Intent
  • Part 10: More C#
    • 10.0 DateTime
    • 10.1-LINQ
    • Challenge Answers
  • Part 11: Reference and Value Types
    • 11.0 Reference & Value Types
  • Eleven Fifty Style Guide
Powered by GitBook
On this page
  • Bronze
  • Silver
  • Gold
  1. Part 3: Objects, Methods, C# Fundamentals
  2. 3.2 Methods

Challenge Answers

Bronze

class Netflix {
    //Properties
    public string Name { get; set; }
    public double Rating { get; set; }
    public string Genre { get; set; }
}

class Program {
    public void Main(string[] args) {
        Netflix show1 = new Netflix();
        show1.Name = "Hello World!";
        show1.Rating = 4.0;
        show1.Genre = "Kid's Shows";

        Netflix show2 = new Netflix();
        show2.Name = "Hello World! 2";
        show2.Rating = 3.0;
        show2.Genre = "Dark Comedy";

        Netflix show3 = new Netflix();
        show3.Name = "Hello World!: The Movie";
        show3.Rating = 4.5;
        show3.Genre = "All Audiences";

        show1.GetSuggestion();
        show2.GetSuggestion();
        show3.GetSuggestion();

        printMovies();
        }
    }
}

Silver

class Netflix {
    public void GetSuggestion()
    {
        if (this.Rating >= 4) {
            Console.WriteLine("You definitely need to watch this show");
            Console.ReadLine();
        } else {
            Console.WriteLine("You probably won't want to watch this show");
            Console.ReadLine();
        }
    }
}

class Main(string[] args) {
    show1.getSuggestion();
    show2.getSuggestion();
    show3.getSuggestion();
}

Gold

class Netflix {
    public void printMovies() {
        foreach(Netflix movie in movieList) {
            Console.WriteLine("Name: {0}, Rating: {1}, Genre: {2}", show.Name, show.Rating, show.Genre);
        }
        Console.ReadLine();
    }
}

class Main(string[] args) {
        List<Netflix> movieList = new List<Netflix>();
        movieList.Add(show1);
        movieList.Add(show2);
        movieList.Add(show3);

        printMovies();
}
Previous3.2 MethodsNext3.3 Method-Overloading

Last updated 7 years ago