Martin Obbo

Martin Obbo

  • NA
  • 1
  • 837

Classes and methods arrangements along arrays

May 4 2015 12:41 AM
How do I go about putting my methods and classes in order?
I am writing a product Data Catalogue program with a mix of classes and methods, as well as Arrays.
Right now, I am stuck. I can’t figure out how to put the combination of Arrays, Methods and classes in proper orders.
Being new to C# makes writing a program with multiple classes and methods a difficult work.
I would be happy for your suggestions and help, to give me an idea how I could go about it.
Below is the dirty script of what I am trying to do:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CatalogueInventory // change to catalogue inventory
{
static void Main (string)[] args)
{
// Create a single­argument constructor, which accepts and
// initializes the catalogueName field and initializes
// numberOfProducts as 0 and allocates and
// assigns an array of ProductData (having MAX_NUM_PRODUCTS elements) to products.

// Create a method PrintCatalogue, which iterates over all products stored in products
// and prints out each product by invoking ProductData’ s PrintProduct method.

// method InsertProduct, which adds another product
// (including its name and retail price) into the catalogue.
 
public int numberOfProducts =0;
const int MAX_NUM_PRODUCTS = 100;
public string[]productNames = new string [MAX_NUM_PRODUCTS];
public double[]retailPrices = new double [MAX_NUM_PRODUCTS];
public string[]catalogueName = new string[MAX_NUM_PRODUCTS];
 
// Create a new product catalogue: Prompt the user to enter the name of the
// product catalogue (e.g., electronics, groceries, apparel, etc.).
// Then create an instance of ProductCatalogue like so:
 
ProductCatalogue catalogue = new ProductCatalogue(StoreitemCatalogue);
productCatalogue[]catalogues = new ProductCatalogue[10];

Catalogues = new Electronics();
productNames[0] = "Golden Apple Watch";
retailPrices[0] = 1800;
productNames[0] = "Swiss cuckoo clock";
retailPrices[0] = 400;
productNames[0] = "ACME watch";
retailPrices[0] = 123.45;
productNames[0] = "Kambrook Fan Heater";
retailPrices[0] = 59;
 
Catalogues = new Books();
productNames[1] = "The Distinguished Gentleman";
retailPrices[1] = 14.95;
productNames[1] = "Get Shorty";
retailPrices[1] = 9.95;
productNames[1] = "Born Invincible";
retailPrices[1] = 22.45;

Catalogues = new Apparel();
productNames[2] = "Women Double-faced wool coat";
retailPrices[2] = 275.25;
productNames[2] = "Men Cotton Polo Shirt";
retailPrices[2] = 45.55;
productNames[2] = "Children Bear coverall sweater";
retailPrices[2] = 48.55;

Console.Writeline("------------------Menu---------------------------");

Console.Writeline("\t1.Electronics");
Console.Writeline("\t2.Books");
Console.Writeline("\t3.Apparel");
Console.Writeline("\t4.InsertProduct or Update existing product price and name");
Console.Writeline("\t5.Calculate Profits");
Console.Writeline("\t6.Calculate totals");
Console.Writeline("\t7.Print Product Data");
Console.Writeline("\t8.Exit Program");

{
public class ProductData
// Create a class ProductData, having two fields: productName ( string) and
// retailPrice ( double) and a method printProduct,
// which prints out the productName and retailPrice.
// create a two ­argument constructor, which takes and
// assigns the initial values for productName and retailPrice.
{
public string productNames;
public double retailPrices;
private string names;

public void Initialize(string names, double price)
{
productNames = names;
retailPrices = price;
}
public void ShowInformation() // method to display productNames and retailPrice
{
// may need to delete one of the brackets
}
public void printProduct()
{
// productName productData = new retailPrice();
}
public class productCatalogue

// Create another class ProductCatalogue, which replaces the hitherto
// separate variables productNames ( string[]) , retailPrices ( double[]) ,
// and numberOfProducts ( int) by 3 fields, being catalogueName ( string)
// an array of ProductData instances and the numberOfProducts ( int) variable:
{
string catalogueName;
ProductData[] products;
int numberOfProducts;
...
}
public void PrintCatalogue()
{
// write something
}
public void InsertProduct()
// write something
{
}
}
}