# C# Program to Schedule A Building Paint Job Assignment Solution.

## Instructions

Objective
Write a C# assignment to schedule a building paint job.

## Requirements and Specifications

Problem:
Write a program for scheduling a building paint job. Both interior and exterior.
The program will do the following:
Get the following data from the customer:
- Ask the customer to enter his/her name.
- Ask the customer to enter the month number that they want to schedule the paint job for (Let the customer know the valid entries are 1 – 12).
- Ask the customer to enter the size of the interior and exterior walls (per square feet) that they want painted.
o example: interior: 7600
exterior: 6400
- Ask the customer for their credit card number (Let the user know AMEX, VISA, & MC cards are accepted)
o (Have in mind that AMEX cards are 15 digits, VISA/MC cards are 16 digits)
o example: 312345678912345 (Amex example)
4987654321234567 (Visa example)
- Note: Make sure to read the values from the same line as the question.
(Question and answer in same line)
Perform the following calculations:
Calculate the following:
o Total number of gallons(cans) of paint needed for the interior (a whole number)
o Total number of gallons(cans) of paint needed for the exterior (a whole number)
o Total number of gallons(cans) of paint needed altogether (a whole number)
§ Perform your calculations based on the following information:
•  Each 1 gallon can of paint can paint 400 SQFT
•  Make sure you always have enough paint
•  Hint: You can add a can (gallon) to the result to make sure you have enough.
•   [XC] Extra Credit Point: Instead of just adding a can, actually
calculate how many cans (gallons) you need.
o total cost of interior paint
o total cost of exterior paint
o total cost of paint all together
§ Perform your calculations based on the following pricing:
•  Exterior paint is weatherproof and more expensive.
• Price to paint the interior walls: \$300.00 (per gallon).
• Price to paint the exterior walls: \$600.00 (per gallon).
Create a receipt for the customer that looks as:
- [tab]Date: followed by [Today’s date]
o Code for today’s Date is: DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss")
- [tab]Name: followed by [Customer name]
- [tab]Card Number: followed by [Customer credit card number as described below]
o Display the card as six (6) stars followed by the last 4 digits of their card number.
o Example, if card number: 1234567890123456, display: ******3456
o Use Substring.
- [tab]Month Scheduled: followed by [month]
o The month will be displayed in the following format:
§ The 3-letter name of the month followed by a space and then the month number inside a pair parenthesis.
§ Example: if month = 11, then display: NOV (11)
§ Use enum (if not sure how, replace month name with “???”, ex: ??? (11))
Line 1: [tab]Date: [Today’s Date]
Line 2: [tab]Name: Name
Line 3: [tab]Card Number: ******[Last 4 digits]
Line 4: [tab]Month Scheduled: NOV (11)
<------------ 40 chars ----------->
Only 10 digits of the card number is displayed
Month Scheduled, is the [3-letter Month Name] ([Month Number])
Followed by receipt details.
- A line of space, followed by details.
o Details are as follows:
§ Line 1: [tab]Header row (Type, Area (sqft), Paint (gal), Cost (\$) )
§ Line 2: [tab]dashes
§ Line 3: [tab]Interior detail
§ Line 4: [tab]Exterior detail
§ Line 5: [tab]dashes
§ Line 6: [tab]Totals
o Note: Format and display all \$ values with \$ sign and one decimal points
- The receipt will look something like the following example:
Date: Todays Date
Name: xxxx
Card Number: ******3450
Month Scheduled: NOV (11)
Type Area (SqFt) Paint (Gal) Cost (\$)
--------- ----------- ----------- -----------
Interior 7600 19 \$5,700.0
Exterior 5500 14 \$8,400.0
--------- ----------- ----------- -----------
Total 13100 33 \$14,100.0
Comments:
Make sure to provide comments in your code as needed to describe your work.
Also include the following program info at the top of your program inside the Class().
Source Code
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MatthewAssignment
{
class Program
{
// Declare ENUM for credit card type
enum CreditCardType
{
NONE,
AMEX,
VISA,
MASTERCARD
}
// Declare a constant that defines the number of square feets that can be painted with a gallon
const int SQFT_PER_GALLON = 400;
// Declare constants for prices (per gallon)
const int INTERIOR_PRICE = 300;
const int EXTERIOR_PRICE = 600;
static int getMonth()
{
// Ask user for a month and check for valid inputs. Display error message if the input
// is not valid and reprompt
int month;
while (true)
{
try
{
Console.Write("Enter month to schedule the paint job (1-12): ");
month = Convert.ToInt32(Console.ReadLine());
if (month >= 1 && month <= 12)
return month;
else
Console.WriteLine("Please enter a valid month number.");
}
catch(Exception ex)
{
Console.WriteLine("Please enter a valid month number.");
}
}
}
static int getInteriorSquareFeets()
{
// Ask user for a number for the size of the area and check for valid inputs. Display error message if the input
// is not valid and reprompt
int sqft;
while (true)
{
try
{
Console.Write("Enter size of interior area (square-feets): ");
sqft = Convert.ToInt32(Console.ReadLine());
if (sqft > 0)
return sqft;
else
Console.WriteLine("Please enter a valid number.");
}
catch (Exception ex)
{
Console.WriteLine("Please enter a valid number.");
}
}
}
static int getExteriorSquareFeets()
{
// Ask user for a number for the size of the area and check for valid inputs. Display error message if the input
// is not valid and reprompt
int sqft;
while (true)
{
try
{
Console.Write("Enter size of exterior area (square-feets): ");
sqft = Convert.ToInt32(Console.ReadLine());
if (sqft > 0)
return sqft;
else
Console.WriteLine("Please enter a valid number.");
}
catch (Exception ex)
{
Console.WriteLine("Please enter a valid number.");
}
}
}
static long getCreditCard()
{
// Ask user for a number if the credit card and check for valid inputs. Display error message if the input
// is not valid and reprompt
long cc;
String cc_str;
while (true)
{
try
{
Console.Write("Enter size of your credit card number: ");
cc_str = Console.ReadLine();
cc = long.Parse(cc_str);
// check if the number has between 15 and 16 digits, and that the type of credit card is valid
if ((cc_str.Length == 15 || cc_str.Length ==16) && getCreditCardType(cc) != CreditCardType.NONE)
return cc;
else
Console.WriteLine("Please enter a valid credit card number.");
}
catch (Exception ex)
{
Console.WriteLine("Please enter a valid credit card number.");
}
}
}
static CreditCardType getCreditCardType(long number)
{
// convert number to string
String cc_str = number.ToString();
// check if the credit card has 15 numbers
if (cc_str.Length == 15) // it is AMEX
return CreditCardType.AMEX;
else // it has 16 digits
{
// check if the number begins with 4
if (cc_str[0] == '4')
return CreditCardType.VISA;
else if (cc_str[0] == '5') // master
return CreditCardType.MASTERCARD;
}
// if none of the conditions are met, then the credit card is of an unknown type
return CreditCardType.NONE;
}
static int calculateRequiredGallons(int area)
{
// Given the size of the area (Square-Feet), calculate the required number
// of gallons of paint
// Calculate
int gallons = 0;
while(area > 0)
{
gallons += 1;
area -= SQFT_PER_GALLON;
}
return gallons;
}
static int calculateInteriorCost(int interior)
{
// calculate the price to paint interior walls
// Calculate number of gallons
int gallons = calculateRequiredGallons(interior);
return gallons* INTERIOR_PRICE;
}
static int calculateExteriorCost(int exterior)
{
// calculate the price to paint exterior walls
// calculate number of gallons
int gallons = calculateRequiredGallons(exterior);
return gallons * EXTERIOR_PRICE;
}
static void generateReceipt(String name, int month, long credit_card, int interior, int exterior)
{
/*
* This functiion receives all the user's parameters and prints a receipt detailing the client name,
* the month to perform the paint job, credit card number and total costs
*
*/
// Convert card number to string
String cc_str = credit_card.ToString();
// Create a string filled with asterisks and only display the last 4 digits
String card_str = "";
for (int i = 0; i < cc_str.Length-4; i++)
card_str += "*";
card_str += cc_str.Substring(cc_str.Length - 4);
// Given the month id, get the name
String month_name = CultureInfo.CurrentCulture.DateTimeFormat.GetAbbreviatedMonthName(month).ToUpper();
String receipt_str = "\tDate: " + DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss") + "\n";
receipt_str += "\tName: " + name + "\n";
receipt_str += "\tCard Number: " + card_str + "\n";
receipt_str += "\tMonth Scheduled: " + month_name + " (" + month.ToString() + ")\n\n";
// Calculate costs
int interior_cost = calculateInteriorCost(interior);
int exterior_cost = calculateExteriorCost(exterior);
// Calculate gallons
int interior_gallons = calculateRequiredGallons(interior);
int exterior_gallons = calculateRequiredGallons(exterior);
int total_area = interior + exterior;
int total_gallons = interior_gallons + exterior_gallons;
int total_cost = interior_cost + exterior_cost;
Console.WriteLine(receipt_str);
Console.WriteLine("\t{0,-10}{1,25}{2,25}{3,25}", "Type", "Area (sqft)", "Paint (gal)", "Cost (\$)");
Console.WriteLine("\t{0,-10}{1,25}{2,25}{3,25}", "----", "-----------", "-----------", "--------");
Console.WriteLine("\t{0,-10}{1,25}{2,25}{3,25}", "Interior", interior.ToString(), interior_gallons.ToString(), "\$"+string.Format("{0:0.0}", interior_cost));
Console.WriteLine("\t{0,-10}{1,25}{2,25}{3,25}", "Exterior", exterior.ToString(), exterior_gallons.ToString(), "\$" + string.Format("{0:0.0}", exterior_cost));
Console.WriteLine("\t{0,-10}{1,25}{2,25}{3,25}", "----", "-----------", "-----------", "--------");
Console.WriteLine("\t{0,-10}{1,25}{2,25}{3,25}", "Total", total_area.ToString(), total_gallons.ToString(), "\$" + string.Format("{0:0.0}", total_cost));
}
static void Main(string[] args)
{
String name; // store user name here
int month, interior, exterior; // store month, interior and exterior areas
long credit_card; // store credit card number here
// Ask user for name
Console.Write("Enter your name: ");
name = Console.ReadLine();
// Ask for month
month = getMonth();
// Ask for interior and exterior sizes
interior = getInteriorSquareFeets();
// Ask for exterior
exterior = getExteriorSquareFeets();
// Ask for credit card number
credit_card = getCreditCard();
generateReceipt(name, month, credit_card, interior, exterior);
Console.Read();
}
}