Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace College_Classes
- {
- class Program
- {
- static void Main(string[] args)
- {
- string[] billsNames = new string[0];
- int[] billsPayments = new int[0];
- int option = 0;
- do
- {
- Console.WriteLine("1. Print Bills\n2. Add Bill\n3. Get bill payment by bill name\n4. Average payment\n5. Print max bill payment\n6. Remove Bill\n7. Exit");
- option = int.Parse(Console.ReadLine());
- if(option >= 1 && option <= 7 && option != 2 && option != 7 && billsNames.Length == 0)
- {
- Console.WriteLine("You don't have any bills");
- Console.ReadKey();
- Console.Clear();
- continue;
- }
- if(option == 1) // Print Bills
- {
- PrintBills(billsNames, billsPayments);
- }
- else if (option == 2) // Add Bill
- {
- billsNames = ModifiedStringArray(billsNames, 1);
- billsPayments = ModifiedIntegerArray(billsPayments, 1);
- Console.Write("Please enter a new bill name: ");
- billsNames[billsNames.Length - 1] = Console.ReadLine();
- Console.Write($"Please enter {billsNames[billsNames.Length -1]}'(s) payment: ");
- billsPayments[billsPayments.Length - 1] = int.Parse(Console.ReadLine());
- PrintBills(billsNames, billsPayments);
- }
- else if (option == 3) // Find Bill by Name
- {
- Console.Write("Please enter the bill's name: ");
- string tmpstr = Console.ReadLine();
- bool found = false;
- for (int i = 0; i < billsNames.Length; i++)
- {
- if (tmpstr == billsNames[i])
- {
- PrintBills(billsNames, billsPayments, i);
- found = true;
- }
- }
- if (found == false) Console.WriteLine($"The bill \"{tmpstr}\" was not found!");
- }
- else if (option == 4) // Average Bill Payment
- {
- double sum = 0;
- for (int i = 0; i < billsPayments.Length; i++)
- {
- sum += billsPayments[i];
- }
- sum /= billsPayments.Length;
- Console.WriteLine($"Average bill payment: {sum}");
- }
- else if (option == 5) // Maximum Value Bill
- {
- int max = 0, maxSlot = 0;
- for (int i = 0; i < billsPayments.Length; i++)
- {
- if(billsPayments[i] > max)
- {
- max = billsPayments[i];
- maxSlot = i;
- }
- }
- Console.WriteLine($"Max bill: {billsNames[maxSlot]} (${billsPayments[maxSlot]})");
- }
- else if (option == 6) // Delete Bill
- {
- Console.Write("Please enter the name of the bill you'd like to delete: ");
- string tmpstr = Console.ReadLine();
- bool found = false;
- for (int i = 0; i < billsNames.Length; i++)
- {
- if (tmpstr == billsNames[i])
- {
- Console.WriteLine($"The bill \"{billsNames[i]}\" (${billsPayments[i]}) has been deleted!");
- billsNames[i] = "";
- billsPayments[i] = 0;
- billsNames = ModifiedStringArray(billsNames, -1);
- billsPayments = ModifiedIntegerArray(billsPayments, -1);
- found = true;
- }
- }
- if (found == false) Console.WriteLine($"The bill \"{tmpstr}\" was not found!");
- }
- else if (option == 7) // Exit
- {
- Console.WriteLine("Exiting...");
- }
- else Console.WriteLine("Stop cuasing troubles, pick 1 to 7.");
- Console.ReadKey();
- Console.Clear();
- }
- while (option != 7);
- }
- static void PrintBills(string[] bNames, int[] bPayments, int slotid = -1)
- {
- if (slotid != -1) Console.WriteLine($"Bill Name: {bNames[slotid]}, Amount: {bPayments[slotid]}");
- else for(int i = 0; i < bNames.Length; i++) Console.WriteLine($"Bill Name: {bNames[i]}, Amount: {bPayments[i]}");
- }
- static string[] ModifiedStringArray(string[] array, int size)
- {
- string[] tmpstr = new string[array.Length + size];
- int emptyCount = 0;
- for (int i = 0; i < array.Length; i++)
- {
- if (array[i] == "")
- {
- emptyCount++;
- continue;
- }
- tmpstr[i-emptyCount] = array[i];
- }
- return tmpstr;
- }
- static int[] ModifiedIntegerArray(int[] array, int size)
- {
- int[] tmpint = new int[array.Length + size];
- int emptyCount = 0;
- for (int i = 0; i < array.Length; i++)
- {
- if(array[i] == 0)
- {
- emptyCount++;
- continue;
- }
- tmpint[i-emptyCount] = array[i];
- }
- return tmpint;
- }
- }
- }
Add Comment
Please, Sign In to add comment