This is Q(6) of the incomplete program. Please complete this program.
using System;
namespace _8e6
{
class Program
{
static void Main(string[] args)
{
IceCreamCone icc1 = IceCreamConeProgram("Orange", 4);
IceCreamCone icc2 = IceCreamConeProgram("Apple", 5);
IceCreamCone icc3 = IceCreamConeProgram("Mango", 6);
Console.WriteLine(icc1.GetFlavor(), icc1.GetScoops());
Console.ReadKey();
}
static IceCreamCone IceCreamConeProgram(string flavor, int scoop)
{
IceCreamCone icc = null;
try
{
icc = new IceCreamCone(flavor, scoop);
}
catch (IceCreamConeException e)
{
Console.WriteLine(e.Message);
}
return icc;
}
class IceCreamConeException : Exception
{
public IceCreamConeException(string flavorAndNoOfScoops) : base(flavorAndNoOfScoops)
{
}
}
class IceCreamCone
{
string iceCreamFlavor;
int scoops;
public IceCreamCone(string iceCreamFlavor, int scoops)
{
this.iceCreamFlavor = iceCreamFlavor;
this.scoops = scoops;
}
public string GetFlavor()
{
if ((iceCreamFlavor != "vanilla") || (iceCreamFlavor != "chocolate") || (iceCreamFlavor != "strawberry") || (iceCreamFlavor != "peach") || (iceCreamFlavor != "banana"))
throw new IceCreamConeException(String.Format("Ice Cream Flavor {0}", iceCreamFlavor));
return this.iceCreamFlavor;
}
public int GetScoops()
{
if (scoops >= 3)
throw new IceCreamConeException(String.Format("No of Scoops {0}", scoops));
return this.scoops;
}
}
}
}
Loading

VulpesRank #55 · 29.2K reputationPosted Feb 14, 2012, 9:21 AM EST
Notice that you're supposed to get input from the user by calling the GetFlavor() and GetScoops() methods from the IceCreamCone class constructor:
Posted Feb 14, 2012, 11:34 AM EST
if ((iceCreamFlavor != "vanilla") && (iceCreamFlavor != "chocolate") && (iceCreamFlavor != "strawberry") && (iceCreamFlavor != "peach") && (iceCreamFlavor != "banana"))
if ((iceCreamFlavor != "vanilla") || (iceCreamFlavor != "chocolate") || (iceCreamFlavor != "strawberry") || (iceCreamFlavor != "peach") || (iceCreamFlavor != "banana"))
VulpesRank #55 · 29.2K reputationPosted Feb 14, 2012, 11:45 AM EST
Posted Feb 14, 2012, 11:58 AM EST
Posted Feb 14, 2012, 9:18 PM EST
int scoops = Convert.ToInt32(Console.ReadLine());
AND
int.TryParse(Console.ReadLine(), out scoops);
VulpesRank #55 · 29.2K reputationPosted Feb 14, 2012, 11:57 PM EST
The second line will not have this effect and will, harmlessly, set scoops to zero if an invalid integer is entered.
Posted Feb 15, 2012, 2:36 AM EST
VulpesRank #55 · 29.2K reputationPosted Feb 15, 2012, 3:58 AM EST
These would throw FormatExceptions if you're using Convert.ToInt32.
Posted Feb 15, 2012, 4:09 AM EST