Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace Eget_Projekt
- {
- class Program
- {
- static void timeAndDate() //Metod för datum och tid.
- {
- DateTime time = DateTime.Now; //Hämtar datum och tid.
- Console.WriteLine("\n\tDate and time: " + time); //Skriver ut datum och tid.
- }
- static void introMenu() //Metod för intro texten när man startar programmet.
- {
- Console.Write("\n\t|--------------------------------------------------|");
- Console.WriteLine("\n\t\tWelcome to my little project." +
- "\n\t\tThis program will work as a diary." +
- "\n\t\tPlease, choose an option to continue.");
- Console.Write("\n\t|--------------------------------------------------|");
- }
- static void mainMenu() //Metod för huvudmenyn som innehåller alla valen.
- {
- //Valde att skriva programmet på engelska då flera
- Console.WriteLine("\n\t[1] Make a new entry." + //användare kan använda programmet.
- "\n\t[2] Print out all entries." +
- "\n\t[3] Print out all titles." +
- "\n\t[4] Search for previous entries." +
- "\n\t[5] Search for previous titles." +
- "\n\t[6] Remove an existing entry." +
- "\n\t[7] Exit program.");
- }
- static void Main(string[] args)
- {
- Console.BackgroundColor = ConsoleColor.DarkRed;
- Console.Clear();
- List<string> entries = new List<string>(); //Lista för att hålla reda på inlägg.
- List<string> titles = new List<string>(); //Lista för att hålla reda på titlar.
- List<string[]> choice = new List<string[]>(); //Lista med sträng variabel kombinerad med en array.
- string[] post = new string[2];
- post[0] = "Title";
- post[1] = "Entry";
- timeAndDate(); //Anropar min metod som innehåller tid och datum.
- introMenu(); //Anropar min metod som innehåller intro texten.
- bool isRunning = true;
- while (isRunning)
- {
- mainMenu(); //Anropar min metod som innehåller huvudmenyn.
- int nr; //Standard int variabel.
- int.TryParse(Console.ReadLine(), out nr); //Felhantering av variabel.
- switch (nr) //Switch sats som innehåller "nr" variabeln som är definierad ovanför.
- {
- case 1:
- Console.Write("\n\tEnter a title for your new entry: "); //Case för att spara titel och huvudtext.
- titles.Add(Console.ReadLine()); //Använder .ReadLine för att lägga till i listan.
- Console.Write("\n\tWrite an entry: ");
- entries.Add(Console.ReadLine());
- break;
- case 2:
- Console.WriteLine("\n\tEntries that are currently saved: "); //Case för att skriva ut tidigare sparade huvudtexter.
- for (int i = 0; i < entries.Count; i++) //for-loop för att skriva ut sparade inputs i "entries".
- {
- Console.WriteLine("\t " + entries[i]);
- Console.ReadKey();
- }
- break;
- case 3:
- Console.WriteLine("\n\tTitles that are currently saved: "); //Case för att skriva ut tidigare sparade titlar.
- for (int i = 0; i < titles.Count; i++) //for-loop för att skriva ut sparade inputs i "titles".
- {
- Console.WriteLine("\t " + titles[i]);
- Console.ReadKey();
- }
- break;
- case 4:
- Console.Write("\tEntry search: "); //Case för att söka efter huvudtexter.
- string entrySearch = Console.ReadLine();
- bool entryFound = true; //bool-variabel för att kolla efter true/false.
- for (int i = 0; i < entries.Count; i++)
- {
- if (entries[i].ToUpper().Contains(entrySearch.ToUpper())) //Använder .Contains för att kunna leta efter specifika texter.
- {
- Console.WriteLine("\tThis is what I could find: " + entries[i]);
- entryFound = false; //Om texten finns så blir "entryFound" false och man skippar if-satsen.
- Console.Write("\tPress any key to return to main menu.");
- Console.ReadKey();
- }
- }
- if (entryFound == true) //if-sats som aktiveras om "entryFound" fortfarande är true.
- {
- Console.WriteLine("\tI could not find what you were looking for.");
- Console.Write("\tPress any key to return to main menu."); //Text som visas om man inte skulle hitta något via sökfunktionen.
- Console.ReadKey();
- }
- break;
- case 5:
- Console.Write("\tTitle search: "); //Case för att söka efter titlar.
- string titleSearch = Console.ReadLine();
- bool titleFound = true; //bool-variabel för att kolla efter true/false.
- for (int i = 0; i < titles.Count; i++) //Allting är identiskt till case 4 förutom att
- { //entry/entries är title/titles.
- if (titles[i].ToUpper().Contains(titleSearch.ToUpper()))
- {
- Console.WriteLine("\tThis is what I could find: " + titles[i]);
- titleFound = false;
- Console.Write("\tPress any key to return to main menu.");
- Console.ReadKey();
- }
- }
- if (titleFound == true)
- {
- Console.WriteLine("\tI could not find what you wre looking for.");
- Console.Write("\tPress any key to return to main menu.");
- Console.ReadKey();
- }
- break;
- case 6:
- {
- break;
- }
- case 7:
- {
- Console.WriteLine("\n\tThank you for using my program, have a nice day!");
- isRunning = false;
- break;
- }
- default:
- break;
- }
- }
- Console.ReadLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement