C# Application Write a C# program (A Console program) that prompts the user for
ID: 3589285 • Letter: C
Question
C# Application
Write a C# program (A Console program) that prompts the user for the weight of the article, the zone to which it is going and whether it should go by air or it is local, and then print out the correct stamp. Test your program with the following scenario.
Create a C# Stamp class. Afterwards test your program with the scenario given below:
1. Create a Local stamp for an article weighing 2 oz. to zone 3.
2. Create an Air Mail stamp for an article weighing 2 oz. to zone 2.
3. Create a Local stamp for an article weighing ½ oz. to zone 1.
4. Create a Local stamp for an article weighing 0.58 oz. to zone 1.
5. Create a Local stamp for an article weighing 0.56 oz. to zone 2.
6. Create an Air mail stamp for an article weighing 1.0 oz. to zone 1 All mail (Local and Air) is divided in to three zones.
If the weight of the mail is ½ ounce or less, all local mail (in all three zones) must have a rate of $0.49. For the first ½ ounce or less, for all three zones, all air mail must have a rate of $0.95. Any mail more than ½ ounce is subjected to an additional charge. SAMPLE OUTPUT:
sample output weight FIRST 1/2 ounce or less For every next 1/2 ounce or less zone local air mail local air mail zone 1 0.49 0.95 0.49*.50 0.95*0.50 zone 2 0.49 0.95 0.49*0.65 0.95*0.60 zone 3 0.49 0.95 0.49*0.80 0.95*0.90Explanation / Answer
Note : I am assuming additional charges for zone 1 and local mail stamp is : 0.5 i.e For every next 1/2 ounce, end user need to pay 0.49+0.50 = $0.99
++++++++++++++++++++++++++++++++++++++
using System.IO;
using System;
class Stamp
{
static void Main()
{
float[] zone1Matrix = {0.49f,0.95f,0.50f,0.50f}; // {<local first 1/2 ounce charges>,<air mail first 1/2 oz charges>, <local extra charges per 1/2 ounce>, <air mail extra charges per 1/2 ounce> }
float[] zone2Matrix = {0.49f,0.95f,0.65f,0.60f};
float[] zone3Matrix = {0.49f,0.95f,0.80f,0.90f};
float[] currentZoneMatrix = null; // it stores one of the above matrix as per zone at run time
float charges = 0.0f;
Console.Write("Enter the weight of Article in ounce : ");
float weight = float.Parse(Console.ReadLine());
Console.WriteLine(weight+" oz");
Console.Write("Enter the Zone to which it is going : ");
int zone = int.Parse(Console.ReadLine());
Console.WriteLine(zone);
Console.Write("Mail [local/air] : ");
String mail = Console.ReadLine();
Console.WriteLine(mail);
// Calculate total number of units.
//Half Ounces = 1 unit.
//0.75 Ounce = 2 unit.
int unit=0;
int weightWithOutDecimal = (int)weight;
int weightAfterDecimal = (int)Math.Round((weight - Math.Truncate(weight))*100);
if(weightAfterDecimal == 0){
unit = weightWithOutDecimal * 2;
}
else if(weightAfterDecimal > 50){
unit = weightWithOutDecimal * 2 + 2;
}
else {
unit = weightWithOutDecimal * 2 + 1;
}
Console.WriteLine("Total Number of Units : "+unit);
//assigning matrix based on zone to currentZoneMatrix
switch(zone){
case 1 :
currentZoneMatrix = zone1Matrix;
break;
case 2 :
currentZoneMatrix = zone2Matrix;
break;
case 3 :
currentZoneMatrix = zone3Matrix;
break;
}
float firstUnitcharges = 0.0f;
float additionalCharges = 0.0f;
switch(mail){
case "local" :
firstUnitcharges = currentZoneMatrix[0];
additionalCharges = currentZoneMatrix[2];
break;
case "air" :
firstUnitcharges = currentZoneMatrix[1];
additionalCharges = currentZoneMatrix[3];
break;
}
if(unit==1){
charges = firstUnitcharges;
}
else{
charges = firstUnitcharges + ((additionalCharges + firstUnitcharges) * (unit-1));
}
Console.WriteLine("Charges : "+charges);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.