Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.help > #2987 > unrolled thread
| Started by | mickie mae erpelo <ememerpz@gmail.com> |
|---|---|
| First post | 2014-08-09 06:22 -0700 |
| Last post | 2014-08-09 11:56 -0400 |
| Articles | 3 — 3 participants |
Back to article view | Back to comp.lang.java.help
Help please mickie mae erpelo <ememerpz@gmail.com> - 2014-08-09 06:22 -0700
Re: Help please Eric Sosman <esosman@comcast-dot-net.invalid> - 2014-08-09 09:30 -0400
Re: Help please Jeff Higgins <jeff@invalid.invalid> - 2014-08-09 11:56 -0400
| From | mickie mae erpelo <ememerpz@gmail.com> |
|---|---|
| Date | 2014-08-09 06:22 -0700 |
| Subject | Help please |
| Message-ID | <071eb276-0134-472a-9815-0505403554a6@googlegroups.com> |
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");
}
}
}
[toc] | [next] | [standalone]
| From | Eric Sosman <esosman@comcast-dot-net.invalid> |
|---|---|
| Date | 2014-08-09 09:30 -0400 |
| Message-ID | <ls57q2$2mo$1@dont-email.me> |
| In reply to | #2987 |
On 8/9/2014 9:22 AM, mickie mae erpelo wrote:
> These are my codes. the error is Package.java:143: error: <identifier>
> Help me please? What should i do?
>[...]
> word = Interger.parseInt(word);
> [...]
"Interger?"
--
esosman@comcast-dot-net.invalid
[toc] | [prev] | [next] | [standalone]
| From | Jeff Higgins <jeff@invalid.invalid> |
|---|---|
| Date | 2014-08-09 11:56 -0400 |
| Message-ID | <ls5gcr$sa7$1@dont-email.me> |
| In reply to | #2987 |
On 08/09/2014 09:22 AM, mickie mae erpelo wrote: > 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.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.help
csiph-web