Question

Modify the code, so that it will check the various user inputs for validity (e.g., months...

Modify the code, so that it will check the various user inputs for validity (e.g., months being between 1 - 12),

- if invalid value was entered, ask user to enter a new (& correct) value,

- check to see if new value is valid

- if valid allow the user to continue.

- if still not valid repeat this process, until valid value is entered

__________________________________________________________________________________________________

QUESTION:

Desc: This program creates a painting order receipt.
Ask for the following information:
Customer name.
Month to schedule painting, numbers between (1 - 12) for month number are valid
Customer credit card number (the card number can be either 15 or 16 digits).
the number of interior and exterior square feet needed to paint.
Calculate the following:
Total number of gallons needed (int/ext/all)
Total paint cost (int/ext/all).
Cost for a gallon of paint is $600 (interior) and $1200 (exterior),
Each gallon of paint can paint 400 SQFT
  
Create a receipt that looks like the sample below and display it to the user.
  
Date: 10/08/2019
Name:   
Card Number: ******3456
Month Scheduled: 11-NOV

Month Int(Gal) Int($) Ext(Gal) Ext($) Total(Gal) Total($)
------- --------- ----------- --------- ----------- ----------- ------------
11-Nov 5 $3,000.00 4 $4,800.00 9 $7,800.00
  
  

Line 1: [tab]Date: Today's Date
Line 2: [tab]Name: Customer Name
Line 3: [tab]Card Number: cardnumber*
Line 4: [tab]Month Scheduled: Month**
   <------------ 35 chars ----------->
   * Only 10 digits of the card number is displayed,
from those 10 digits, the first 6 are [*] followed by the last 4 digits of the card.
Example: Cardnumber 1234567890123456, will be displayed as: ******3456
   ** Month is the combination of Month Number entered, a "-", followed by the 3-letter month name
Example: Month entered: 11, Month will be displayed as: 11-NOV

ANSWER(which needs to be modified with loops):

using System;
using static System.Console;

namespace Mid1
{
enum Months {JAN=1, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC };

class Program

static void Main(string[] args)
{
const double COST_PAINT_INT = 600;
const double COST_PAINT_EXT = 1200;
const int SQFT_PER_GALLON = 400;

int monthScheduled;

int monthSqftInt = 0;
int monthSqftExt = 0;
int gallonsInt = 0;
int gallonsExt = 0;
int gallonsPartialInt = 0;
int gallonsPartialExt = 0;
int gallonsTotal = 0;

double costMonthInt = 0;
double costMonthExt = 0;
double costTotalInt = 0;
double costTotalExt = 0;
double costTotal = 0;

string dateOrdered = DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss");
string name;
string cardNumber, cardNumberProtect;
string monthDisplayed;
string receipt;


// Ask user for their name and card number

Write("\nPlease enter your name: ");
name = ReadLine();

// Ask the user for the month scheduled to paint
Write("\nPlease enter the number for the month you want your painting scheduled (1-12): ");
monthScheduled = Convert.ToInt32(ReadLine());
  

// Ask the user for the SQFT needed to paint (interior/exterior)
Write("\nPlease enter the square feet of interior walls you want painted: ");
monthSqftInt = Convert.ToInt32(ReadLine());
Write("\nPlease enter the square feet of exterior walls you want painted: ");
monthSqftExt = Convert.ToInt32(ReadLine());

// Ask the user for their 15/16 digit credit card number
Write("\nPlease enter your card number (AMEX, VISA, & MC cards accepted): ");
cardNumber = ReadLine();

// Calculations

// Calculate the gallons needed for painting
gallonsInt = monthSqftInt / SQFT_PER_GALLON;
gallonsExt = monthSqftExt / SQFT_PER_GALLON;

gallonsPartialInt = monthSqftInt % SQFT_PER_GALLON;
gallonsPartialExt = monthSqftExt % SQFT_PER_GALLON;

gallonsInt += gallonsPartialInt.CompareTo(0);
gallonsExt += gallonsPartialExt.CompareTo(0);

gallonsTotal = gallonsInt + gallonsExt;

// Calculate the cost
costMonthInt = gallonsInt * COST_PAINT_INT;
costMonthExt = gallonsExt * COST_PAINT_EXT;
costTotal = costMonthInt + costMonthExt;

// Create month displayed
monthDisplayed = monthScheduled + "-" + (Months)monthScheduled;

// Create protected card number
cardNumberProtect = "******" + cardNumber.Substring(cardNumber.Length - 4, 4);

// Display Receipt

receipt = String.Format("\n\t{0, -18}{1, 22}", "Date:", dateOrdered);
receipt += String.Format("\n\t{0, -18}{1, 22}", "Name:", name);
receipt += String.Format("\n\t{0, -18}{1, 22}", "Cardnumber:", cardNumberProtect);
receipt += String.Format("\n\t{0, -18}{1, 22}\n", "Month Scheduled:", monthDisplayed);
receipt += String.Format("\n{0, -7}{1, 13}{2, 16}{3, 13}{4, 16}{5, 13}{6, 17}",
"Month", "Int (Gal)", "Int ($)", "Ext (Gal)", "Ext ($)", "Total (Gal)", "Total ($)");
receipt += String.Format("\n{0, -7}{1, 13}{2, 16}{3, 13}{4, 16}{5, 13}{6, 17}",
"-------", "-----------", "--------------", "-----------", "--------------", "-----------", "---------------");
receipt += String.Format("\n{0,-7}{1, 13}{2, 16}{3, 13}{4, 16}{5, 13}{6, 17}",
monthDisplayed, gallonsInt, costMonthInt.ToString("C2"),
gallonsExt, costMonthExt.ToString("C2"),
gallonsTotal, costTotal.ToString("C2"));

WriteLine(receipt);

ReadLine();

}
}
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

using System;
using static System.Console;

namespace Mid1
{
enum Months {JAN=1, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC };

class Program
{
static void Main(string[] args)
{
const double COST_PAINT_INT = 600;
const double COST_PAINT_EXT = 1200;
const int SQFT_PER_GALLON = 400;

int monthScheduled;
int flag=0;
int monthSqftInt = 0;
int monthSqftExt = 0;
int gallonsInt = 0;
int gallonsExt = 0;
int gallonsPartialInt = 0;
int gallonsPartialExt = 0;
int gallonsTotal = 0;

double costMonthInt = 0;
double costMonthExt = 0;
double costTotalInt = 0;
double costTotalExt = 0;
double costTotal = 0;

string dateOrdered = DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss");
string name;
string cardNumber, cardNumberProtect;
string monthDisplayed;
string receipt;


// Ask user for their name and card number

Write("\nPlease enter your name: ");
name = ReadLine();

// Ask the user for the month scheduled to paint
do{
if(flag<1){
Write("\nPlease enter the number for the month you want your painting scheduled (1-12): ");
flag=flag+1;
}
else
Write("\nPlease enter the correct number for the month you want your painting scheduled (1-12): ");
monthScheduled = Convert.ToInt32(ReadLine());
}while(monthScheduled<=0 || monthScheduled>=13);
flag=0;
// Ask the user for the SQFT needed to paint (interior/exterior)
Write("\nPlease enter the square feet of interior walls you want painted: ");
monthSqftInt = Convert.ToInt32(ReadLine());
Write("\nPlease enter the square feet of exterior walls you want painted: ");
monthSqftExt = Convert.ToInt32(ReadLine());

// Ask the user for their 15/16 digit credit card number
do{
if(flag<1){
Write("\nPlease enter your card number (AMEX, VISA, & MC cards accepted): ");
flag=flag+1;
}
else
Write("\nPlease enter your correct card number (AMEX, VISA, & MC cards accepted): ");
cardNumber = ReadLine();
}while(cardNumber.Length!=15 && cardNumber.Length!=16);
flag=0;
// Calculations

// Calculate the gallons needed for painting
gallonsInt = monthSqftInt / SQFT_PER_GALLON;
gallonsExt = monthSqftExt / SQFT_PER_GALLON;

gallonsPartialInt = monthSqftInt % SQFT_PER_GALLON;
gallonsPartialExt = monthSqftExt % SQFT_PER_GALLON;

gallonsInt += gallonsPartialInt.CompareTo(0);
gallonsExt += gallonsPartialExt.CompareTo(0);

gallonsTotal = gallonsInt + gallonsExt;

// Calculate the cost
costMonthInt = gallonsInt * COST_PAINT_INT;
costMonthExt = gallonsExt * COST_PAINT_EXT;
costTotal = costMonthInt + costMonthExt;

// Create month displayed
monthDisplayed = monthScheduled + "-" + (Months)monthScheduled;

// Create protected card number
cardNumberProtect = "******" + cardNumber.Substring(cardNumber.Length - 4, 4);

// Display Receipt

receipt = String.Format("\n\t{0, -18}{1, 22}", "Date:", dateOrdered);
receipt += String.Format("\n\t{0, -18}{1, 22}", "Name:", name);
receipt += String.Format("\n\t{0, -18}{1, 22}", "Cardnumber:", cardNumberProtect);
receipt += String.Format("\n\t{0, -18}{1, 22}\n", "Month Scheduled:", monthDisplayed);
receipt += String.Format("\n{0, -7}{1, 13}{2, 16}{3, 13}{4, 16}{5, 13}{6, 17}",
"Month", "Int (Gal)", "Int ($)", "Ext (Gal)", "Ext ($)", "Total (Gal)", "Total ($)");
receipt += String.Format("\n{0, -7}{1, 13}{2, 16}{3, 13}{4, 16}{5, 13}{6, 17}",
"-------", "-----------", "--------------", "-----------", "--------------", "-----------", "---------------");
receipt += String.Format("\n{0,-7}{1, 13}{2, 16}{3, 13}{4, 16}{5, 13}{6, 17}",
monthDisplayed, gallonsInt, costMonthInt.ToString("C2"),
gallonsExt, costMonthExt.ToString("C2"),
gallonsTotal, costTotal.ToString("C2"));

WriteLine(receipt);

ReadLine();

}
}
}

OUTPUTS:

Add a comment
Know the answer?
Add Answer to:
Modify the code, so that it will check the various user inputs for validity (e.g., months...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In Chapter 4 of your book, you created an interactive application named MarshallsRevenue that prompts a...

    In Chapter 4 of your book, you created an interactive application named MarshallsRevenue that prompts a user for the number of interior and exterior murals scheduled to be painted during a month and computes the expected revenue for each type of mural. The program also prompts the user for the month number and modifies the pricing based on requirements listed in Chapter 4. Now, modify the program so that the user must enter a month value from 1 through 12....

  • Credit card numbers follow certain patterns. A credit card number must have between 13 and 16...

    Credit card numbers follow certain patterns. A credit card number must have between 13 and 16 digits. The number must start with the following: 4 for Visa cards 5 for MasterCard cards 37 for American Express cards 6 for Discover cards In 1954, Hans Luhn of IBM proposed an algorithm for validating credit card numbers. The algorithm is useful to determine whether a card number is entered correctly or is scanned correctly by a scanner. Almost all credit card numbers...

  • Validating Credit Card Numbers Write a program named Creditcard.java that prompts the user for a credit...

    Validating Credit Card Numbers Write a program named Creditcard.java that prompts the user for a credit card number and determines whether it is valid or not. (Much of this assignment is taken from exercise 6.31 in the book) Credit card numbers follow certain patterns. A credit card number must have between 13 and 16 digits, and must start with: 4 for Visa cards 5 for Master cards 6 for Discover cards 37 for American Express cards The algorithm for determining...

  • Please answer the following question with Java Modify the Employee and ProductionWorker classes provided below so...

    Please answer the following question with Java Modify the Employee and ProductionWorker classes provided below so they throw exceptions when the following errors occur. - The Employee class should throw an exception named InvalidEmployeeNumber when it receives an employee number that is less than 0 or greater than 9999. - The ProductionWorker class should throw an exception named InvalidShift when it receives an invalid shift. - The ProductionWorker class should thrown anexception named InvalidPayRate when it receives a negative number...

  • This is just part of a C# windows form Application. When the user enters their information, checks the check box to save info and hits the payment button the information is saved to a .txt file. When...

    This is just part of a C# windows form Application. When the user enters their information, checks the check box to save info and hits the payment button the information is saved to a .txt file. When user enters last name and clicks autofill if name is found in file it will auto fill the boxes but i'm having issues with this part. For some reason it skips the firstname box and enters the last name in the first name...

  • Use java and continue stage 2 and 3 stage 1 code public abstract class BabyItem { protected String name;...

    Use java and continue stage 2 and 3 stage 1 code public abstract class BabyItem { protected String name; public BabyItem() { name=""; } public BabyItem(String name) { this.name = name; } public String getName() { return name; } public void setName(String name) { } public abstract double getCost(); } ======================================================================================== public class BabyFood extends BabyItem { private int numberOfJars; private double pricePerDozen; public BabyFood() { super(); numberOfJars = 0; pricePerDozen = 0; } public BabyFood(int numberOfJars, double pricePerDozen) {...

  • Here is the code I made, but the test case is not working, it goes wrong...

    Here is the code I made, but the test case is not working, it goes wrong when the binary string convert to decimal. please help. #include "stdafx.h" #include <iostream> #include <string> #include <math.h> #include <locale> using namespace std; // function for option 1 void decToBin(int number) {        int array[16];        int i = 0;        for (int counter = 0; counter < 16; counter++)        {               array[counter] = 0;        }        while (number > 0)        {...

  • Can someone modify my code so that I do not get this error: Exception in thread...

    Can someone modify my code so that I do not get this error: Exception in thread "main" java.lang.NullPointerException at java.awt.Container.addImpl(Container.java:1043) at java.awt.Container.add(Container.java:363) at RatePanel.<init>(RatePanel.java:64) at CurrencyConverter.main(CurrencyConverter.java:16) This code should get the amount of money in US dollars from user and then let them select which currency they are trying to convert to and then in the textfield print the amount //********************************************************************* //File name: RatePanel.java //Name: Brittany Hines //Purpose: Panel for a program that convers different currencyNamerencies to use dollars //*********************************************************************...

  • // C code // If you modify any of the given code, the return types, or...

    // C code // If you modify any of the given code, the return types, or the parameters, you risk getting compile error. // Yyou are not allowed to modify main (). // You can use string library functions. #include <stdio.h> #include <stdlib.h> #include <string.h> #pragma warning(disable: 4996) // for Visual Studio #define MAX_NAME 30 // global linked list 'list' contains the list of patients struct patientList {    struct patient *patient;    struct patientList *next; } *list = NULL;  ...

  • Can some one fix my code so that the output result same as below? BAR PLOT...

    Can some one fix my code so that the output result same as below? BAR PLOT OF CYLINDER PRESSURE -VS- TIME pressure is on horizontal axis - units are psi time is on vertical axis - units are msec    0.0         20.0        40.0          60.0        80.0       100.0      120.0       +---------+---------+---------+---------+---------+---------+ 0.0|************************* 1.5|********************************* 3.0|***************************************** 4.4|**************************************************      05.9|********************************************* 7.4|******************************** 8.9|*********************** 10.4|***************** 11.9|************** 13.3|************* 14.8|************ 16.3|********* 17.8|******* 19.3|****** 20.7|****** 22.2|******* 23.7|******* .......... ===================== her is my code //#include"stdafx.h" #include #include #include #include #include #include using...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT