|
-
February 5th, 2011, 05:10 PM
#1
Stack Overflow Error?
I am writing a program to act as a postage calculator. I am getting a stack overflow error and I can't for the life of me figure out WHY it is happening. Can one of you gents point me in the right direction??
Code:
namespace Lab2
{
public class Package
{
private string FName;
private string LName;
private string Address;
private string City;
private string State;
private string ZipCode;
private decimal Weight = 0.0M;// in ounces
private decimal Cost = 0.00M;// per ounce
// constructor
public Package(string FirstName1, string LastName1, string Address1, string City1, string State1,
string ZipCode1, decimal Weight1, decimal Cost1)
{
// implicit call to object constructor
FName = FirstName1;
LName = LastName1;
Address = Address1;
City = City1;
State = State1;
ZipCode = ZipCode1;
}// end Package constructor
// read-only property that gets first name
public string FirstName1
{
get
{
return FName;
}// end get
}// end property FirstName1
// read-only property that gets last name
public string LastName1
{
get
{
return LName;
}// end get
}// end property LastName1
// read-only property that gets address
public string Address1
{
get
{
return Address;
}// end get
}// end property Address11
// read-only property that gets city
public string City1
{
get
{
return City;
}//end get
}// end property City1
// read-only property that gets state
public string State1
{
get
{
return State1;
}//end get
}// end property State1
// read-only property that gets zip
public string ZipCode1
{
get
{
return ZipCode;
}// end get
}// end property ZipCode1
// read-only property that gets weight
public decimal Weight1
{
get
{
return Weight;
}// end get
set
{
Weight = (value < 0) ? 0 : value;
}// end set
}// end property Weight1
// read-only property that gets cost
public decimal Cost1
{
get
{
return Cost;
}//end get Cost1
set
{
Cost = (value < 0) ? 0 : value;
}// end set
}// end property Cost1
// Calculate cost
public virtual decimal CalculateCost()
{
return Weight1 * Cost1;
}// end method CalculateCost
// return string representation of Package object
public override string ToString()
{
return string.Format(
"{0}: {1} {2}: \n{3}: {4}\n{5}: {6} \n{7}: {8}\n{9}: {10}: \n{11}: {12} \n{13:F2}: {14} \n{15:C}: {16}",
"Sender's First Name", FirstName1,
"Sender's LastName1", LastName1,
"Address", Address1,
"City", City1,
"State", State1,
"ZipCode",ZipCode1,
"Weight", Weight1,
"Cost", Cost1);
}// end ToString method
}// end class Package
}// end namespace Lab2
namespace Lab2
{
public class TwoDayPackage : Package
{
private decimal Fee = 5.00M;// 2-day flat fee delivery charge
//derived class constructor
public TwoDayPackage(string FirstName1, string LastName1, string Address1, string City1,
string State1, string ZipCode1, decimal Weight1, decimal Cost1)
: base(FirstName1, LastName1, Address1, City1, State1, ZipCode1, Weight1, Cost1)
{
Fee1 = Cost1;
}// end constructor
// property that gets and sets
public decimal Fee1
{
get
{
return Fee;
}// end get
set
{
Fee = (value < 0) ? 0 : value;
}// end set
}// end property Fee1
// calculate total cost
public override decimal CalculateCost()
{
return Fee1 + base.CalculateCost();
}// end method CalculateCost
// return string representation of TwoDayPackage
public override string ToString()
{
return string.Format("Fee {0}\nFee: {1:C}",
base.ToString(), Fee1);
}// end method ToString
}// end class TwoDayPackage
}// end namespace Lab2
namespace Lab2
{
public class OverNightPackage : Package
{
private decimal AddFee = 10.00M;// additional fee per ounce for overnight delivery
// derived class constructor
public OverNightPackage(string FirstName1, string LastName1, string Address1, string City1, string State1,
string ZipCode1, decimal Weight1, decimal Cost1)
: base(FirstName1, LastName1, Address1, City1, State1, ZipCode1, Weight1, Cost1)
{
AddFee1 = Cost1;
}// end constructor
// property for AddFee1
public decimal AddFee1
{
get
{
return AddFee;
}// end get
set
{
AddFee = (value < 0) ? 0 : value;
}// end set
}// end property AddFee1
// calculate cost
public override decimal CalculateCost()
{
return AddFee1 + base.CalculateCost();
}// end method CalculateCost
// return string representation of OverNightPackage
public override string ToString()
{
return string.Format("Cost {0}\nAdditional Fee: {1:C}",
base.ToString(), AddFee1);
}// end method ToString
}// end class OverNightPackage
}// end namespace Lab2
namespace Lab2
{
public class PackageTest
{
public static void Main(string[] args)
{
// instantiate Package object
Package Sender = new Package("Jane", "Doe", "121 Broad St", "Houston", "Texas", "77077",
5.0M, 10.00M);
Sender.CalculateCost();
Console.WriteLine(Sender.ToString());
// instantiate TwoDayPackage object
TwoDayPackage TwoDayPkg = new TwoDayPackage("John", "Doe", "1201 Main St",
"Dallas", "Texas", "75208", 7.5M, 13.00M);
// instantiate OverNightPackage object
OverNightPackage OverNightPkg = new OverNightPackage("Mary", "Bloom", "540 River Lane",
"Dallas", "Texas", "75055", 3.0M, 7.50M);
// display Sender data
Console.WriteLine("First name is: {0}", Sender.FirstName1);
Console.WriteLine("Last name is: {0}", Sender.LastName1);
Console.WriteLine("Address is: {0}", Sender.Address1);
Console.WriteLine("City: {0}", Sender.City1);
Console.WriteLine("State: {0}", Sender.State1);
Console.WriteLine("Zip: {0}", Sender.ZipCode1);
Console.WriteLine("Weight of package: {0:F2}", Sender.Weight1);
Console.WriteLine("Cost of package: {0:C}", Sender.Cost1);
Console.WriteLine(TwoDayPkg.ToString());
Console.WriteLine(OverNightPkg.ToString());
}
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|