SlideShare a Scribd company logo
I need to do the following:Add a new item to the inventory manager, Remove an item from the
inventory, Restock an item in the inventory, Display the items in the inventory, Search for an
item/items in the inventory by a variety of criteria. I believe my driver program does this with the
inventory manager, but now I need this to do it on the form application. I also need to Update the
inventory manager so that it uses a list to store inventory items instead of an array. Here are my
four pages of code in c# Visual studio: public partial class Form1:
{
Car car = new Car();
InventoryManager manager = new InventoryManager(10);
public Form1()
{
InitializeComponent();
}
private void btnShow_Click(object sender, EventArgs e)
{
Car car = new Car();
// Display all the cars in the inventory
manager.DisplayItems();
car.Make = "Challenger";
car.Model = "Dodge";
car.Year = 2019;
car.MilesPerGallon = 38;
car.HorsePower = 300;
car.CarPrice = 29000;
car.Quantity = 1;
carTextBox.Text += "Car make is " + car.Make + "rn"
+ "Car Model is: " + car.Model + "rn"
+ "Car Year is: " + car.Year + "rn"
+ "Car Miles Per Gallon is: " + car.MilesPerGallon + "rn"
+ "Car Horse Power is: " + car.HorsePower + "rn"
+ "Quantity of cars in stock is: " + car.Quantity;
}
private void hideBtn_Click(object sender, EventArgs e)
{
carTextBox.Text = String.Empty;
}
public void btnAdd_Click(object sender, EventArgs e)
{
// Display all the cars in the inventory
manager.DisplayItems();
}
private void removeItemButton_Click(object sender, EventArgs e)
{
}
private void restockItemButton_Click(object sender, EventArgs e)
{
}
private void searchPriceButton_Click(object sender, EventArgs e)
{
}
private void searchModelButton_Click(object sender, EventArgs e)
{
}
}
internal class Driver
{
static void Main(string[] args)
{
// Create an inventory manager with a capacity of 10 items
InventoryManager manager = new InventoryManager(10);
// Add some cars to the inventory
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
});
// Display all the cars in the inventory
manager.DisplayItems();
// Remove the Dodge Charger from the inventory
Car dodgeCharger = new Car()
{
Make = "Dodge",
Model = "Charger",
Year = 2018,
MilesPerGallon = 19,
HorsePower = 292,
CarPrice = 28000,
Quantity = 2
};
manager.RemoveItem(dodgeCharger);
// Display all the cars in the inventory again
manager.DisplayItems();
// Restock the Ford Mustang by 2 units
Car fordMustang = new Car()
{
Make = "Ford",
Model = "Mustang",
Year = 2020,
MilesPerGallon = 22,
HorsePower = 450,
CarPrice = 35000,
Quantity = 5
};
manager.RestockItem(fordMustang, 2);
// Display all the cars in the inventory again
manager.DisplayItems();
// Search for cars by name
Car[] searchResults = manager.SearchItemByName("Mustang");
foreach (Car car in searchResults)
{
Console.WriteLine("Make: " + car.Make + ", Model: " + car.Model);
}
// Search for cars by price
searchResults = manager.SearchItemByPrice(35000);
foreach (Car car in searchResults)
{
Console.WriteLine("Make: " + car.Make + ", Model: " + car.Model + ", Price: " + car.CarPrice);
}
Console.ReadLine();
}
}
internal class InventoryManager
{
private Car[] inventory;
public InventoryManager(int size)
{
inventory = new Car[size];
}
public void AddItem(Car item)
{
for (int i = 0; i < inventory.Length; i++)
{
if (inventory[i] == null)
{
inventory[i] = item;
break;
}
}
}
public void RemoveItem(Car item)
{
for (int i = 0; i < inventory.Length; i++)
{
if (inventory[i] == item)
{
inventory[i] = null;
break;
}
}
}
public void RestockItem(Car item, int quantity)
{
for (int i = 0; i < inventory.Length; i++)
{
if (inventory[i] == item)
{
inventory[i].Quantity += quantity;
break;
}
}
}
public void DisplayItems()
{
foreach (Car item in inventory)
{
if (item != null)
{
Console.WriteLine("Make: " + item.Make + ", Model: " + item.Model + ", Year: " + item.Year + ",
MilesPerGallon: " + item.MilesPerGallon + ", HorsePower: " + item.HorsePower);
}
}
}
public Car[] SearchItemByName(string name)
{
List<Car> result = new List<Car>();
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<Car> result = new List<Car>();
foreach (Car item in inventory)
{
if (item != null && item.CarPrice == CarPrice)
{
result.Add(item);
}
}
return result.ToArray();
}
}
internal 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; }
}

More Related Content

PDF
This is my visual studio C code how do I make it so that w.pdf
PDF
I need this code, to show ALL inventory items, then with the remove .pdf
PDF
In C#, visual studio, I want no more text boxes added, I have button.pdf
PPTX
The C# programming laguage delegates notes Delegates.pptx
PDF
C# Programming Help
PDF
Oop in java script
PDF
For the following questions, you will implement the data structure to.pdf
DOCX
Software Engineer Screening Question - OOP
This is my visual studio C code how do I make it so that w.pdf
I need this code, to show ALL inventory items, then with the remove .pdf
In C#, visual studio, I want no more text boxes added, I have button.pdf
The C# programming laguage delegates notes Delegates.pptx
C# Programming Help
Oop in java script
For the following questions, you will implement the data structure to.pdf
Software Engineer Screening Question - OOP

Similar to I need to do the followingAdd a new item to the inventory m.pdf (20)

PDF
[FEConf Korea 2017]Angular 컴포넌트 대화법
PPTX
Angular 2.0 Dependency injection
PDF
Angular2: Quick overview with 2do app example
PDF
Google App Engine in 40 minutes (the absolute essentials)
PDF
Assignment DIn Problem D1 we will use a file to contain the dat.pdf
PDF
publicclass VehicleParser {publicstatic Vehicle parseStringToVehic.pdf
PPTX
Classes and Objects In C# With Example
PDF
C#i need help creating the instance of stream reader to read from .pdf
PDF
Predicting model for prices of used cars
PPTX
Jan 2017 - a web of applications (angular 2)
PDF
#includeiostream #includecmath #includestringusing na.pdf
DOCX
#include iostream#include string#include iomanip#inclu.docx
PDF
How React Native, Appium and me made each other shine @Frontmania 16-11-2018
PDF
Scala Self Types by Gregor Heine, Principal Software Engineer at Gilt
PDF
Driverimport java.util.Scanner;A class that keeps a f.pdf
DOCX
srcCommissionCalculation.javasrcCommissionCalculation.javaimpo.docx
DOCX
#include iostream #include string #include fstream std.docx
PDF
29. Treffen - Tobias Meier - TypeScript
PDF
I have the first program completed (not how request, but it works) a.pdf
PPTX
How to Create a Custom Screen in Odoo 17 POS
[FEConf Korea 2017]Angular 컴포넌트 대화법
Angular 2.0 Dependency injection
Angular2: Quick overview with 2do app example
Google App Engine in 40 minutes (the absolute essentials)
Assignment DIn Problem D1 we will use a file to contain the dat.pdf
publicclass VehicleParser {publicstatic Vehicle parseStringToVehic.pdf
Classes and Objects In C# With Example
C#i need help creating the instance of stream reader to read from .pdf
Predicting model for prices of used cars
Jan 2017 - a web of applications (angular 2)
#includeiostream #includecmath #includestringusing na.pdf
#include iostream#include string#include iomanip#inclu.docx
How React Native, Appium and me made each other shine @Frontmania 16-11-2018
Scala Self Types by Gregor Heine, Principal Software Engineer at Gilt
Driverimport java.util.Scanner;A class that keeps a f.pdf
srcCommissionCalculation.javasrcCommissionCalculation.javaimpo.docx
#include iostream #include string #include fstream std.docx
29. Treffen - Tobias Meier - TypeScript
I have the first program completed (not how request, but it works) a.pdf
How to Create a Custom Screen in Odoo 17 POS
Ad

More from adianantsolutions (20)

PDF
Nancy acaba de vender algunas de sus acciones en Spotify Inc.pdf
PDF
Name this accessory gland to the digestive systemName th.pdf
PDF
Name of Bacteria Observation Results E coli Yellow s.pdf
PDF
Nasopharyngeal aspirates samples are used to investigate the.pdf
PDF
Mutating His E7 the distal His in myoglobin to a Gly would.pdf
PDF
Muthata1Calleingove LatinatLahr Nereant 1 17ar.pdf
PDF
Nadine LeMieux has just inherited 8000 She wants to use t.pdf
PDF
NAD Participa en la hidrlisis de la sacarosa a glucosa e.pdf
PDF
Multi choice Which sequence represents the correct sequence .pdf
PDF
n2 1 let xPn Show that yv2x0X22n 2 Let x1x2.pdf
PDF
n Faturalama Belgesi ilevini kullanmak iin n koullar nele.pdf
PDF
Myra had high scores as cooperative team player evenkeele.pdf
PDF
Mycobacterium tuberculosis infecta a casi 13 de la poblaci.pdf
PDF
My library gt IT 145 Intro to Software Development home .pdf
PDF
My code is below How do I write this code without usin.pdf
PDF
My essay topic is Water Pollution in black Mississippi Jacks.pdf
PDF
Msrda renkli bir aleuron tohumun bir ksm bir maddenin var.pdf
PDF
MRPnin baarl bir ekilde uygulanmas ve iletilmesi iin aadak.pdf
PDF
Mr senabe is a senior teacher in a secondary school he has.pdf
PDF
Multiple Choice that those genes are not useful in interpret.pdf
Nancy acaba de vender algunas de sus acciones en Spotify Inc.pdf
Name this accessory gland to the digestive systemName th.pdf
Name of Bacteria Observation Results E coli Yellow s.pdf
Nasopharyngeal aspirates samples are used to investigate the.pdf
Mutating His E7 the distal His in myoglobin to a Gly would.pdf
Muthata1Calleingove LatinatLahr Nereant 1 17ar.pdf
Nadine LeMieux has just inherited 8000 She wants to use t.pdf
NAD Participa en la hidrlisis de la sacarosa a glucosa e.pdf
Multi choice Which sequence represents the correct sequence .pdf
n2 1 let xPn Show that yv2x0X22n 2 Let x1x2.pdf
n Faturalama Belgesi ilevini kullanmak iin n koullar nele.pdf
Myra had high scores as cooperative team player evenkeele.pdf
Mycobacterium tuberculosis infecta a casi 13 de la poblaci.pdf
My library gt IT 145 Intro to Software Development home .pdf
My code is below How do I write this code without usin.pdf
My essay topic is Water Pollution in black Mississippi Jacks.pdf
Msrda renkli bir aleuron tohumun bir ksm bir maddenin var.pdf
MRPnin baarl bir ekilde uygulanmas ve iletilmesi iin aadak.pdf
Mr senabe is a senior teacher in a secondary school he has.pdf
Multiple Choice that those genes are not useful in interpret.pdf
Ad

Recently uploaded (20)

PDF
Complications of Minimal Access Surgery at WLH
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
PPTX
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
PDF
A systematic review of self-coping strategies used by university students to ...
PPTX
Orientation - ARALprogram of Deped to the Parents.pptx
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PPTX
UV-Visible spectroscopy..pptx UV-Visible Spectroscopy – Electronic Transition...
PDF
Indian roads congress 037 - 2012 Flexible pavement
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PDF
Classroom Observation Tools for Teachers
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PDF
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
PDF
LNK 2025 (2).pdf MWEHEHEHEHEHEHEHEHEHEHE
PPTX
Onco Emergencies - Spinal cord compression Superior vena cava syndrome Febr...
PPTX
Cell Types and Its function , kingdom of life
PDF
advance database management system book.pdf
PDF
IGGE1 Understanding the Self1234567891011
PDF
Empowerment Technology for Senior High School Guide
Complications of Minimal Access Surgery at WLH
Supply Chain Operations Speaking Notes -ICLT Program
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
A systematic review of self-coping strategies used by university students to ...
Orientation - ARALprogram of Deped to the Parents.pptx
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
UV-Visible spectroscopy..pptx UV-Visible Spectroscopy – Electronic Transition...
Indian roads congress 037 - 2012 Flexible pavement
Final Presentation General Medicine 03-08-2024.pptx
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
Classroom Observation Tools for Teachers
Chinmaya Tiranga quiz Grand Finale.pdf
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
LNK 2025 (2).pdf MWEHEHEHEHEHEHEHEHEHEHE
Onco Emergencies - Spinal cord compression Superior vena cava syndrome Febr...
Cell Types and Its function , kingdom of life
advance database management system book.pdf
IGGE1 Understanding the Self1234567891011
Empowerment Technology for Senior High School Guide

I need to do the followingAdd a new item to the inventory m.pdf

  • 1. I need to do the following:Add a new item to the inventory manager, Remove an item from the inventory, Restock an item in the inventory, Display the items in the inventory, Search for an item/items in the inventory by a variety of criteria. I believe my driver program does this with the inventory manager, but now I need this to do it on the form application. I also need to Update the inventory manager so that it uses a list to store inventory items instead of an array. Here are my four pages of code in c# Visual studio: public partial class Form1: { Car car = new Car(); InventoryManager manager = new InventoryManager(10); public Form1() { InitializeComponent(); } private void btnShow_Click(object sender, EventArgs e) { Car car = new Car(); // Display all the cars in the inventory manager.DisplayItems(); car.Make = "Challenger"; car.Model = "Dodge"; car.Year = 2019; car.MilesPerGallon = 38; car.HorsePower = 300; car.CarPrice = 29000; car.Quantity = 1; carTextBox.Text += "Car make is " + car.Make + "rn" + "Car Model is: " + car.Model + "rn" + "Car Year is: " + car.Year + "rn" + "Car Miles Per Gallon is: " + car.MilesPerGallon + "rn" + "Car Horse Power is: " + car.HorsePower + "rn" + "Quantity of cars in stock is: " + car.Quantity; } private void hideBtn_Click(object sender, EventArgs e) { carTextBox.Text = String.Empty; } public void btnAdd_Click(object sender, EventArgs e) { // Display all the cars in the inventory manager.DisplayItems(); }
  • 2. private void removeItemButton_Click(object sender, EventArgs e) { } private void restockItemButton_Click(object sender, EventArgs e) { } private void searchPriceButton_Click(object sender, EventArgs e) { } private void searchModelButton_Click(object sender, EventArgs e) { } } internal class Driver { static void Main(string[] args) { // Create an inventory manager with a capacity of 10 items InventoryManager manager = new InventoryManager(10); // Add some cars to the inventory 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() {
  • 3. Make = "Dodge", Model = "Charger", Year = 2018, MilesPerGallon = 19, HorsePower = 292, CarPrice = 28000, Quantity = 2 }); // Display all the cars in the inventory manager.DisplayItems(); // Remove the Dodge Charger from the inventory Car dodgeCharger = new Car() { Make = "Dodge", Model = "Charger", Year = 2018, MilesPerGallon = 19, HorsePower = 292, CarPrice = 28000, Quantity = 2 }; manager.RemoveItem(dodgeCharger); // Display all the cars in the inventory again manager.DisplayItems(); // Restock the Ford Mustang by 2 units Car fordMustang = new Car() { Make = "Ford", Model = "Mustang", Year = 2020, MilesPerGallon = 22, HorsePower = 450, CarPrice = 35000, Quantity = 5 }; manager.RestockItem(fordMustang, 2); // Display all the cars in the inventory again manager.DisplayItems(); // Search for cars by name Car[] searchResults = manager.SearchItemByName("Mustang"); foreach (Car car in searchResults) {
  • 4. Console.WriteLine("Make: " + car.Make + ", Model: " + car.Model); } // Search for cars by price searchResults = manager.SearchItemByPrice(35000); foreach (Car car in searchResults) { Console.WriteLine("Make: " + car.Make + ", Model: " + car.Model + ", Price: " + car.CarPrice); } Console.ReadLine(); } } internal class InventoryManager { private Car[] inventory; public InventoryManager(int size) { inventory = new Car[size]; } public void AddItem(Car item) { for (int i = 0; i < inventory.Length; i++) { if (inventory[i] == null) { inventory[i] = item; break; } } } public void RemoveItem(Car item) { for (int i = 0; i < inventory.Length; i++) { if (inventory[i] == item) { inventory[i] = null; break; } } } public void RestockItem(Car item, int quantity) {
  • 5. for (int i = 0; i < inventory.Length; i++) { if (inventory[i] == item) { inventory[i].Quantity += quantity; break; } } } public void DisplayItems() { foreach (Car item in inventory) { if (item != null) { Console.WriteLine("Make: " + item.Make + ", Model: " + item.Model + ", Year: " + item.Year + ", MilesPerGallon: " + item.MilesPerGallon + ", HorsePower: " + item.HorsePower); } } } public Car[] SearchItemByName(string name) { List<Car> result = new List<Car>(); 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<Car> result = new List<Car>(); foreach (Car item in inventory) { if (item != null && item.CarPrice == CarPrice) { result.Add(item); } }
  • 6. return result.ToArray(); } } internal 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; } }