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 8 of 8

Thread: some help please

  1. #1
    Junior Member
    Join Date
    Nov 2012
    Posts
    3
    My Mood
    Stressed
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Angry some help please

    hi every one i'm new member and i'm beginner in java

    i have a problem in me code and i don't know how to deal with it


    this is the question


    In this project, write a Java program that will convert an input metric to a corresponding value in the International System of Units. Input metric will be in Yards, Inches, Miles, and Pounds. The converted metric should be converted as follows:
    Table 1:

    Input Metric


    Output Metric


    Yards


    Meters


    Inches


    Centimeters


    Miles


    Kilometers


    Pounds


    Kilogram



    The program should display a Menu for the user to choose from the above metric. The menu is shown in the figure below.



    Welcome to Multi conversion System
    Press c for Inches to Centimeters
    Press m for Yards to Meters
    Press k for Miles to Kilometers
    Press g for Pounds to Kilograms

    The user has to enter c, m, k, or g. Next, the user will enter a value for the input metric which the program will convert to the specified unit from table 1. The output of the program should be the converted metric value. In addition, consider the following scenarios in the output:
    1. If the user inputs a character that is not recognized (NOT c, m, k, or g), then the program prints “Wrong Selection!”, and exits.
    2. If the user inputs a value less than zero for a metric, the program will display a message that states “Cannot convert a negative value!”
    3. After displaying the converted metric value (if input value is not negative), the program should also display the range of the converted value according to the following rules:
    a. If converted value is less than 20, print “Less than 20.”
    b. If converted value is less than 50, print “Less than 50.”
    c. If converted value is equal 50, print “Equal 50”.
    d. If converted value is greater than 50, print “Greater than 50.”
    Hint 1: To read a character using a Scanner input, use the following statement:
    char c = input.nextLine().charAt(0);
    Hint 2: To convert a metric use the following formulas:
    Centimeters = 2.54 * inches
    Meters = 0.9144 * Yards
    Kilometers = 1.60934 * Miles
    Kilograms = 0.453592 * Pounds

    Note: Submit only the source code. For example: IA_1110348_P2.java
    Sample Program Run #1:



    Welcome to Multi conversion System
    Press c for Inches to Centimeters
    Press m for Yards to Meters
    Press k for Miles to Kilometers
    Press g for Pounds to Kilograms

    k
    Enter a value in Miles: 10
    Your 10.0 Miles are 16.0934 Kilometers. Less than 20.

    Sample Program Run #2:
    Welcome to Multi conversion System
    Press c for Inches to Centimeters
    Press m for Yards to Meters
    Press k for Miles to Kilometers
    Press g for Pounds to Kilograms

    y
    Wrong Selection!






    Sample Program Run #3:
    Welcome to Multi conversion System
    Press c for Inches to Centimeters
    Press m for Yards to Meters
    Press k for Miles to Kilometers
    Press g for Pounds to Kilograms

    g
    Enter a value in Miles: -20
    Cannot convert a negative value!

    Sample Program Run #4:
    Welcome to Multi conversion System
    Press c for Inches to Centimeters
    Press m for Yards to Meters
    Press k for Miles to Kilometers
    Press g for Pounds to Kilograms




    c
    Enter a value in Inches: 100
    Your 100.0 Inches are 254.0 Centimeters. Greater than 50.



    and i have try many times to solve it and every time i failed

     import java.util.Scanner;
    import javax.swing.JOptionPane;
     
    /**
     *
     * @author Mac
     */
    public class EA_1211835_P2 {
     
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
            // TODO code application logic here
     
            double yardes,inches,miles,pounds,meters,centimeters,kilogram,kilometers;
     
            char c,m,k,g;
     
            String x;
     
            Scanner in = new Scanner(System.in);
     
            x=JOptionPane.showInputDialog(null, 
                    "please press c for centimeters , g for kilogram , k for kilometers , m for meters ");
     
        c=in.nextLine().charAt(0);
     
         m=in.nextLine().charAt(0);
     
         k=in.nextLine().charAt(0);
     
         g=in.nextLine().charAt(0);
     
         if (c<20)
     
         {
           c=inches*2.45;
         }
     
     
     
     
        }
    }
    please help me

  2. #2
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: some help please

    I see your code.
    I see the assignment instructions.
    I see your complaint.
    I see you want help.
    I do not see what you are stuck on, what you need help with, or what your question is.

  3. #3
    Junior Member
    Join Date
    Nov 2012
    Posts
    3
    My Mood
    Stressed
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: some help please

    I don't know how to complete the assignment

  4. #4
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 140 Times in 135 Posts

    Default Re: some help please

    Can you be a bit more specific than that? What exactly don't you understand? A golden rule of thumb is to try to put as much effort into asking your question as you'd like a volunteer to expend answering it.

  5. #5
    Junior Member
    Join Date
    Nov 2012
    Posts
    3
    My Mood
    Stressed
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: some help please

    this is my code

    import java.util.Scanner;
    import javax.swing.JOptionPane;
     
    /**
     *
     * @author Mac
     */
    public class EA_1211835_P2 {
     
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
            // TODO code application logic here
     
            double yardes,inches,miles,pounds,meters,centimeters,kilogram,kilometers;
     
            char c,m,k,g;
     
            String x;
     
            Scanner in = new Scanner(System.in);
     
            x=JOptionPane.showInputDialog(null, "please press c for centimeters , g for kilogram , k for kilometers , m for meters");
     
     
     
     
            c=in.nextLine().charAt(0);
     
         m=in.nextLine().charAt(0);
     
         k=in.nextLine().charAt(0);
     
         g=in.nextLine().charAt(0);
     
         if (c=='c') {
                centimeters=2.45*inches;
            }
     
     
     
     
         {}

    the problem is i can't get the result's and when i use if and else if the program say else with out if

  6. #6
    Junior Member
    Join Date
    Nov 2012
    Location
    Germany
    Posts
    20
    My Mood
    Bored
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Default Re: some help please

    Quote Originally Posted by zezo View Post
    when i use if and else if the program say else with out if
    can you describe your if problem a little more, please?

  7. #7
    Member
    Join Date
    Oct 2011
    Posts
    114
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: some help please

    Could you not use a switch statement for the letter choices and have the default case print "invalid selection"

  8. #8
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: some help please

    Quote Originally Posted by zezo View Post
    this is my code

    import java.util.Scanner;
    import javax.swing.JOptionPane;
     
    /**
     *
     * @author Mac
     */
    public class EA_1211835_P2 {
     
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) {
            // TODO code application logic here
     
            double yardes,inches,miles,pounds,meters,centimeters,kilogram,kilometers;
     
            char c,m,k,g;
     
            String x;
     
            Scanner in = new Scanner(System.in);
     
            x=JOptionPane.showInputDialog(null, "please press c for centimeters , g for kilogram , k for kilometers , m for meters");
     
     
     
     
            c=in.nextLine().charAt(0);
     
         m=in.nextLine().charAt(0);
     
         k=in.nextLine().charAt(0);
     
         g=in.nextLine().charAt(0);
     
         if (c=='c') {
                centimeters=2.45*inches;
            }
     
     
     
     
         {}

    the problem is i can't get the result's and when i use if and else if the program say else with out if
    There is no else in the posted code. You will have to post the code you have questions about if you want help with it.