Advertisement
Guest User

FuelGauge

a guest
Dec 9th, 2019
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace A5
  8. {
  9. class FuelGauge
  10. {
  11.  
  12. private static double fuel = 0;
  13.  
  14. public static double getFuel()
  15. {
  16. return fuel;
  17. }
  18. public static void setFuel()
  19. {
  20. bool invalid = true;
  21. double n = 0;
  22.  
  23. while (invalid)
  24. {
  25. try
  26. {
  27. Console.WriteLine("How much fuel do you want to add?");
  28. n = int.Parse(Console.ReadLine());
  29.  
  30. double total = fuel + n;
  31.  
  32. if (total > 60)
  33. {
  34. fuel = 60;
  35. Console.WriteLine("Added 60L of fuel");
  36. invalid = false;
  37. } else if (n <= 0)
  38. {
  39. Console.WriteLine("You need to add more gas, 0 L is not allowed!");
  40. }
  41. else
  42. {
  43. fuel = n;
  44. invalid = false;
  45. Console.WriteLine("Added " + n + "L of fuel");
  46. }
  47.  
  48. } catch (Exception ex)
  49. {
  50. Console.WriteLine(ex.Message);
  51. }
  52. }
  53. }
  54. public static bool checkGas()
  55. {
  56. if (fuel >= .12)
  57. {
  58. fuel = fuel - .12;
  59. return true;
  60. }
  61. else
  62. {
  63. Console.WriteLine("Out of fuel... please add fuel!");
  64. return false;
  65. }
  66. }
  67. }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement