Answer to Question #234317 in C# for Jade adaora

Question #234317
a) Create classes for Medicine and Sales Medicine details that will be stored are as follows:
1. Medicine Code
2. Medicine Name
3. Manufacturer Name 4. Unit Price
5. Quantity On Hand 6. Manufactured Date 7. Expiry Date
8. Batch Number

_Sales details that are to be stored include:_
quantity on hand was zero, write a method to increase the quantity on hand for each of these medicines by 50.
===========
g) Create a Test class to create objects of each of these two classes. Compile the test class and execute the same through Visual Studio IDE.
1
Expert's answer
2021-09-07T14:16:23-0400




using System;
using System.Collections.Generic;
namespace MedicineApp
{
    class Medicine
    {


        private string medicineCode;
        private string medicineName;
        private string manufacturerName;
        private float unitPrice;
        private int quantityOnHand;
        private string manufacturedDate;
        private string expiryDate;
        private int batchNumber;


        public Medicine(string medicineCode, string medicineName, string manufacturerName,
            float unitPrice, int quantityOnHand, string manufacturedDate, string expiryDate, int batchNumber)
        {
            this.medicineCode = medicineCode;
            this.medicineName = medicineName;
            this.manufacturerName = manufacturerName;
            this.unitPrice = unitPrice;
            this.quantityOnHand = quantityOnHand;
            this.manufacturedDate = manufacturedDate;
            this.expiryDate = expiryDate;
            this.batchNumber = batchNumber;
        }




        public void displayInfo()
        {
            Console.WriteLine("Medicine code: {0} ", medicineCode);
            Console.WriteLine("Medicine name: {0} ", medicineName);
            Console.WriteLine("Manufacturer Name: {0} ", manufacturerName);
            Console.WriteLine("Unit price: {0} ", unitPrice.ToString("N"));
            Console.WriteLine("Quantity on Hand: {0} ", quantityOnHand);
            Console.WriteLine("Manufactured Date: {0} ", manufacturedDate);
            Console.WriteLine("Expiry Date: {0} ", expiryDate);
            Console.WriteLine("Batch number: {0} ", batchNumber);


        }
        public void increaseQuantityOnhHand()
        {
            this.quantityOnHand = 50;
        }
    }


    class Sales {
        private List<Medicine> medicines=new List<Medicine>();




        public Sales() { }
        public void addMedicine(Medicine medicine)
        {
            this.medicines.Add(medicine);
        }


        public void display()
        {
            for (int i = 0; i < medicines.Count; i++)
            {
                medicines[i].displayInfo();
            }
        }


        public void increaseQuantityOnhHand() {
            for (int i = 0; i < medicines.Count; i++) {
                medicines[i].increaseQuantityOnhHand();
            }
        }
    }


    class Program
    {
        static void Main(string[] args)
        {


            Sales sales = new Sales();


            sales.addMedicine(new Medicine("455646", "Test name 1", "Medicine name 1", 45, 0, "05.05.2020", "05.05.2021",1346466));
            sales.addMedicine(new Medicine("785545", "Test name 2", "Medicine name 2", 85, 0, "02.02.2021", "01.03.2022", 452124));
            sales.addMedicine(new Medicine("454445", "Test name 3", "Medicine name 3", 36, 0, "06.01.2019", "08.07.2023", 1224545));
            sales.display();
            sales.increaseQuantityOnhHand();
            sales.display();




            Console.ReadLine();
        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS