static void Main(string[] args) { Odometer trip1 = new Odometer(); trip1.SetMiles(50); trip1.SetFuelUsed(10); trip1.AddValues(10, 10); Console.WriteLine(trip1.GetMiles()); Console.WriteLine(trip1.GetFuelUsed()); Console.WriteLine(trip1.MilesPerGallon()); trip1.Reset(); Console.WriteLine(trip1.ToString()); Odometer trip2 = new Odometer(100, 25); Console.WriteLine(trip2); Console.WriteLine(trip2.MilesPerGallon()); Odometer trip3 = new Odometer(100, 25); Console.WriteLine(trip1.Equals(trip2)); Console.WriteLine(trip2.Equals(trip3)); }
static void Main(string[] args) { Odometer trip1 = new Odometer(); trip1.Add(55, 10); Console.WriteLine("fuel used for trip1 is: " + trip1.mpg()); Odometer trip2 = new Odometer(50, 10); trip1.Add(100, 20); Console.WriteLine("fuel used for trip2 is: " + trip2.mpg()); Console.WriteLine("This is trip1: " + trip1.toString()); Console.WriteLine("This is trip2: " + trip2.toString()); if (trip1.equals(trip2)) { Console.WriteLine("The two objects are the same"); } else { Console.WriteLine("The two objects are not the same"); } Console.WriteLine("This is the amount of miles per gallen: " + trip1.mpg()); Console.WriteLine("This is the amount of miles per gallen: " + trip2.mpg()); trip1.Reset(); Console.WriteLine(trip1.toString()); }
/// <summary> /// Check if two objects are the same /// </summary> /// <param name="odometer">Odometer object</param> /// <returns>True if equal</returns> public bool Equals(Odometer odometer) { return(miles == odometer.miles && fuelUsed == odometer.fuelUsed); }
public bool equals(Odometer other) { // return (this.miles == other.miles) && (this.fuelused == other.fuelused); return((this.Getmiles() == other.Getmiles()) && (this.Getfuelused() == other.Getfuelused())); }