Change Lesson 3 Task 1 to remove goto
This commit is contained in:
parent
1380c6a583
commit
60f5d40b8d
2 changed files with 36 additions and 35 deletions
|
@ -65,6 +65,39 @@ class Computer
|
||||||
Price = motherboard.Price;
|
Price = motherboard.Price;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void HardwareSelection(int money)
|
||||||
|
{
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
int choice;
|
||||||
|
Console.WriteLine("RAMs [1]\nCPUs [2]\nGPUs [3]\nDrives [4]\nCheckout [5]\nQuit [6]");
|
||||||
|
Console.Write("Enter a number: ");
|
||||||
|
if (int.TryParse(Console.ReadLine(), out choice))
|
||||||
|
{
|
||||||
|
switch (choice)
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
(new RamMethods()).DisplayRamList(this, (new RamsForSale()).Hardware);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
(new CpuMethods()).DisplayCpuList(this, (new CpusForSale()).Hardware);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
(new GpuMethods()).DisplayGpuList(this, (new GpusForSale()).Hardware);
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
(new DriveMethods()).DisplayDriveList(this, (new DrivesForSale()).Hardware);
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
Checkout(money);
|
||||||
|
break;
|
||||||
|
case 6:
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void Checkout(int money)
|
public void Checkout(int money)
|
||||||
{
|
{
|
||||||
while (true)
|
while (true)
|
||||||
|
@ -80,6 +113,7 @@ class Computer
|
||||||
Console.WriteLine("You cannot afford this computer.");
|
Console.WriteLine("You cannot afford this computer.");
|
||||||
|
|
||||||
Console.WriteLine("Remove RAMs [1]\nRemove CPUs [2]\nRemove GPUs [3]\nRemove Drives [4]\nReplace motherboard (removes everything else) [5]\nGo back [6]");
|
Console.WriteLine("Remove RAMs [1]\nRemove CPUs [2]\nRemove GPUs [3]\nRemove Drives [4]\nReplace motherboard (removes everything else) [5]\nGo back [6]");
|
||||||
|
Console.Write("Enter a number: ");
|
||||||
if (int.TryParse(Console.ReadLine(), out choice))
|
if (int.TryParse(Console.ReadLine(), out choice))
|
||||||
{
|
{
|
||||||
switch (choice)
|
switch (choice)
|
||||||
|
@ -101,12 +135,10 @@ class Computer
|
||||||
this.Replace(motherboard);
|
this.Replace(motherboard);
|
||||||
break;
|
break;
|
||||||
case 6:
|
case 6:
|
||||||
goto Back;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Back:
|
|
||||||
Console.WriteLine("Going back…");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Computer(Motherboard motherboard)
|
public Computer(Motherboard motherboard)
|
||||||
|
|
|
@ -15,35 +15,4 @@ Console.WriteLine("Choose a motherboard first.");
|
||||||
Motherboard motherboard = (new MotherboardMethods()).DisplayMotherboardList();
|
Motherboard motherboard = (new MotherboardMethods()).DisplayMotherboardList();
|
||||||
Computer computer = new Computer(motherboard);
|
Computer computer = new Computer(motherboard);
|
||||||
|
|
||||||
while (true)
|
computer.HardwareSelection(money);
|
||||||
{
|
|
||||||
int choice;
|
|
||||||
Console.WriteLine("RAMs [1]\nCPUs [2]\nGPUs [3]\nDrives [4]\nCheckout [5]\nQuit [6]");
|
|
||||||
Console.Write("Enter a number: ");
|
|
||||||
if (int.TryParse(Console.ReadLine(), out choice))
|
|
||||||
{
|
|
||||||
switch (choice)
|
|
||||||
{
|
|
||||||
case 1:
|
|
||||||
(new RamMethods()).DisplayRamList(computer, (new RamsForSale()).Hardware);
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
(new CpuMethods()).DisplayCpuList(computer, (new CpusForSale()).Hardware);
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
(new GpuMethods()).DisplayGpuList(computer, (new GpusForSale()).Hardware);
|
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
(new DriveMethods()).DisplayDriveList(computer, (new DrivesForSale()).Hardware);
|
|
||||||
break;
|
|
||||||
case 5:
|
|
||||||
computer.Checkout(money);
|
|
||||||
break;
|
|
||||||
case 6:
|
|
||||||
goto Exit;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Exit:
|
|
||||||
Console.WriteLine("Goodbye.");
|
|
||||||
|
|
Reference in a new issue