forked from AustinCodingAcademy/csharp-workbook
-
Notifications
You must be signed in to change notification settings - Fork 0
Created gradebook #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mtrich
wants to merge
3
commits into
master
Choose a base branch
from
week4-2
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <TargetFramework>netcoreapp2.1</TargetFramework> | ||
| </PropertyGroup> | ||
|
|
||
| </Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| using System; | ||
|
|
||
|
|
||
| public class Program | ||
| { | ||
|
|
||
| public static void Main() | ||
| { | ||
| // instantiating a new instance of person, and passing names to the constructor; | ||
| Person Jill = new Person("Jill"); | ||
| Person Chris = new Person("Chris"); | ||
| Person Rebecca = new Person("Rebecca"); | ||
| Person Barry = new Person("Barry"); | ||
|
|
||
| // instantiating a new instance of car, and passing colors to the constructor; | ||
| Car blueCar = new Car("blue"); | ||
| Car redCar = new Car("red"); | ||
| Car greenCar = new Car("green"); | ||
| Car whiteCar = new Car("white"); | ||
|
|
||
| //Assigning Persons names to cars | ||
| blueCar.Name = Jill.Name; | ||
| redCar.Name = Barry.Name; | ||
| greenCar.Name = Chris.Name; | ||
| whiteCar.Name = Rebecca.Name; | ||
|
|
||
| // instantiating a new instance of Garage class, and passing in a size of 4 to the constructor; | ||
| Garage smallGarage = new Garage(4); | ||
|
|
||
| // calling a method Parkcar of the smallGarage instance, with inputs of car color and parking space | ||
| smallGarage.ParkCar(blueCar, 0); | ||
| smallGarage.ParkCar(redCar, 1); | ||
| smallGarage.ParkCar(greenCar, 2); | ||
| smallGarage.ParkCar(whiteCar, 3); | ||
|
|
||
| // printint out the cars attribute of the small garage | ||
| Console.WriteLine(smallGarage.Cars); | ||
| } | ||
| } | ||
|
|
||
| class Car | ||
| { | ||
| // once the color is set i cant change it, outisde of this class | ||
| public string Color {get; private set;} | ||
|
|
||
| // Name can be set outside of class | ||
| public string Name{get; set;} | ||
|
|
||
| // Car constructor | ||
| public Car(String color) | ||
| { | ||
| this.Color = color; | ||
| } | ||
| } | ||
|
|
||
| class Person | ||
| { | ||
| //attribute for persons name | ||
| public string Name { get; private set;} | ||
|
|
||
| //Person constructor | ||
| public Person(string name){ | ||
| this.Name = name; | ||
| } | ||
| } | ||
|
|
||
| class Garage | ||
| { | ||
| // creates array of cars so they can be parked in the for loop down below | ||
| public Car[] cars; | ||
|
|
||
| // constructor , int of initial size | ||
| public Garage(int initialSize) | ||
| { | ||
| // setting the size of this garage | ||
| Size = initialSize; | ||
| // instantiating an array of Cars, of size initialsize | ||
| this.cars = new Car[initialSize]; | ||
| } | ||
|
|
||
| //attribute , private for number of slots in the garage. | ||
| public int Size { get; private set; } | ||
|
|
||
| // a method that adds a car to the spot in the cars array | ||
| public void ParkCar (Car car, int spot) | ||
| { | ||
| // what if there is a car already in the spot? | ||
| // what if the spot passed in is outside the array? | ||
| cars[spot] = car; | ||
| } | ||
| public string Cars { | ||
| get { | ||
| String carsString = ""; | ||
| //parks cars in spot | ||
| for (int i = 0; i < cars.Length; i++) | ||
| { | ||
| if (cars[i] != null) { | ||
| carsString += String.Format("{2}'s {0} car is in spot {1}.", cars[i].Color, i, cars[i].Name); | ||
| carsString += "\n"; | ||
| } | ||
| } | ||
| return carsString; | ||
| } | ||
| } | ||
| } | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <TargetFramework>netcoreapp2.1</TargetFramework> | ||
| </PropertyGroup> | ||
|
|
||
| </Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
|
|
||
| namespace Gradebook | ||
| { | ||
| class Program | ||
| { | ||
| public static void Main() | ||
| { | ||
| Gradebook book = new Gradebook(); | ||
| book.run(); | ||
| } | ||
| } | ||
|
|
||
| //Creates dictionary with name as key and a list of grades as values. | ||
| class book{ | ||
| Dictionary<string, Value> grades = new Dictionary<string,Value>(); | ||
| } | ||
|
|
||
| class Gradebook | ||
| { | ||
|
|
||
| public void run(){ | ||
| Gradebook.getUserInput(new Dictionary<string, List<int>>()); | ||
| } | ||
|
|
||
| public static void getUserInput(Dictionary<string, List<int>> grades){ | ||
| string status = "y"; | ||
|
|
||
| //promts user to add name that is added as key in dictionary. Then | ||
| while (status != "n" && status != "no") | ||
| { | ||
| //prompts user to add name | ||
| Console.WriteLine("Please enter student name:"); | ||
| string name = Console.ReadLine(); | ||
| //runs loop to ask user for grades | ||
| List<int> gradeList = Value.Add(); | ||
| //adds name and list of grades to dictionary | ||
| grades.Add(name,gradeList); | ||
| //asks user if they want to add another student thus repeating this while loop. | ||
| Console.WriteLine("Would you like to enter a new student?(Y/N)"); | ||
| status = Console.ReadLine().ToLower(); | ||
| } | ||
| //Writes each sudents Name, grade average, max grade, and min grade. | ||
| foreach (var key in grades.Keys) | ||
| { | ||
| Console.WriteLine("Name: " + key); | ||
| Console.WriteLine("Average: " +grades[key].Average()); | ||
| Console.WriteLine("Max: " + grades[key].Max()); | ||
| Console.WriteLine("Minimum: " + grades[key].Min()); | ||
| } | ||
| } | ||
| } | ||
| class Value | ||
| { | ||
| //promts user to add grade and if they want to keep adding grades. Then returns the grades. | ||
| public static List<int> Add() | ||
| { | ||
| var grades = new List<int>(); | ||
| string keepAdding = "y"; | ||
| while (keepAdding != "n"&&keepAdding != "no") | ||
| { | ||
| //prompts user for grade then adds input to list | ||
| Console.WriteLine("Please enter a grade:"); | ||
| grades.Add(Convert.ToInt16(Console.ReadLine())); | ||
| //asks user if they want to keep adding grades | ||
| Console.WriteLine("Keep adding grades?(Y/N)"); | ||
| keepAdding = Console.ReadLine().ToLower(); | ||
| } | ||
| return grades; | ||
| } | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like where you were going with this.