Java Questions

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • xosunkist
    New Member
    • Mar 2007
    • 10

    Java Questions

    Instructions:

    My project uses one class to convert a value entered by the user in yards to meters and feet. The program should print the results of each conversion to the screen without the user having to re-enter the value to be converted.
    The name of your class should be YardsConversion .The program should have the user enter a type double value for yards using the keyboard.
    The class should contain a main method to enter the value in yards to be converted. It should also contain two other methods to make the calculations to meters and feet respectively and then print the results to the DOS screen.

    My attempt and questions:

    import java.util.*;
    public class YardsConversion
    {
    public static final double yards: ;
    public static final double meters: ;
    public static final double feet: ;

    public static double yards=0
    public static double meters=0
    public static double feet=0

    public static void output()

    {


    Scanner scannerObject = new Scanner(System. in);

    System.out.prin tln("This program allows you to convert a value entered by the
    user in yards to meters to feet without the user having to re-enter the value to be converted.");



    I don't know if this is the correct way to start or not? I would like to know the command or example of a command to use to execute this. Thanks.
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by xosunkist
    Instructions:

    My project uses one class to convert a value entered by the user in yards to meters and feet. The program should print the results of each conversion to the screen without the user having to re-enter the value to be converted.
    The name of your class should be YardsConversion .The program should have the user enter a type double value for yards using the keyboard.
    The class should contain a main method to enter the value in yards to be converted. It should also contain two other methods to make the calculations to meters and feet respectively and then print the results to the DOS screen.

    My attempt and questions:

    import java.util.*;
    public class YardsConversion
    {
    public static final double yards: ;
    public static final double meters: ;
    public static final double feet: ;

    public static double yards=0
    public static double meters=0
    public static double feet=0

    public static void output()

    {


    Scanner scannerObject = new Scanner(System. in);

    System.out.prin tln("This program allows you to convert a value entered by the
    user in yards to meters to feet without the user having to re-enter the value to be converted.");



    I don't know if this is the correct way to start or not? I would like to know the command or example of a command to use to execute this. Thanks.
    Follow the instructions in the question.

    It says you should have
    1.)A main method
    2.)Two more methods toMeters and toFeet

    Comment

    • xosunkist
      New Member
      • Mar 2007
      • 10

      #3
      Code:
      import java.util.*;
      
       
      
      public class YardsConversion
      
      {
      
       
      
      
       
      
                  public static final double YARD2METER = .9144;
      
                  public static final double METER2FEET =  3.280;
      
       
      
       
      
       
      
                
      
       
      
                  public static double yard =0;
      
                  public static double meter =0;
      
                  public static double feet = 0;
      
                  public static double YARD2METER = 0;
      
                  public static int METER2FEET =0;
      
       
      
       
      
                 
       
      
       
      
                 
      
       
      
                  public static void output()
      
                  {
      
       
      
                              Scanner scannerObject = new Scanner(System.in);
      
       
      
                              System.out.println("This program allows you to convert yard");
      
                              System.out.println("to meter and feet");
      
                            	System.out.println(" ");
      
                              System.out.print("\n");
      
       
      
       
      
       
      
                             
       
      
       
      
                             
                  }                 
      
       
      
       
      
                  public static void yard2meter()
      
       
      
                  {
      
                                          Scanner scannerObject = new Scanner(System.in);
      
       
      
                                          /***Prompt to tell the user what to do next. ***/
      
       
      
                                          System.out.print("Enter a temperature in yard.  ");
      
       
      
                                          /***Assigns number entered by user to
      
                                          variable named yard2meter ***/
      
       
      
                                          yard2meter = scannerObject.nextDouble();
      
       
      
       
      
                                          /***  Shows the end user the value they
      
                                          entered via the keyboard ***/
      
       
      
                                          System.out.print("\n\n");
      
                                          System.out.println("\n You entered " + yard2meter + " yard.");
      
       
      
                                          /*** Formula to convert yards to meter and
      
                                         assign the results to a variable named meter. ***/
      
       
      
                                          meter =  YARD2METER * tempCent + 32;
      
       
      
       
      
      
       
      
                         System.out.println(YARD2METER + " YARDS IS EQUAL TO " +  .");
      
       
      
       
      
                                 /***Used to print a blank line to the screen***/
      
       
      
                                          System.out.print("\n");
      
       
      
                  }               /***  end  method  ***/
      
       
      
       
      
       
      
                  public static void METER2FEET()
      
       
      
                  {
      
                                          Scanner scannerObject = new Scanner(System.in);
      
       
      
                                          /***Prompt to tell the user to enter a 
                                          value.   ***/
      
       
      
       
      
                                          System.out.print("Enter a temperature in feet.");
      
       
      
                                          /***Assigns number entered by user to
      
                                          variable named METER2FEET***/
      
       
      
                                          METER2FEET = scannerObject.nextDouble();
      
       
      
                                          /***  Shows the end user the value they
      
                                          entered via the keyboard ***/
      
       
      
                                          System.out.print("\n");
      
                                          System.out.println("\n You entered " + METER2FEET + " .");
      
       
      
       
      
                                          /*** Formula to convert  and
      
                                          assign the results to a variable named cent. ***/
      
       
      
                                         METER =  () * ;
      
       
      
                                          /***Outputs the value assigned to  and to the
      
                                          screen along with some explanatory words so the user can understand
      
                                          what is happening.  ***/
      
       
      
                                          System.out.println(METER2FEET + " FEET " + FEET)
      
                                                                                                                              + " degrees Centigrade.");
      
       
      
                                          /***Used to print a blank line to the screen***/
      
       
      
                                          System.out.print("\n");
      
       
      
                  }                /*** end of  method ***/
      
       
      
      }                      /*  end of class YardsConversion  */

      Comment

      • xosunkist
        New Member
        • Mar 2007
        • 10

        #4
        I truly do not know where to begin. This is all I have and I have a major headache. This assignment is due in two days and I need MAJOR pointers. I have never done this before!!!! Brand new to JAVA and major assingment. I learn quick just need help with this. What am I doing wrong? Help!!

        Comment

        • r035198x
          MVP
          • Sep 2006
          • 13225

          #5
          Originally posted by xosunkist
          Code:
          import java.util.*;
          
           
          
          public class YardsConversion
          
          {
          
           
          
          
           
          
                      public static final double YARD2METER = .9144;
          
                      public static final double METER2FEET =  3.280;
          
           
          
           
          
           
          
                    
          
           
          
                      public static double yard =0;
          
                      public static double meter =0;
          
                      public static double feet = 0;
          
                      public static double YARD2METER = 0;
          
                      public static int METER2FEET =0;
          
           
          
           
          
                     
           
          
           
          
                     
          
           
          
                      public static void output()
          
                      {
          
           
          
                                  Scanner scannerObject = new Scanner(System.in);
          
           
          
                                  System.out.println("This program allows you to convert yard");
          
                                  System.out.println("to meter and feet");
          
                                	System.out.println(" ");
          
                                  System.out.print("\n");
          
           
          
           
          
           
          
                                 
           
          
           
          
                                 
                      }                 
          
           
          
           
          
                      public static void yard2meter()
          
           
          
                      {
          
                                              Scanner scannerObject = new Scanner(System.in);
          
           
          
                                              /***Prompt to tell the user what to do next. ***/
          
           
          
                                              System.out.print("Enter a temperature in yard.  ");
          
           
          
                                              /***Assigns number entered by user to
          
                                              variable named yard2meter ***/
          
           
          
                                              yard2meter = scannerObject.nextDouble();
          
           
          
           
          
                                              /***  Shows the end user the value they
          
                                              entered via the keyboard ***/
          
           
          
                                              System.out.print("\n\n");
          
                                              System.out.println("\n You entered " + yard2meter + " yard.");
          
           
          
                                              /*** Formula to convert yards to meter and
          
                                             assign the results to a variable named meter. ***/
          
           
          
                                              meter =  YARD2METER * tempCent + 32;
          
           
          
           
          
          
           
          
                             System.out.println(YARD2METER + " YARDS IS EQUAL TO " +  .");
          
           
          
           
          
                                     /***Used to print a blank line to the screen***/
          
           
          
                                              System.out.print("\n");
          
           
          
                      }               /***  end  method  ***/
          
           
          
           
          
           
          
                      public static void METER2FEET()
          
           
          
                      {
          
                                              Scanner scannerObject = new Scanner(System.in);
          
           
          
                                              /***Prompt to tell the user to enter a 
                                              value.   ***/
          
           
          
           
          
                                              System.out.print("Enter a temperature in feet.");
          
           
          
                                              /***Assigns number entered by user to
          
                                              variable named METER2FEET***/
          
           
          
                                              METER2FEET = scannerObject.nextDouble();
          
           
          
                                              /***  Shows the end user the value they
          
                                              entered via the keyboard ***/
          
           
          
                                              System.out.print("\n");
          
                                              System.out.println("\n You entered " + METER2FEET + " .");
          
           
          
           
          
                                              /*** Formula to convert  and
          
                                              assign the results to a variable named cent. ***/
          
           
          
                                             METER =  () * ;
          
           
          
                                              /***Outputs the value assigned to  and to the
          
                                              screen along with some explanatory words so the user can understand
          
                                              what is happening.  ***/
          
           
          
                                              System.out.println(METER2FEET + " FEET " + FEET)
          
                                                                                                                                  + " degrees Centigrade.");
          
           
          
                                              /***Used to print a blank line to the screen***/
          
           
          
                                              System.out.print("\n");
          
           
          
                      }                /*** end of  method ***/
          
           
          
          }                      /*  end of class YardsConversion  */
          The two methods are supposed to be yardsToFeet and yardsToMetres

          Comment

          Working...