Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Create a class. DONE
- Add a private integer called largest. Add a property that can get largest. DONE
- Add a private List<int> initializing it to new List<int>() at declaration.
- Add a method called Add that takes an integer.
- - This method will add the number to the list, if the value is larger than the current largest, it will update the largest to be the larger number.
- In main.
- Instantiate your class.
- Add a loop that gets a number from the user, adds it the list, then prints out the largest.
- Loop until they enter -1.
- */
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Largest_Homework
- {
- class MyClass // My Class
- {
- // (1) Add a private integer called largest. Add a property that can get largest:
- private int largest; // Declare private int largest
- public int Largest // Create a public i
- {
- get { return largest; }
- set { largest = value; }
- }
- // (2) Add a private List<int> initializing it to new List<int>() at declaration:
- private static List<int> myList = new List<int>();
- // (3) Add a method called Add that takes an integer:
- public void Add(int takeInteger)
- {
- // (3a) This method will add the number to the list:
- myList.Add(takeInteger);
- // (3b) If the value is larger than the current largest, it will update the largest to be the larger number
- if (takeInteger > Largest)
- {
- Largest = takeInteger;
- }
- return;
- }
- static void Main(string[] args)
- {
- // (4) Instantiate your class:
- MyClass free = new MyClass();
- // (5) Add a loop:
- while (free.largest > -1) // While loop which checks if the object variable free is > -1
- {
- // (5a) that gets a number from the user:
- Console.Write("Enter a number: "); // Prompt user for input
- // (5b) adds it the list:
- var N = int.Parse(Console.ReadLine());
- free.Add(N);
- // (5c) then prints out the largest:
- Console.Write("Your largest number is: " + free.largest);
- // (5d) Loop until they enter -1:
- free.largest--;
- }
- // Prevent Exit:
- Console.ReadLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement