I need this code, to show ALL inventory items, then with the remove button, remove one of them
at a time, and the add button to add it back, and the restock button to reset the inventory items to
show all of them again. EVERYTHING IS WITH BUTTONS So it should look like this when
you hit the show button:
Make = "Ford",
Model = "Mustang",
Year = 2020,
MilesPerGallon = 22,
HorsePower = 450,
CarPrice = 35000,
Quantity = 5
Make = "Dodge",
Model = "Charger",
Year = 2018,
MilesPerGallon = 19,
HorsePower = 292,
CarPrice = 28000,
Quantity = 2
public partial class Form1 : Form
{
Car car = new Car();
Driver driver = new Driver();
InventoryManager manager;
int latestCarIndex = -1;
public Form1(InventoryManager invMan)
{
InitializeComponent();
manager = invMan;
}
private void btnShow_Click(object sender, EventArgs e)
{
if (manager.inventory.Count > 0 && latestCarIndex >= 0)
{
Car latestCar = manager.inventory[manager.inventory.Count - 1]; carTextBox.Text =
"Car make is " + latestCar.Make + "rn"
+ "Car Model is: " + latestCar.Model + "rn"
+ "Car Year is: " + latestCar.Year + "rn"
+ "Car Miles Per Gallon is: " + latestCar.MilesPerGallon + "rn"
+ "Car Horse Power is: " + latestCar.HorsePower + "rn"
+ "Quantity of cars in stock is: " + latestCar.Quantity + "rn";
}
}
int numAddedCars = 0;
int numRemovedCars = 0;
public void btnAdd_Click(object sender, EventArgs e)
{
// Create a new instance of the Car class with the desired attributes
Car newCar = new Car()
{
Make = "Chevy",
Model = "Corvette",
Year = 2022,
MilesPerGallon = 30,
HorsePower = 500,
Quantity = 1
};
manager.AddItem(newCar);
latestCarIndex = manager.inventory.Count - 1;
btnShow_Click(sender, e);
Car latestCar = manager.inventory[manager.inventory.Count - 1];
btnShow_Click(sender, e);
}
private void removeItemButton_Click(object sender, EventArgs e)
{
if (latestCarIndex >= 0)
{
Car latestCar = manager.inventory[latestCarIndex];
manager.RemoveItem(latestCar);
latestCarIndex--;
if (latestCarIndex >= 0)
{
btnShow_Click(sender, e);
}
}
class Driver
{
static void Main(string[] args)
{
InventoryManager manager = new InventoryManager(10);
Boolean windowOpen = true;
manager.AddItem(new Car()
{
Make = "Ford",
Model = "Mustang",
Year = 2020,
MilesPerGallon = 22,
HorsePower = 450,
CarPrice = 35000,
Quantity = 5
});
manager.AddItem(new Car()
{
Make = "Chevrolet",
Model = "Camaro",
Year = 2019,
MilesPerGallon = 20,
HorsePower = 455,
CarPrice = 32000,
Quantity = 3
});
manager.AddItem(new Car()
{
Make = "Dodge",
Model = "Charger",
Year = 2018,
MilesPerGallon = 19,
HorsePower = 292,
CarPrice = 28000,
Quantity = 2
});
manager.DisplayItems();
Car dodgeCharger = new Car()
{
Make = "Dodge",
Model = "Charger",
Year = 2018,
MilesPerGallon = 19,
HorsePower = 292,
CarPrice = 28000,
Quantity = 2
};
manager.RemoveItem(dodgeCharger);
manager.DisplayItems();
Car fordMustang = new Car()
{
Make = "Ford",
Model = "Mustang",
Year = 2020,
MilesPerGallon = 22,
HorsePower = 450,
CarPrice = 35000,
Quantity = 5
};
manager.RestockItem(fordMustang, 2);
manager.DisplayItems();
Car[] searchResults = manager.SearchItemByName("Mustang");
foreach (Car car in searchResults)
{
Console.WriteLine("Make: " + car.Make + ", Model: " + car.Model);
}
searchResults = manager.SearchItemByPrice(35000);
foreach (Car car in searchResults)
{
Console.WriteLine("Make: " + car.Make + ", Model: " + car.Model + ", Price: " +
car.CarPrice);
}
}
public class InventoryManager
{
public List inventory;
public InventoryManager(int size)
{
//inventory = new Car[size]; Replacing for a list
inventory = new List(size);
}
public void AddItem(Car item)
{
inventory.Add(item);
}
public void RemoveItem(Car item)
{
inventory.Remove(item);
}
public void RestockItem(Car item, int quantity)
{
Car existingItem = inventory.Find(i => i.Equals(item));
if (existingItem != null)
{
existingItem.Quantity += quantity;
}
}
public void DisplayItems()
{
foreach (Car item in inventory)
{
Console.WriteLine("Make: " + item.Make +
", Model: " + item.Model + ", Year: "
+ item.Year + ", MilesPerGallon: " +
item.MilesPerGallon + ", HorsePower: "
+ item.HorsePower);
}
}
public Car[] SearchItemByName(string name)
{
List result = new List();
foreach (Car item in inventory)
{
if (item != null && item.Make.ToLower().Contains(name.ToLower()))
{
result.Add(item);
}
}
return result.ToArray();
}
public Car[] SearchItemByPrice(int CarPrice)
{
List result = new List();
foreach (Car item in inventory)
{
if (item != null && item.CarPrice == CarPrice)
{
result.Add(item);
}
}
return result.ToArray();
}
public class Car
{
public string Make { get; set; }
public string Model { get; set; }
public int Year { get; set; }
public int MilesPerGallon { get; set; }
public int HorsePower { get; set; }
public double CarPrice { get; set; }
public int Quantity { get; internal set; }

I need this code, to show ALL inventory items, then with the remove .pdf

  • 1.
    I need thiscode, to show ALL inventory items, then with the remove button, remove one of them at a time, and the add button to add it back, and the restock button to reset the inventory items to show all of them again. EVERYTHING IS WITH BUTTONS So it should look like this when you hit the show button: Make = "Ford", Model = "Mustang", Year = 2020, MilesPerGallon = 22, HorsePower = 450, CarPrice = 35000, Quantity = 5 Make = "Dodge", Model = "Charger", Year = 2018, MilesPerGallon = 19, HorsePower = 292, CarPrice = 28000, Quantity = 2 public partial class Form1 : Form { Car car = new Car(); Driver driver = new Driver(); InventoryManager manager; int latestCarIndex = -1; public Form1(InventoryManager invMan) { InitializeComponent(); manager = invMan; } private void btnShow_Click(object sender, EventArgs e) { if (manager.inventory.Count > 0 && latestCarIndex >= 0) {
  • 2.
    Car latestCar =manager.inventory[manager.inventory.Count - 1]; carTextBox.Text = "Car make is " + latestCar.Make + "rn" + "Car Model is: " + latestCar.Model + "rn" + "Car Year is: " + latestCar.Year + "rn" + "Car Miles Per Gallon is: " + latestCar.MilesPerGallon + "rn" + "Car Horse Power is: " + latestCar.HorsePower + "rn" + "Quantity of cars in stock is: " + latestCar.Quantity + "rn"; } } int numAddedCars = 0; int numRemovedCars = 0; public void btnAdd_Click(object sender, EventArgs e) { // Create a new instance of the Car class with the desired attributes Car newCar = new Car() { Make = "Chevy", Model = "Corvette", Year = 2022, MilesPerGallon = 30, HorsePower = 500, Quantity = 1 }; manager.AddItem(newCar); latestCarIndex = manager.inventory.Count - 1; btnShow_Click(sender, e); Car latestCar = manager.inventory[manager.inventory.Count - 1]; btnShow_Click(sender, e); } private void removeItemButton_Click(object sender, EventArgs e) { if (latestCarIndex >= 0) { Car latestCar = manager.inventory[latestCarIndex]; manager.RemoveItem(latestCar); latestCarIndex--;
  • 3.
    if (latestCarIndex >=0) { btnShow_Click(sender, e); } } class Driver { static void Main(string[] args) { InventoryManager manager = new InventoryManager(10); Boolean windowOpen = true; manager.AddItem(new Car() { Make = "Ford", Model = "Mustang", Year = 2020, MilesPerGallon = 22, HorsePower = 450, CarPrice = 35000, Quantity = 5 }); manager.AddItem(new Car() { Make = "Chevrolet", Model = "Camaro", Year = 2019, MilesPerGallon = 20, HorsePower = 455, CarPrice = 32000, Quantity = 3 }); manager.AddItem(new Car() { Make = "Dodge", Model = "Charger", Year = 2018,
  • 4.
    MilesPerGallon = 19, HorsePower= 292, CarPrice = 28000, Quantity = 2 }); manager.DisplayItems(); Car dodgeCharger = new Car() { Make = "Dodge", Model = "Charger", Year = 2018, MilesPerGallon = 19, HorsePower = 292, CarPrice = 28000, Quantity = 2 }; manager.RemoveItem(dodgeCharger); manager.DisplayItems(); Car fordMustang = new Car() { Make = "Ford", Model = "Mustang", Year = 2020, MilesPerGallon = 22, HorsePower = 450, CarPrice = 35000, Quantity = 5 }; manager.RestockItem(fordMustang, 2); manager.DisplayItems(); Car[] searchResults = manager.SearchItemByName("Mustang"); foreach (Car car in searchResults) { Console.WriteLine("Make: " + car.Make + ", Model: " + car.Model); } searchResults = manager.SearchItemByPrice(35000);
  • 5.
    foreach (Car carin searchResults) { Console.WriteLine("Make: " + car.Make + ", Model: " + car.Model + ", Price: " + car.CarPrice); } } public class InventoryManager { public List inventory; public InventoryManager(int size) { //inventory = new Car[size]; Replacing for a list inventory = new List(size); } public void AddItem(Car item) { inventory.Add(item); } public void RemoveItem(Car item) { inventory.Remove(item); } public void RestockItem(Car item, int quantity) { Car existingItem = inventory.Find(i => i.Equals(item)); if (existingItem != null) { existingItem.Quantity += quantity; } } public void DisplayItems() { foreach (Car item in inventory) { Console.WriteLine("Make: " + item.Make + ", Model: " + item.Model + ", Year: "
  • 6.
    + item.Year +", MilesPerGallon: " + item.MilesPerGallon + ", HorsePower: " + item.HorsePower); } } public Car[] SearchItemByName(string name) { List result = new List(); foreach (Car item in inventory) { if (item != null && item.Make.ToLower().Contains(name.ToLower())) { result.Add(item); } } return result.ToArray(); } public Car[] SearchItemByPrice(int CarPrice) { List result = new List(); foreach (Car item in inventory) { if (item != null && item.CarPrice == CarPrice) { result.Add(item); } } return result.ToArray(); } public class Car { public string Make { get; set; } public string Model { get; set; } public int Year { get; set; } public int MilesPerGallon { get; set; }
  • 7.
    public int HorsePower{ get; set; } public double CarPrice { get; set; } public int Quantity { get; internal set; }