Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
public class Package {
private double Height, Length, Width, weight;
private bool air = false;
public double Height
{
get { return Height; }
set { Height = value; }
}
public double Length
{
get { return Length; }
set { Length= value; }
}
public double Width
{
get { return Width; }
set { Width = value; }
}
public double Weight
{
get { return Weight; }
set { Weight = value; }
}
public Package(){
height = 0;
length = 0;
width = 0;
weight = 0;
}
public Package(float height, float length, float width, float weight, bool air){
this.height = height;
this.length = length;
this.width = width;
this.weight = weight;
this.air = air;
}
public Package setShippingMethodToLand() {
this.air = false;
return this;
}
public Package setShippingMethodToAir(){
this.air = true;
return this;
}
public float getPrice();
public double getPerimeter()
{
return (2 * length) + (2 * width);
}
public double getVolume()
{
return height * width * length;
}
public double Surcharges()
{
double total = 0;
const double FLAT_RATE = 4.95, SM_WEIGHT = 3.95, MD_WEIGHT = 6.95, LG_WEIGHT = 9.95, LG_VOL = 5.95, LG_PERIMETER = 3.95, AIR_SHIP = 9.95;
total += FLAT_RATE;
if (weight >= 10 && weight < 15)
{
total += SM_WEIGHT;
}
else if (weight >= 15 && weight <= 20 )
{
total += MD_WEIGHT;
}
else if (weight >= 20 && weight <= 25 )
{
total += LG_WEIGHT;
}
if (volume > 4800)
{
total += LG_VOL;
}
if (perimeter > 130)
{
total += LG_PERIMETER;
}
if (air == true)
{
total += AIR_SHIP;
}
return total;
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ShippingRateCalculator
{
class Program
{
static void Main(string[] args)
{
int numPackages;
//double total = 0, extraCharges = 0;
string shippingType;
//Some of these things I am not sure how to write into methods. I also think some of the methods are really cluttered and could be written better, but I'm not sure how.
//Do not know how to write a restraint method. Have not written the summary stuff yet, since I think it will change when I talk to you
Console.WriteLine("How many packages would you like to ship?");
numPackages = Convert.ToInt32(Console.ReadLine());
Package[] packages = new Packages[numPackages];
for(int i = 0; i < packages.length; i++){
Package package = packages[i];
Console.WriteLine("What is the height of the package?");
package.setHeight(Convert.ToDouble(Console.ReadLine()));
Console.WriteLine("What is the length of the package?");
package.setLength = (Convert.ToDouble(Console.ReadLine()));
Console.WriteLine("What is the width of the package?");
packageWidth = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("How much does the package weigh?");
packageWeight = Convert.ToDouble(Console.ReadLine());
}
//Package information. Do not know how to do this in a method. Was thinking it would be ok with a for loop, but I can't think of a way to write it.
//Shipping information
Console.WriteLine("Is this package being sent by air or land?");
shippingType = Console.ReadLine();
if (shippingType == "air")
{
air = true;
}
//Dimension methods
packagePerimeter = Perimeter(packageLength, packageWidth);
packageVolume = Volume(packageHeight, packageWidth, packageLength);
//Surcharge method
extraCharges = Surcharges(packageWeight, packageVolume, packagePerimeter, air);
total += extraCharges;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment