I trying to finish this assignment for Java and it's really getting to me. I haven't had this much trouble in the past, but things ramped up pretty quickly and I'm really stuck. I'll post what I have, although it's not much, if someone out there is kind enough to lend me a hand. The sad thing is I don't think this will take that long, as it seems to be a fairly straight forward program - but I'm pulling my hair out and my teacher is really no help at all.

The basic jist of the program is that a user will enter in command line arguments relating to the weight of a package and shipping method for said package. Based on the command line argument info the program will tell you how much the cost to ship the package is, insurance cost for the package and the total.


My program needs to have five classes - Main, Shipment, Insurance (a subclass of Shipment), CheckShipment, DisplayData.

Main Class
uses command-line arguments
10 T
10 is weight
T is shipping method Truck
creates an Insurance object to calculate and display
the shipment cost
the insurance cost
the total cost

uses the CheckShipment class to check the validity of the requested weights and methods
will throw an Exception
if the weight is not between 0 and 100 kilos
if an invalid method is requested
if the first argument is not an integer
if no command-line arguments are entered


Shipment Class -
has four protected instance variables
weight
is the weight of the shipment
method
is the shipping method
‘M’ or ‘m’ for mail
‘A’ or ‘a’ for air
‘T’ or ‘t’ for truck
shippingCost
is the cost of shipping
methodCost
is the cost of using a particular method and weight

has a private method calculateCost()
does not take an argument
does not return a value
calculates the cost of a given shipment

has a constructor
takes two arguments
method
weight

Insurance -subclass of Shipment
has a method calculateInsurance()
is private
does not take an argument
does not return a value
calculates the cost of insurance

has a public method displayOrder()
uses the DisplayData class
returns a String that can be used to display the details of a given shipment


I'm not looking for someone to just finish this for me, I'm genuinely stuck and want to figure this out, so if there's a kind soul out there who can lend a hand i'd be forever grateful. Thanks!

I thought you said you'd post what you had. Unfortunately for you all I see is the assignment text. Where is your code? You should, at least, be able to create class shells with empty methods and vars for the described attributes, right? Start with that, then start filling those methods in, just do one at a time.

I didn't supply code because I was waiting for a reply.I will also say that the price for the package depends on the weight and what shipping method is used. Weight in kilograms -

if package weighs 1-8 - Air per kilo: $2.00 Truck per kilo: $1.50 Mail per kilo: $0.50
if package weighs 9-16 - Air per kilo: $3.00 Truck per kilo: $2.35 Mail per kilo: $1.50
if package weighs 17 and over - Air per kilo: $4.50 Truck per kilo: $3.25 Mail per kilo: $2.15

I need to have something with arrays for each of the prices and weight right? Basically based on the info above, I would type in the command line arguments 10 M, with 10 being the weight and M being the method. Then it needs to calculate total. If someone could show me a very crude version of this type of program that would be very very helpful. I'm stressing out like crazy.

This is what I have, not much I know, but I'm stuck.

public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {

        Insurance one = new Insurance();
        System.out.println();

    }

}
public class Insurance extends Shipment {

    int weight = 100;
    char method = air;

    protected double insuranceCost;
    protected double totalCost;


    public Insurance (int weight, char method){

    }

    public double getInsuranceCost(){
        return insuranceCost;

    }

    public double getTotalCost(){
        return totalCost;
    }

    public String displayOrder(){
        return
    }


    private void calculateInsurance(){

    }

}
public class Shipment {

    int weight = 100;
    char method = Air;
    
    
    
 public class Shipment (int weight, char method){
    
    
    protected int weight;
    
    protected char method;
    
    protected double shippingCost;
        
    
    
    protected double methodCost; {
        
    }
        
    }

 public double getShippingCost(){
     return shippingCost;
 }


}
public class CheckShipment {

    public static boolean checkMethod(char method){
        return method;
    }
    
    
    public static boolean checkWeight(int weight){
        return weight;
    }



    
}

Okay? And the rest of my suggestion? I am not going to "finish" your code, if that's what you think. At least try to implement some of the methods, the constructors, at least.

This article has been dead for over six months. Start a new discussion instead.