Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Setting up postage calculations

  1. #1
    Junior Member
    Join Date
    Jan 2014
    Posts
    9
    My Mood
    Sleepy
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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.


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default 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?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Junior Member
    Join Date
    Jan 2014
    Posts
    9
    My Mood
    Sleepy
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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.

    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:

    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); 
    	}
    }

    Solved it, if any optimizations can be made please tell me.

Similar Threads

  1. Math calculations
    By mikem1034 in forum Java Theory & Questions
    Replies: 1
    Last Post: January 16th, 2013, 10:13 AM
  2. Replies: 9
    Last Post: December 5th, 2012, 05:03 PM
  3. Replies: 3
    Last Post: November 8th, 2012, 01:24 PM
  4. User input and calculations problems
    By javabeg123 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: December 7th, 2011, 07:32 PM
  5. Replies: 1
    Last Post: May 3rd, 2010, 01:03 PM