Discussion:
Help please
(too old to reply)
mickie mae erpelo
2014-08-09 13:22:34 UTC
Permalink
These are my codes. the error is Package.java:143: error: <identifier>
Help me please? What should i do?



import javax.swing.*;

public class Package
{
private int packageWeight;
private char shippingMethod;
private double shippingCost;

public final double AIRSMALLPACKAGE = 2.00;
public final double AIRMEDIUMPACKAGE = 3.00;
public final double AIRHEAVYPACKAGE = 4.50;
public final double TRUCKLIGHTPACKAGE = 1.50;
public final double TRUCKMEDIUMPACKAGE = 2.50;
public final double TRUCKHEAVYPACKAGE = 3.25;
public final double MAILLIGHTPACKAGE = 0.50;
public final double MAILMEDIUMPACKAGE = 1.50;
public final double MAILHEAVYPACKAGE = 2.15;

//DEFAULT CONSTRUCTOR
public Package(int pacWeight, char shipMethod)
{
packageWeight = pacWeight;
shippingMethod = shipMethod;
shippingCost = calculateCost();
}

//METHOD TO GET AND SET PACKAGE WEIGHT
public int getWeight()
{
return packageWeight;
}
public void setWeight()
{
String weightOfPackage = new String(" ");
weightOfPackage = JOptionPane.showInputDialog(null, "Please enter the package weight?");
packageWeight = Integer.parseInt(weightOfPackage);
}

//METHOD TO GET AND SET PACKAGE SHIPPING COST
public char getShipMethod()
{
return shippingMethod;
}
public void setShipMethod(char shippingMethod)
{
String s = (JOptionPane.showInputDialog(null, "How would you like the package shipped, (A)ir, (T)ruck, or (M)ail ?"));
shippingMethod = s.charAt(0);
}

//METHOD TO GET AND SET PACKAGE SHIPPING COST
public double getCost()
{
return shippingCost;
}
public void setCost(double sCost)
{
shippingCost = sCost;
}

//METHOD TO CALCULATE SHIPPING COSTS
private double calculateCost()
{
double shipCost = 0;
if (packageWeight >= 1 && packageWeight <= 8)
{
if (shippingMethod == 'A') //Air Shipping
{
shipCost = AIRSMALLPACKAGE * packageWeight;
}
else if (shippingMethod == 'T') //Truck Shipping
{
shipCost = TRUCKLIGHTPACKAGE * packageWeight;
}
else if (shippingMethod == 'M') //Mail Shipping
{
shipCost = MAILLIGHTPACKAGE * packageWeight;
}
}
else if (packageWeight >=9 && packageWeight <= 16)
{
if (shippingMethod == 'A') //Air Shipping
{
shipCost = AIRMEDIUMPACKAGE * packageWeight;
}
else if (shippingMethod == 'T') //Truck Shipping
{
shipCost = TRUCKMEDIUMPACKAGE * packageWeight;
}
else if (shippingMethod == 'M') //Mail Shipping
{
shipCost = MAILMEDIUMPACKAGE * packageWeight;
}
}
else if (packageWeight >= 17)
{
if (shippingMethod == 'A') //Air Shipping
{
shipCost = AIRHEAVYPACKAGE * packageWeight;
}
else if (shippingMethod == 'T') //Truck Shipping
{
shipCost = TRUCKHEAVYPACKAGE * packageWeight;
}
else if (shippingMethod == 'M') //Mail Shipping
{
shipCost = MAILHEAVYPACKAGE * packageWeight;
}
}
return shipCost;
}

//METHOD TO DISPLAY RESULTS
public String display()
{
return "Package Weight: " + packageWeight + "ounce(s), Shipping Method: " + displayMethod() + ", Shipping Cost: $" + shippingCost;
}

//METHOD TO ASSIGN AND DISPLAY PACKAGE WEIGHT
public String displayMethod()
{
String method = "";
if (shippingMethod=='A')
{
method = "Air";
}
else if (shippingMethod=='T')
{
method = "Truck";
}
else if (shippingMethod=='M')
{
method = "Mail";
}
return method;

try
{
int word;
JOptionPane.showMessageDialog( null, "Please enter a word" );
word = Interger.parseInt(word);
}
catch(NumberFormatException)
{
JOptionPane.showMessageDialog( null, "Error");
}

}

}
Eric Sosman
2014-08-09 13:30:37 UTC
Permalink
Post by mickie mae erpelo
These are my codes. the error is Package.java:143: error: <identifier>
Help me please? What should i do?
[...]
word = Interger.parseInt(word);
[...]
"Interger?"
--
***@comcast-dot-net.invalid
Jeff Higgins
2014-08-09 15:56:54 UTC
Permalink
Post by mickie mae erpelo
These are my codes. the error is Package.java:143: error: <identifier>
Help me please? What should i do?
Now that your codes compiles,
thanks to help received from Eric Sosman:

Investigate, "the use of constants in Java".
Investigate, "java.lang.StringBuilder class".
Investigate, "Java mutable vs immutable objects".
Investigate, "Java class vs instance methods".
Investigate, "Java coding conventions".
Investigate, "user interface conventions".

Write some codes to validate input, including arguments
to your (misleadingly commented) default constructor.

Write some test harness codes, and test codes to
verify that your class behaves as you intend it to.
Stefan Ram
2014-08-10 17:46:57 UTC
Permalink
Post by mickie mae erpelo
catch(NumberFormatException)
catch( final java.lang.NumberFormatException exception )

Loading...