课程: C# Practice: Interfaces and Abstract Classes
Explore the code challenge
- [Instructor] This course consists of automated code challenges that appear when you click on the challenge links in the course table of contents. Each challenge includes instructions that describe your task and a pair of code editors where you create and test your own solution to the challenge. These challenges are hosted by CoderPad, and they appear in the same area of the course page where you watch the course videos. We recommend using a desktop browser for the best experience with code challenges, but you can use the LinkedIn Learning mobile app if you prefer. Looking at the CoderPad interface, you'll see four distinct areas. The instructions are in the top left. On the right side of the screen are two code editors. The one at the top is where you write your code answer, and the one on the bottom is where you see how your code is used and how you can modify the test cases. Finally on the bottom left is a console output. You can change the size of these panes by dragging these handles, including dragging from left to right. Now let's talk about the instructions. You'll find those over here. Over there in this section, you'll find a description of the problem, in this case, rephrase. Over here, you'll find a description of the challenge, which is to find the largest number in an array. More details, and then below that is a call out to your specific task, return the largest number in the array using the link expression. In some of the challenges, I'll provide your code with parameters. If that's the case, you'll see some information about the parameters here. So you can see that there is an array of integers, which is called numbers. And of course, if you can read your C Sharp code, you can come over here and look at the code and see that there's a method called FindLargest that receives an int array called numbers and returns an int. You can also read details about the result over here. That should be the largest number in the array, and it's of type N. If there are constraints, they'll be listed below. And in some of our code challenges, we might also include examples. You'll write your code answer here in the top right side of the screen. This is a code editor. It's an interactive code editor that has IntelliSense and other helpful features. Right now, let's just run the code to see what happens. I'll click on test my code. That'll process the code and shows the results of that first test, and it tells me that I've got an incorrect result. Also tells me that my code returned zero, and this also tells me there's some help available. So there's two Boolean variables that are defined here at the top of your answer class. One's called ShowExpectedResult, and the other one is called ShowHints. Let's change ShowExpectedResult to true, and rerun or retest my code. Now over here, I see that I still don't have it correct, and I get two bits of information now. I see that my code returns zero and the expected result for this code challenge is 19. Now if I want more hints, I can change this ShowHints Boolean to true, test my code, and now I see one of the available hints. Try using the system.link method, and so on. And if I run it again, I might get a different hint. You can also change the test code. Now, you have to be careful how much you change here, because it could make your code unrunnable. But for example, let's say I want to put in a different large number here, like 500, and then test my code. Still it says the expected result is 500, and my code returns zero. So now let's start changing this by returning some value. Let's say I'll just return the number 500, and test my code. Now I'm getting the correct answer. Of course, you should write the real code that tests for the largest number in the array. But the point of this is that you can change how the test code runs over here in the test code section. The code challenges for this course are focused on object-oriented topics like abstract base classes and interface implementation. For these kinds of challenges, you'll be asked to create and implement types. So some of the challenges won't have method calls or return values. You will, however, see some useful information in the console output. For example, here I'm asking you to create a trading card class that derives from the card base class. There's some information about how that's going to be called here, and when you run test my code, it tells you that you haven't got the implementation right yet. And in this case, there's one test failed message. In some of the examples, you might see more than one test failed message here. In this case, it's telling me that the GetSalePrice method must be an abstract method. When you finish each code challenge, return to the course table of contents and click the next video to see my solution.