Advertisement
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 A5
- {
- class FuelGauge
- {
- private static double fuel = 0;
- public static double getFuel()
- {
- return fuel;
- }
- public static void setFuel()
- {
- bool invalid = true;
- double n = 0;
- while (invalid)
- {
- try
- {
- Console.WriteLine("How much fuel do you want to add?");
- n = int.Parse(Console.ReadLine());
- double total = fuel + n;
- if (total > 60)
- {
- fuel = 60;
- Console.WriteLine("Added 60L of fuel");
- invalid = false;
- } else if (n <= 0)
- {
- Console.WriteLine("You need to add more gas, 0 L is not allowed!");
- }
- else
- {
- fuel = n;
- invalid = false;
- Console.WriteLine("Added " + n + "L of fuel");
- }
- } catch (Exception ex)
- {
- Console.WriteLine(ex.Message);
- }
- }
- }
- public static bool checkGas()
- {
- if (fuel >= .12)
- {
- fuel = fuel - .12;
- return true;
- }
- else
- {
- Console.WriteLine("Out of fuel... please add fuel!");
- return false;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement