Member Avatar for Erwin_Rosyid

First, I apologize for posting a question as my first post but I'm in need of help since I couldn't solve this assignment.

I wrote this simple code for an assignment last week. Today, the professor got to leave early so he left us an assignment which is related to function, procedure, and class - which haven't been explained to us. To cirvumvent our complaints he left us a copy of his powerpoint presentation regarding to subject matter. He also include my previously written code to my suprise and gave us an assignment which is :

Make your friend's code simplified by separating its components into classes I outlined.

Class ProcessData;
    public void Input(paramater);
    public float getTotal(parameter);
    public void Report(parameter);

Class ProcessAll;
    Public Procedure ExecuteProg();

In the main void class there can oly be two statement which is

ProcessAll Karaoke= new ProcessAll()
Karaoke.ExecuteProg();

Needles to say, I'm confused since the last 8 hours googling for something remotely resembling an answer was fruitless. The assignment itself was ungraded but I would like to have a reference code for future assignment. Any help is appreciated.

Erwin Rosyid -
STIKOM Bali Indonesia

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Test1
{
    class Program
    {
        static void Main(string[] args)
        {
            System.Console.WriteLine("===Wellcome to the karaoke===");
            System.Console.WriteLine("              Room Type "); 
            System.Console.WriteLine("====================================");
            System.Console.WriteLine("1. Small  (90.000)");
            System.Console.WriteLine("2. VIP    (400.000) ");
            System.Console.WriteLine("3. VVIP   (500.000)");
            System.Console.WriteLine("====================================");
            System.Console.Write("Select Room Type (1,2,3)= ");
            char tipe = System.Console.ReadLine()[0];
            System.Console.Write("Member [y/n]            = ");
            char Member = System.Console.ReadLine()[0];
            System.Console.Write("Duration                = ");
            int hour = int.Parse(System.Console.ReadLine());
            float discount = 0, price = 0, bagi = 100;

            if (Member == 'y')
            {
                discount = 5;
            }
            float total;
            string room = "";

            switch (tipe)
            {
                case '1':
                    room = "Small";
                    price = 90000;
                    break;
                case '2':
                    room = "VIP";
                    price = 400000;
                    break;
                case '3':
                    room = "VVIP";
                    price = 500000;
                    break;
                default:
                    price = 50000;
                    break;
            }

            total = (price * hour) * (discount / bagi);
            total = (price * hour) - total;

            System.Console.WriteLine();
            System.Console.WriteLine("================Payment details===============");
            System.Console.WriteLine("Room Price  = " + room + " =" + price);
            System.Console.WriteLine("Hours spent = " + hour + " hour");
            System.Console.WriteLine("Discount    = " + discount + " %");
            System.Console.WriteLine("=================================================");
            System.Console.WriteLine("Total       = " + total);
            System.Console.ReadKey();

        }
    }
}

Following the post guidelines, here is my attempt at solving it:

Creating the ProcessData and its members with several errors:

namespace Test1
{
    class ProcessData
    {
        public void Input()
        {
            System.Console.WriteLine("===Wellcome to the karaoke===");
            System.Console.WriteLine("              Room Type ");
            System.Console.WriteLine("====================================");
            System.Console.WriteLine("1. Small  (90.000)");
            System.Console.WriteLine("2. VIP    (400.000) ");
            System.Console.WriteLine("3. VVIP   (500.000)");
            System.Console.WriteLine("====================================");
            System.Console.Write("Select Room Type (1,2,3)= ");
            char tipe = System.Console.ReadLine()[0];
            System.Console.Write("Member [y/n]            = ");
            char Member = System.Console.ReadLine()[0];
            System.Console.Write("Duration                = ");
            int hour = int.Parse(System.Console.ReadLine());
        }

        public float getTotal
        {
            float discount = 0, price = 0, bagi = 100;

            if (Member == 'y')
            {
                discount = 5;
            }
            float total;
            string room = "";

            switch (tipe)
            {
                case '1':
                    room = "Small";
                    price = 90000;
                    break;
                case '2':
                    room = "VIP";
                    price = 400000;
                    break;
                case '3':
                    room = "VVIP";
                    price = 500000;
                    break;
                default:
                    price = 50000;
                    break;
            }

            total = (price * hour) * (discount / bagi);
            total = (price * hour) - total;
        }

        public void Report()
        {
            System.Console.WriteLine();
            System.Console.WriteLine("================Payment details===============");
            System.Console.WriteLine("Room Price  = " + room + " =" + price);
            System.Console.WriteLine("Hours spent = " + hour + " hour");
            System.Console.WriteLine("Discount    = " + discount + " %");
            System.Console.WriteLine("=================================================");
            System.Console.WriteLine("Total       = " + total);
            System.Console.ReadKey();
        }
    }
}

Here is a brief example of what he wants:

  1. Start a new project
  2. Create 2 classes , one named ProcessData and one called ProcessAll
  3. In the ProcessData class you need to have the following:

ProcessData Class

//private class variables  - All the variables which are used in your program
private int room;
private char member;
private int duration;

public void Input() { - used to set the variables
//put your input code here and set the private variables with what the user enters
}
public float getTotal(parameter) {

float total = 0;
 //put your calculation code here and add a return statement
return total;
}

public void Report(float total) {
  //put your report code here using the total variable which is passed
  Writeline("total = " + total); etc.
}

ProcessAll Class

//create a class constructor

public void ExecuteProg() {

//create ProcessData object

ProcessData pd = new ProcessData();

pd.Input(); //execute the input part
float total = pd.getTotal(); //assign the return float the local variable
pd.Report(total); //pass the total to the report page

}

Main Class

public static void main(String[] args) {


    ProcessAll Karaoke = new ProcessAll()
    Karaoke.ExecuteProg();

}

There is obviousy some code missing but this is the basic outline of what you need.

commented: Very helpful and constructive, not going to spoon-feed is the best possible way to answer! +0
Member Avatar for Erwin_Rosyid

Thank you Mr. Skeldale, your answer was what I desperately needed. Now my mind can be at ease because of you.

From your code, I adapted it into

Main

        static void Main(string[] args)
        {
            ProcessAll Karaoke = new ProcessAll();
            Karaoke.ExecuteProg();
        }

ProcessData

class ProcessData

{

    private char member;
    private int duration;
    private char tipe;
    private float discount;
    private float price;

    public void Input()
    {
        System.Console.WriteLine("===Wellcome to the karaoke===");
        System.Console.WriteLine("              Room Type ");
        System.Console.WriteLine("====================================");
        System.Console.WriteLine("1. Small  (90.000)");
        System.Console.WriteLine("2. VIP    (400.000) ");
        System.Console.WriteLine("3. VVIP   (500.000)");
        System.Console.WriteLine("====================================");
        System.Console.Write("Select Room Type (1,2,3)= ");
        tipe = System.Console.ReadLine()[0];
        System.Console.Write("Member [y/n]            = ");
        member = System.Console.ReadLine()[0];
        System.Console.Write("Duration                = ");
        duration = int.Parse(System.Console.ReadLine());
    }

    public float getTotal() 
    {
        float total = 0, bagi = 100;
        if (member == 'y')
        {
            discount = 5;
        }

        switch (tipe)
        {
            case '1':
                room = "Small";
                price = 90000;
                break;
            case '2':
                room = "VIP";
                price = 400000;
                break;
            case '3':
                room = "VVIP";
                price = 500000;
                break;
            default:
                price = 50000;
                break;
        }

        total = (price * duration) * (discount / bagi);
        total = (price * duration) - total;
        //put your calculation code here and add a return statement
        return total;
    }

    public void Report(float total) 
    {
        System.Console.WriteLine();
        System.Console.WriteLine("================Payment details===============");
        System.Console.WriteLine("Room Price  = " + room + " = " + price);
        System.Console.WriteLine("Hours spent = " + duration + " hour");
        System.Console.WriteLine("Discount    = " + discount + " %");
        System.Console.WriteLine("=================================================");
        System.Console.WriteLine("Total       = " + total);
        System.Console.ReadKey();
    }
}
}

ExecuteProg

public void ExecuteProg()
        {
            //create ProcessData object
            ProcessData pd = new ProcessData();
            pd.Input(); //execute the input part
            float total = pd.getTotal(); //assign the return float the local variable
            pd.Report(total); //pass the total to the report page
        }

Again, thank you for your help - it's been very constructive and helpful.

Regards,
Erwin Rosyid

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.