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();
}
}
}