In previous chapters, you continued to modify the MarshallsRevenue program. Now,
ID: 3744536 • Letter: I
Question
In previous chapters, you continued to modify the MarshallsRevenue program. Now, modify the program so that the major functions appear in the following individual methods:
GetMonth - This method prompts for and returns the month
GetNumMurals - This method prompts for and returns the number of murals scheduled and is called twice -- once for interior murals and once for exterior murals
ComputeRevenue - This method accepts the number of interior and exterior murals scheduled, accepts the month they are scheduled, displays the interior and exterior prices, and then returns the total expected revenue
DataEntry - This method fills an array with customer names and mural codes and is called twice -- once to fill the array of interior murals and once to fill the array of exterior murals
GetSelectedMurals - This method continuously prompts for mural codes and displays jobs of the corresponding type until a sentinel value is entered.
This is in C#, Please all the methods are works, Thanks
Previous code
using System;
using static System.Console;
class MarshallsRevenue
{
static void Main()
{
const int INTERIOR_PRICE = 500;
const int DISCOUNT_INTERIOR_PRICE = 450;
const int EXTERIOR_PRICE = 750;
const int DISCOUNT_EXTERIOR_PRICE = 699;
const int MIN_MURALS = 0;
const int MAX_MURALS = 30;
string entryString;
int month;
int numInterior;
int numExterior;
int revenueInterior;
int revenueExterior;
int total;
bool isInteriorGreater;
string[] interiorCustomers = new string[MAX_MURALS];
string[] exteriorCustomers = new string[MAX_MURALS];
char[] muralCodes = {'L', 'S', 'A', 'C', 'O'};
string[] muralCodesStrings = {"Landscape", "Seascape",
"Abstract", "Children's", "Other"};
char[] interiorCodes = new char[MAX_MURALS];
char[] exteriorCodes = new char[MAX_MURALS];
int x;
bool isValid;
bool found;
int pos = 0;
int[] interiorCounts = {0, 0, 0, 0, 0};
int[] exteriorCounts = {0, 0, 0, 0, 0};
char option;
const char QUIT = 'Z';
Write("Enter the month >> ");
entryString = ReadLine();
month = Convert.ToInt32(entryString);
while(month< 1 || month > 12)
{
Write("Invalid month. Enter the month >> ");
entryString = ReadLine();
month = Convert.ToInt32(entryString);
}
Write("Enter number of interior murals scheduled >> ");
entryString = ReadLine();
numInterior = Convert.ToInt32(entryString);
while(numInterior < MIN_MURALS || numInterior > MAX_MURALS)
{
WriteLine("Number must be between {0} and {1} inclusive", MIN_MURALS, MAX_MURALS);
Write("Enter number of interior murals scheduled >> ");
entryString = ReadLine();
numInterior = Convert.ToInt32(entryString);
}
Write("Enter number of exterior murals scheduled >> ");
entryString = ReadLine();
numExterior = Convert.ToInt32(entryString);
while(numExterior < MIN_MURALS || numExterior > MAX_MURALS)
{
WriteLine("Number must be between {0} and {1} inclusive", MIN_MURALS, MAX_MURALS);
Write("Enter number of Exterior murals scheduled >> ");
entryString = ReadLine();
numExterior = Convert.ToInt32(entryString);
}
if(month == 12 || month ==1 || month == 2)
numExterior = 0;
if(month == 4 || month == 5 || month ==9 || month ==10)
revenueInterior = numInterior * DISCOUNT_INTERIOR_PRICE;
else
revenueInterior = numInterior * INTERIOR_PRICE;
if(month == 7 || month == 8)
revenueExterior = numExterior * DISCOUNT_EXTERIOR_PRICE;
else
revenueExterior = numExterior * EXTERIOR_PRICE;
total = revenueInterior + revenueExterior;
isInteriorGreater = numInterior > numExterior;
WriteLine("{0} interior murals are scheuled at {1} each for a total of {2}",
numInterior, INTERIOR_PRICE.ToString("C"), revenueInterior.ToString("C"));
WriteLine("{0} exterior murals are scheuled at {1} each for a total of {2}",
numExterior, EXTERIOR_PRICE.ToString("C"), revenueExterior.ToString("C"));
WriteLine("Total revenue expected is {0}", total.ToString("C"));
WriteLine("It is {0} that there are more interior murals scheduled than exterior ones.", isInteriorGreater);
WriteLine("Entering interior jobs:");
x = 0;
while(x < numInterior)
{
Write("Enter customer name >> ");
interiorCustomers[x] = ReadLine();
WriteLine("Mural options are:");
for(int y = 0; y < muralCodes.Length; ++y)
WriteLine(" {0} {1}", muralCodes[y], muralCodesStrings[y]);
Write(" Enter mural style code >> ");
interiorCodes[x] = Convert.ToChar(ReadLine());
isValid = false;
while(!isValid)
{
for(int z = 0; z < muralCodes.Length; ++z)
{
if(interiorCodes[x] == muralCodes[z])
{
isValid = true;
++interiorCounts[z];
}
}
if(!isValid)
{
WriteLine("{0} is not a valid code", interiorCodes[x]);
Write(" Enter mural style code >> ");
interiorCodes[x] = Convert.ToChar(ReadLine());
}
}
++x;
}
WriteLine("Entering exterior jobs:");
x = 0;
while(x < numExterior)
{
Write("Enter customer name >> ");
exteriorCustomers[x] = ReadLine();
WriteLine("Mural options are:");
for(int y = 0; y < muralCodes.Length; ++y)
WriteLine(" {0} {1}", muralCodes[y], muralCodesStrings[y]);
Write(" Enter mural style code >> ");
exteriorCodes[x] = Convert.ToChar(ReadLine());
isValid = false;
while(!isValid)
{
for(int z = 0; z < muralCodes.Length; ++z)
{
if(exteriorCodes[x] == muralCodes[z])
{
isValid = true;
++exteriorCounts[z];
}
}
if(!isValid)
{
WriteLine("{0} is not a valid code", exteriorCodes[x]);
Write(" Enter mural style code >> ");
interiorCodes[x] = Convert.ToChar(ReadLine());
}
}
++x;
}
WriteLine(" The interior murals scheduled are:");
for(x = 0; x < interiorCounts.Length; ++x)
WriteLine("{0, -20} {1, 5}", muralCodesStrings[x], interiorCounts[x]);
WriteLine(" The exterior murals scheduled are:");
for(x = 0; x < exteriorCounts.Length; ++x)
WriteLine("{0, -20} {1, 5}", muralCodesStrings[x], exteriorCounts[x]);
Write(" Enter a mural type or {0} to quit >> ", QUIT);
option = Convert.ToChar(ReadLine());
while(option != QUIT)
{
isValid = false;
for(int z = 0; z < muralCodes.Length; ++z)
{
if(option == muralCodes[z])
{
isValid = true;
pos = z;
}
}
if(!isValid)
WriteLine("{0} is not a valid code", option);
else
{
WriteLine(" Customers ordering {0} murals are:", muralCodesStrings[pos]);
found = false;
for(x = 0; x < numInterior; ++x)
{
if(interiorCodes[x] == option)
{
WriteLine("{0} Interior", interiorCustomers[x]);
found = true;
}
}
for(x = 0; x < numExterior; ++x)
{
if(exteriorCodes[x] == option)
{
WriteLine("{0} Exterior", exteriorCustomers[x]);
found = true;
}
}
if(!found)
WriteLine("No customers ordered {0} murals", muralCodesStrings[pos]);
}
Write(" Enter a mural type or {0} to quit >> ", QUIT);
option = Convert.ToChar(ReadLine());
}
}
}
Explanation / Answer
using System;
using static System.Console;
class MarshallsRevenue
{
static void Main()
{
const int INTERIOR_PRICE = 500;
const int DISCOUNT_INTERIOR_PRICE = 450;
const int EXTERIOR_PRICE = 750;
const int DISCOUNT_EXTERIOR_PRICE = 699;
const int MIN_MURALS = 0;
const int MAX_MURALS = 30;
string entryString;
int month;
int numInterior;
int numExterior;
int revenueInterior;
int revenueExterior;
int total;
bool isInteriorGreater;
string[] interiorCustomers = new string[MAX_MURALS];
string[] exteriorCustomers = new string[MAX_MURALS];
char[] muralCodes = {'L', 'S', 'A', 'C', 'O'};
string[] muralCodesStrings = {"Landscape", "Seascape",
"Abstract", "Children's", "Other"};
char[] interiorCodes = new char[MAX_MURALS];
char[] exteriorCodes = new char[MAX_MURALS];
int x;
bool isValid;
bool found;
int pos = 0;
int[] interiorCounts = {0, 0, 0, 0, 0};
int[] exteriorCounts = {0, 0, 0, 0, 0};
char option;
const char QUIT = 'Z';
string location;
int num;
string[] customers;
char[] codes;
int [] counts;
//Code Lies Within the Methods..
GetMonth();
GetNumMurals(location);
ComputeRevenue(month,numInterior,numExterior);
DataEntry(location,num,customers,muralCodes,muralCodesStrings,codes,counts);
GetSelectedMurals(muralCodes,muralCodesStrings,numInterior,numExterior,interiorCustomers,interiorCodes,exteriorCustomers,exteriorCodes);
}
public static int GetMonth() {
Write("Enter the month >> ");
entryString = ReadLine();
month = Convert.ToInt32(entryString);
while(month< 1 || month > 12)
{
Write("Invalid month. Enter the month >> ");
entryString = ReadLine();
month = Convert.ToInt32(entryString);
}
}
public static int GetNumMurals(string location){
Write("Enter number of interior murals scheduled >> ");
entryString = ReadLine();
numInterior = Convert.ToInt32(entryString);
while(numInterior < MIN_MURALS || numInterior > MAX_MURALS)
{
WriteLine("Number must be between {0} and {1} inclusive", MIN_MURALS, MAX_MURALS);
Write("Enter number of interior murals scheduled >> ");
entryString = ReadLine();
numInterior = Convert.ToInt32(entryString);
}
Write("Enter number of exterior murals scheduled >> ");
entryString = ReadLine();
numExterior = Convert.ToInt32(entryString);
while(numExterior < MIN_MURALS || numExterior > MAX_MURALS)
{
WriteLine("Number must be between {0} and {1} inclusive", MIN_MURALS, MAX_MURALS);
Write("Enter number of Exterior murals scheduled >> ");
entryString = ReadLine();
numExterior = Convert.ToInt32(entryString);
}
}
public static int ComputeRevenue(int month,int numInterior,int numExterior){
if(month == 12 || month ==1 || month == 2)
numExterior = 0;
if(month == 4 || month == 5 || month ==9 || month ==10)
revenueInterior = numInterior * DISCOUNT_INTERIOR_PRICE;
else
revenueInterior = numInterior * INTERIOR_PRICE;
if(month == 7 || month == 8)
revenueExterior = numExterior * DISCOUNT_EXTERIOR_PRICE;
else
revenueExterior = numExterior * EXTERIOR_PRICE;
total = revenueInterior + revenueExterior;
isInteriorGreater = numInterior > numExterior;
WriteLine("{0} interior murals are scheuled at {1} each for a total of {2}",
numInterior, INTERIOR_PRICE.ToString("C"), revenueInterior.ToString("C"));
WriteLine("{0} exterior murals are scheuled at {1} each for a total of {2}",
numExterior, EXTERIOR_PRICE.ToString("C"), revenueExterior.ToString("C"));
WriteLine("Total revenue expected is {0}", total.ToString("C"));
WriteLine("It is {0} that there are more interior murals scheduled than exterior ones.", isInteriorGreater);
}
public static void DataEntry(string location,int num, string[] customers,
char[] muralCodes,string[] muralCodesStrings,char[] codes,int[] counts) {
WriteLine("Entering interior jobs:");
x = 0;
while(x < numInterior)
{
Write("Enter customer name >> ");
interiorCustomers[x] = ReadLine();
WriteLine("Mural options are:");
for(int y = 0; y < muralCodes.Length; ++y)
WriteLine(" {0} {1}", muralCodes[y], muralCodesStrings[y]);
Write(" Enter mural style code >> ");
interiorCodes[x] = Convert.ToChar(ReadLine());
isValid = false;
while(!isValid)
{
for(int z = 0; z < muralCodes.Length; ++z)
{
if(interiorCodes[x] == muralCodes[z])
{
isValid = true;
++interiorCounts[z];
}
}
if(!isValid)
{
WriteLine("{0} is not a valid code", interiorCodes[x]);
Write(" Enter mural style code >> ");
interiorCodes[x] = Convert.ToChar(ReadLine());
}
}
++x;
}
WriteLine("Entering exterior jobs:");
x = 0;
while(x < numExterior)
{
Write("Enter customer name >> ");
exteriorCustomers[x] = ReadLine();
WriteLine("Mural options are:");
for(int y = 0; y < muralCodes.Length; ++y)
WriteLine(" {0} {1}", muralCodes[y], muralCodesStrings[y]);
Write(" Enter mural style code >> ");
exteriorCodes[x] = Convert.ToChar(ReadLine());
isValid = false;
while(!isValid)
{
for(int z = 0; z < muralCodes.Length; ++z)
{
if(exteriorCodes[x] == muralCodes[z])
{
isValid = true;
++exteriorCounts[z];
}
}
if(!isValid)
{
WriteLine("{0} is not a valid code", exteriorCodes[x]);
Write(" Enter mural style code >> ");
interiorCodes[x] = Convert.ToChar(ReadLine());
}
}
++x;
}
}
public static void GetSelectedMurals(char[] muralCodes,string[] muralCodesStrings,int numInterior,
int numExterior,string[] interiorCustomers,char[] interiorCodes,string[] exteriorCustomers,
char[] exteriorCodes) {
WriteLine(" The interior murals scheduled are:");
for(x = 0; x < interiorCounts.Length; ++x)
WriteLine("{0, -20} {1, 5}", muralCodesStrings[x], interiorCounts[x]);
WriteLine(" The exterior murals scheduled are:");
for(x = 0; x < exteriorCounts.Length; ++x)
WriteLine("{0, -20} {1, 5}", muralCodesStrings[x], exteriorCounts[x]);
Write(" Enter a mural type or {0} to quit >> ", QUIT);
option = Convert.ToChar(ReadLine());
while(option != QUIT)
{
isValid = false;
for(int z = 0; z < muralCodes.Length; ++z)
{
if(option == muralCodes[z])
{
isValid = true;
pos = z;
}
}
if(!isValid)
WriteLine("{0} is not a valid code", option);
else
{
WriteLine(" Customers ordering {0} murals are:", muralCodesStrings[pos]);
found = false;
for(x = 0; x < numInterior; ++x)
{
if(interiorCodes[x] == option)
{
WriteLine("{0} Interior", interiorCustomers[x]);
found = true;
}
}
for(x = 0; x < numExterior; ++x)
{
if(exteriorCodes[x] == option)
{
WriteLine("{0} Exterior", exteriorCustomers[x]);
found = true;
}
}
if(!found)
WriteLine("No customers ordered {0} murals", muralCodesStrings[pos]);
}
Write(" Enter a mural type or {0} to quit >> ", QUIT);
option = Convert.ToChar(ReadLine());
}
}
}