In: Computer Science
ONLY USE VISUAL STUDIO (NO JAVA CODING)
VISUAL STUDIO -> C# -> CONSOLE APPLICATION
Write a C# (console) program to calculate the number of shipping labels that can be printed on a sheet of paper.
This program will use a menu that includes the following options:
The first menu option will ask the user to enter the width and height of the paper.
The second menu option will ask the user for the width and height of the label.
The third menu option will calculate the number of whole labels that can fit on the sheet and the report the following:
Your program must:
Print a welcome message including a program description and your name before the menu is displayed
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp2
{
class Program
{
static int paperWidth, paperHeight, labelWidht, labelHeight;
static int ch;
static void Main(string[] args)
{
do
{
Console.WriteLine("1. Enter/Update paper size");
Console.WriteLine("2. Enter/Update label size");
Console.WriteLine("3. Generate report");
Console.WriteLine("4. Exit");
try
{
ch = Convert.ToInt32(Console.ReadLine());
}
catch (Exception)
{
Console.WriteLine("Please provide valid integer values for
choice");
continue;
}
switch (ch)
{
case 1:
readPaperSize();
break;
case 2:
readLabelSize();
break;
case 3:
generateReport();
break;
case 4:
break;
default:
break;
}
} while (ch != 4);
}
static void readPaperSize()
{
try
{
Console.WriteLine("Enter paper widht:");
paperWidth = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter paper height:");
paperHeight = Convert.ToInt32(Console.ReadLine());
}
catch (Exception)
{
Console.WriteLine("Please provide valid integer values for
sizes");
}
}
static void readLabelSize()
{
try
{
Console.WriteLine("Enter label widht:");
labelWidht = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter label height:");
labelHeight = Convert.ToInt32(Console.ReadLine());
}
catch (Exception)
{
Console.WriteLine("Please provide valid integer values for
sizes");
}
}
static void generateReport()
{
if (paperHeight == 0 || paperWidth == 0)
{
Console.WriteLine("Please provide paper size");
return;
}
if (labelHeight == 0 || labelWidht == 0)
{
Console.WriteLine("Please provide label size");
return ;
}
if (paperHeight < labelHeight)
{
Console.WriteLine("Label hight cannot be greater than paper
size");
return;
}
if (paperWidth < labelWidht)
{
Console.WriteLine("Label width cannot be greater than paper
size");
return;
}
Console.Write("Paper size: %d * %d", paperHeight,
paperWidth);
Console.Write("Label size: %d * %d", labelHeight,
labelWidht);
int paperArea = paperHeight * paperWidth;
int labelArea = labelHeight * labelWidht;
int totalLabels = paperArea / labelArea;
Console.Write("Total labels: %d", totalLabels);
Console.Write("Total Paper Area (Square inches): %d",
paperArea);
Console.Write("Area used by labels (Square Inches): %d", labelArea
* totalLabels);
Console.Write("Amount of unused paper (Percentage of Total Paper
Area): %f", (paperArea / (labelArea * totalLabels)) * 100);
}
}
}