# Setting up postage calculations

• January 15th, 2014, 09:21 AM
jingojang
Setting up postage calculations
(Hopefully this is the correct forumsection to post in)

Hello,

I need help writing a Java code that is using various dialog boxes and calculates postage for letters, here are some exampel values:

"Max weight in grams" "Price"

"20" "6 kr"
"100" "12 kr"
"250" "24 kr"
"500" "36 kr"
"1000" "48 kr"
"2000" "72 kr"

Letters over 2000grams are considered packages.

kr is short for kronor, swedish currency.

If you can document the code it wouldn't hurt so I can learn from it, you do not have to, I can google most of it.

Feel free to ask if I have been unclear with the information given.
• January 15th, 2014, 09:27 AM
KevinWorkman
Re: Setting up postage calculations
That is not how this works. We aren't going to do your homework for you.

What have you tried? Where are you stuck? What is your specific technical question?
• January 15th, 2014, 09:42 AM
jingojang
Re: Setting up postage calculations
I know how to create a JPanel with input and link a few numbers to it, not sure how to make all the different values.

Code :

package pakul;

import javax.swing.*;
import java.text.*;
public class pakul {
public static void main (String[] arg) {
int knappNr;
do {
String x = JOptionPane.showInputDialog("Vad väger ditt brev/paket?");
NumberFormat r = NumberFormat.getInstance();
int calc = Integer.parseInt(x);

if (calc == 20)
JOptionPane.showMessageDialog(null, "Porto kostar 6kr med den vikten.");

else if (calc == 100)
JOptionPane.showMessageDialog(null, "Porto kostar 12kr med den vikten.");

else if (calc == 250)
JOptionPane.showMessageDialog(null, "Porto kostar 24kr med den vikten.");
knappNr = JOptionPane.showConfirmDialog(null, "Vill du beräkna portot igen?", "Fråga", JOptionPane.YES_NO_OPTION);
} while (knappNr == 0);
}
}

Is this close? I want the person using the program to type in a value and then a messagedialog will come up.

EDIT:

Code :

package pakul;

import javax.swing.*;
import java.text.*;
public class pakul {
public static void main (String[] arg) {
int knappNr;
do {
String x = JOptionPane.showInputDialog("Vad väger ditt brev/paket?");
NumberFormat r = NumberFormat.getInstance();
int calc = Integer.parseInt(x);

if (calc >= 20 && calc <= 99)
JOptionPane.showMessageDialog(null, "Porto kostar 6kr med den vikten.");

else if (calc >= 100 && calc <= 249)
JOptionPane.showMessageDialog(null, "Porto kostar 12kr med den vikten.");

else if (calc >= 250 && calc <= 499)
JOptionPane.showMessageDialog(null, "Porto kostar 24kr med den vikten.");

else if (calc >= 500 && calc <= 999)
JOptionPane.showMessageDialog(null, "Porto kostar 36kr med den vikten.");

else if (calc >= 1000 && calc <= 1999)
JOptionPane.showMessageDialog(null, "Porto kostar 48kr med den vikten.");

else if (calc == 2000)
JOptionPane.showMessageDialog(null, "Porto kostar 76kr med den vikten.");

else if (calc > 2000)
JOptionPane.showMessageDialog(null, "Detta räknas som paket, det blir dyrt!");

knappNr = JOptionPane.showConfirmDialog(null, "Vill du beräkna portot igen?", "Fråga", JOptionPane.YES_NO_OPTION);
} while (knappNr == 0);
}
}