Car Engine And Tires
Здравейте, изкарвам 66/100, а следвам инструкциите.
Problem 4. Car Engine and Tires
Using the Car class, you already created, define another class Engine.
The class should have private fields for:
- horsePower: int
- cubicCapacity: double
The class should also have properties for:
- HorsePower: int
- CubicCapacity: double
The class should also have a constructor, which accepts horsepower and cubicCapacity upon initialization:
Now create a class Tire.
The class should have private fields for:
- year: int
- pressure: double
The class should also have properties for:
- Year: int
- Pressure: double
The class should also have a constructor, which accepts year and pressure upon initialization:
Finally, go to the Car class and create private fields and public properties for Engine and Tire[].Create another constructor, which accepts make, model, year, fuelQuantity, fuelConsumption, Engine and Tire[] upon initialization:
namespace CarManufacturer
{
public class StartUp
{
public static void Main(string[] args)
{
Tire[] tires = new Tire[4]
{
new Tire(1, 2.5),
new Tire(1, 2.1),
new Tire(2, 0.5),
new Tire(2, 2.3),
};
Engine engine = new Engine(560, 6300);
Car car = new Car("Lamborghini", "Urus", 2010, 250, 9, engine, tires);
}
}
}
using System;
using System.Text;
namespace CarManufacturer
{
public class Car
{
private string make;
private string model;
private int year;
private double fuelQuantity;
private double fuelConsumption;
private Engine engine;
private Tire pressure;
public string Make { get; set; }
public string Model { get; set; }
public int Year { get; set; }
public double FuelQuantity { get; set; }
public double FuelConsumption { get; set; }
public Engine Engine { get; set; }
public Tire[] Pressure { get; set; }
public Car()
{
this.Make = "VW";
this.Model = "Golf";
this.Year = 2025;
this.FuelQuantity = 200;
this.FuelConsumption = 10;
}
public Car(string make, string model, int year) : this()
{
this.Make = make;
this.Model = model;
this.Year = year;
}
public Car(string make, string model, int year, double fuelQuantity, double fuelConsumption) : this(make, model, year)
{
this.FuelQuantity = fuelQuantity;
this.FuelConsumption = fuelConsumption;
}
public Car(string make, string model, int year, double fuelQuantity, double fuelConsumption, Engine engine, Tire[] tires)
: this(make, model, year, fuelQuantity, fuelConsumption)
{
this.Engine = engine;
this.Pressure = tires;
}
public void Drive(double distance)
{
double fuel = FuelConsumption * distance / 100;
if (fuel > FuelQuantity)
{
Console.WriteLine("Not enough fuel to perform this trip!");
}
else
{
FuelQuantity -= fuel;
}
}
public string WhoAmI()
{
StringBuilder print = new StringBuilder();
print.AppendLine($"Make: {this.Make}");
print.AppendLine($"Model: {this.Model}");
print.AppendLine($"Year: {this.Year}");
print.Append($"Fuel: {this.FuelQuantity:f2}L");
return print.ToString();
}
}
}
namespace CarManufacturer
{
public class Engine
{
private int horsePower;
private double cubicCapacity;
public int HorsePower { get; set; }
public double CubicCapacity { get; set; }
public Engine(int horsePower, double cubicCapacity)
{
this.HorsePower = horsePower;
this.CubicCapacity = cubicCapacity;
}
}
}
namespace CarManufacturer
{
public class Tire
{
private int year;
private double pressure;
public int Year { get; set; }
public double Pressure { get; set; }
public Tire(int year, double pressure)
{
this.Year = year;
this.Pressure = pressure;
}
}
}
Ако може помощ.
Благодаря!
За тази задача Виктор Даков каза, че Джъдж иска, както е написано в лаба, така да се подаде и че се гледа само в класовете, a в StartUp.cs няма нужда да има нищо.
Моята грешка беше правописна HorsepPower - и бам 66/100
Твоята мисля, че е Tier[] Pressure => трябва да е Tires.