Hello.
I'm trying to code a C# assignment which is well due tomorrow. This is my first project. I know it's last minute but I'm desperate for help.
So here goes. Basically I'm doing on army store system. The project requires me to use Objects and 2D arrays which I'm pretty sure I've included that.
I'm stuck at this points:-
- Display all the goods of the storage rack by alphabetical order. - Can't seem to do this. I've googled and searched but I still failed.
- Re-order level (quantity) – if the stock balance is less than or equal to the re-quantity, you need to replenish the stock. (one of the attributes that I can't manage to solve)
- Instead of fixing the number of goods, allow the user to specify the number of types of goods (ie. dynamic sizing).
These are the three major aspects that I'm not able to solve. Besides that I'm pretty much done but I need to include the three points I've mentioned above. The codes are pretty long. So please bear with me.
Any help is extremely appreciated.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Project1
{
class store //methods - Update, Display, Constructor, Destructor
{
//data
private string name;
private int hp;
public bin[,] rack = new bin[3, 5];
//method
public void Update()
{
Console.WriteLine("Enter Officer In Charge's Name: ");
name = Console.ReadLine();
Console.WriteLine("Enter telephone number: ");
hp = int.Parse(Console.ReadLine());
}
public void Display()
{
Console.WriteLine("Name: " + name);
Console.WriteLine("Telephone number: " + hp);
}
// default constructor
public store() // no Void
{
name = "UNKNOWN";
hp = 0;
for (int row = 0; row < 3; row++)
{
for (int col = 0; col < 5; col++)
{
rack[row, col] = new bin(); // call constructor
}
}
}
//overload constructor
public store(string Xname, int Xhp)
{
name = Xname;
hp = Xhp;
}
// destructor - no public and void
~store()
{
Console.WriteLine("Name " + name + " is destoryed");
}
//Getter
public string GetName()
{
return name;
}
public int GetHp()
{
return hp;
}
//Setter
public void SetName(string x)
{
name = x;
}
public void SetHp(int x)
{
hp = x;
}
}
class bin
{
//data
private int goods;
public goods[] bingoods = new goods[3];
//methods
public void Update()
{
Console.WriteLine("Enter goods: ");
goods = int.Parse(Console.ReadLine());
}
public void Display()
{
Console.WriteLine("Goods is " + goods);
}
// default constructor
public bin() // no Void
{
goods = 1;
for (int i = 0; i < 3; i++)
{
bingoods[i] = new goods(); // call constructor
}
}
//overload constructor
public bin(int Xgoods)
{
goods = Xgoods;
}
// destructor - no public and void
~bin()
{
Console.WriteLine("Goods " + goods + " is destroyed");
}
//Getter
public int GetGoods()
{
return goods;
}
//Setter
public void SetGoods(int x)
{
goods = x;
}
}
class goods
{
//data
private int code;
private string description;
private string model;
private int quantity;
//method
public void Update()
{
Console.WriteLine("Enter Code: ");
code = int.Parse(Console.ReadLine());
Console.WriteLine("Enter description: ");
description = Console.ReadLine();
Console.WriteLine("Enter Model: ");
model = Console.ReadLine();
Console.WriteLine("Enter Quantity: ");
quantity = int.Parse(Console.ReadLine());
}
public void Display()
{
Console.WriteLine("Code: " + code);
Console.WriteLine("description: " + description);
Console.WriteLine("Model: " + model);
Console.WriteLine("Quantity: " + quantity);
}
// default constructor
public goods() // no Void
{
code = 0;
description = "NONE";
model = "NONE";
quantity = 0;
}
public void Issue()
{
code = 0;
description = null;
model = null;
quantity = 0;
}
//overload constructor
public goods(int Xcode, string Xdescription, string Xmodel, int Xquantity)
{
code = Xcode;
description = Xdescription;
model = Xmodel;
quantity = Xquantity;
}
// destructor - no public and void
~goods()
{
Console.WriteLine("Code " + code + " is destroyed");
}
//Getter
public int GetCode()
{
return code;
}
public string Getdescription()
{
return description;
}
public string GetModel()
{
return model;
}
public int GetQuantity()
{
return quantity;
}
//Setter
public void SetCode(int x)
{
code = x;
}
public void Setdescription(string x)
{
description = x;
}
public void SetModel(string x)
{
model = x;
}
public void SetQuantity(int x)
{
quantity = x;
}
}
class Program
{
static void Main(string[] args)
{
string choice;
// calling default constructor
store s1 = new store();
store s2 = new store();
store s3 = new store();
do
{
Console.WriteLine("");
Console.WriteLine("Army Storage System");
Console.WriteLine("Store Selection");
Console.WriteLine("-------------------");
Console.WriteLine("1) Store 1");
Console.WriteLine("2) Store 2");
Console.WriteLine("3) Store 3");
Console.WriteLine("4) Exit");
Console.WriteLine("-------------------");
Console.Write("Enter choice: ");
choice = Console.ReadLine();
Console.WriteLine("");
switch (choice)
{
case "1":
selection(s1);
break;
case "2":
selection(s2);
break;
case "3":
selection(s3);
break;
case "4":
Console.WriteLine("Goodbye");
break;
default:
ErrorMessage();
break;
} // End of switch case
} while (choice != "4");
}
static void ErrorMessage()
{
Console.WriteLine("Invalid choice. Please enter again. ");
}
static void selection(store s1)
{
string choice;
do
{
Console.WriteLine("");
Console.WriteLine("Army Storage System");
Console.WriteLine("-------------------");
Console.WriteLine("1) Receive Goods");
Console.WriteLine("2) Issue Goods");
Console.WriteLine("3) Display All Goods");
Console.WriteLine("4) Officer-in-charge Details");
Console.WriteLine("5) Exit");
Console.WriteLine("-------------------");
Console.Write("Enter choice: ");
choice = Console.ReadLine();
Console.WriteLine("");
switch (choice)
{
case "1":
Receive_Goods(s1);
break;
case "2":
Issue_Goods(s1);
break;
case "3":
Display_All_Goods(s1);
break;
case "4":
Officer_in_charge_Details(s1);
break;
case "5":
Console.WriteLine("Goodbye");
break;
default:
ErrorMessage();
break;
} // End of switch case
} while (choice != "5");
}
static void Receive_Goods(store s1)
{
int row, col, good;
char answer;
string choice;
do
{
Console.WriteLine("");
Console.WriteLine("Receive Goods");
Console.WriteLine("-------------------");
Console.WriteLine("1) Receive Goods");
Console.WriteLine("2) Display Receive Goods");
Console.WriteLine("3) Exit");
Console.WriteLine("-------------------");
Console.Write("Enter choice: ");
choice = Console.ReadLine();
Console.WriteLine("");
switch (choice)
{
case "1":
do
{
Console.Write("Enter the row (1-3): ");
row = int.Parse(Console.ReadLine());
if (row > 3)
{
ErrorMessage();
}
} while (row > 3);
do
{
Console.Write("Enter the col (1-5): ");
col = int.Parse(Console.ReadLine());
if (col > 5)
{
ErrorMessage();
}
} while (col > 5);
do
{
Console.Write("Enter the set of goods (1-3): ");
good = int.Parse(Console.ReadLine());
} while (good > 3);
s1.rack[row - 1, col - 1].bingoods[good - 1].Update();// update goods
break;
case "2":
do
{
Console.Write("Enter the row (1-3): ");
row = int.Parse(Console.ReadLine());
if (row > 3)
{
ErrorMessage();
}
} while (row > 3);
do
{
Console.Write("Enter the col (1-5): ");
col = int.Parse(Console.ReadLine());
if (col > 5)
{
ErrorMessage();
}
} while (col > 5);
do
{
Console.Write("Enter the set of goods (1-3): ");
good = int.Parse(Console.ReadLine());
} while (good > 3);
s1.rack[row - 1, col - 1].bingoods[good - 1].Display();
break;
case "3":
Console.WriteLine("Goodbye");
break;
default:
ErrorMessage();
break;
}
//prompt the user is he/she wants to continue
Console.Write("Do you wish to continue(Y/N)? ");
answer = char.Parse(Console.ReadLine());
if ((answer == 'N') || (answer == 'n'))
{
break;
}
else if((answer != 'Y') || (answer != 'y'))
{
}
else
{
ErrorMessage();
}
} while ((answer != 'Y') || (answer != 'y'));
}
static void Issue_Goods(store s1)
{
int row, col, good;
char answer;
string choice;
do
{
Console.WriteLine("");
Console.WriteLine("Issue Goods");
Console.WriteLine("-------------------");
Console.WriteLine("1) Issue Goods");
Console.WriteLine("2) Exit");
Console.WriteLine("-------------------");
Console.Write("Enter choice: ");
choice = Console.ReadLine();
Console.WriteLine("");
switch (choice)
{
case "1":
Console.WriteLine("Enter the row & col of the goods that you want to remove.");
do
{
Console.Write("Enter the row (1-3): ");
row = int.Parse(Console.ReadLine());
if (row > 3)
{
ErrorMessage();
}
} while (row > 3);
do
{
Console.Write("Enter the col (1-5): ");
col = int.Parse(Console.ReadLine());
if (col > 5)
{
ErrorMessage();
}
} while (col > 5);
do
{
Console.Write("Enter the set of goods (1-3): ");
good = int.Parse(Console.ReadLine());
} while (good > 3);
s1.rack[row - 1, col - 1].bingoods[good - 1].Issue();
Console.WriteLine("Goods from row " + row + " & col " + col + " has been issue.");
break;
case "2":
Console.WriteLine("Goodbye");
break;
default:
ErrorMessage();
break;
}
//prompt the user is he/she wants to continue
Console.Write("Do you wish to continue(Y/N)? ");
answer = char.Parse(Console.ReadLine());
if ((answer == 'N') || (answer == 'n'))
{
break;
}
else if ((answer != 'Y') || (answer != 'y'))
{
}
else
{
ErrorMessage();
}
} while ((answer != 'Y') || (answer != 'y'));
}
static void Display_All_Goods(store s1)
{
int total1 = 0;
int total2 = 0;
int total3 = 0;
int total = 0;
string choice;
do
{
Console.WriteLine("");
Console.WriteLine("Display All Goods");
Console.WriteLine("-------------------");
Console.WriteLine("1) Display All Quantity");
Console.WriteLine("2) Exit");
Console.WriteLine("-------------------");
Console.Write("Enter choice: ");
choice = Console.ReadLine();
Console.WriteLine("");
switch (choice)
{
case "1":
for (int row = 0; row < 3; row++)
{
for (int col = 0; col < 5; col++)
{
total1 = total1 + s1.rack[row, col].bingoods[0].GetQuantity();
}
}
for (int row = 0; row < 3; row++)
{
for (int col = 0; col < 5; col++)
{
total2 = total2 + s1.rack[row, col].bingoods[1].GetQuantity();
}
}
for (int row = 0; row < 3; row++)
{
for (int col = 0; col < 5; col++)
{
total3 = total3 + s1.rack[row, col].bingoods[2].GetQuantity();
}
}
total = total1 + total2 + total3;
Console.WriteLine("Total Quantity is " + total);
break;
case "2":
Console.WriteLine("Goodbye");
break;
default:
ErrorMessage();
break;
}
} while (choice != "2");
}
static void Officer_in_charge_Details(store s1)
{
char answer;
string choice;
do
{
Console.WriteLine("");
Console.WriteLine("Officer-in-charge Details");
Console.WriteLine("-------------------");
Console.WriteLine("1) Update Officer-in-charge Details");
Console.WriteLine("2) Display Officer-in-charge Details");
Console.WriteLine("3) Exit");
Console.WriteLine("-------------------");
Console.Write("Enter choice: ");
choice = Console.ReadLine();
Console.WriteLine("");
switch (choice)
{
case "1":
s1.Update();
break;
case "2":
s1.Display();
break;
case "3":
Console.WriteLine("Goodbye");
break;
default:
ErrorMessage();
break;
}
//prompt the user if he/she wants to continue
Console.Write("Do you wish to continue(Y/N)? ");
answer = char.Parse(Console.ReadLine());
if ((answer == 'N') || (answer == 'n'))
{
break;
}
else if ((answer != 'Y') || (answer != 'y'))
{
}
else
{
ErrorMessage();
}
} while ((answer != 'Y') || (answer != 'y'));
}
}
Thanks,
Rin