Thush Perera
Is this correct???what are the unnessasary codings here??
1 Answer(s)      4 years and 2 months ago
Posted in : Java Beginners
import java.util.Scanner;
public class Length
{
  public int meters;
  public int centiMeters;
  public double yards;
  public double feet;
  public double inches;
  public double newMeter;

  public void read()
   {
     Scanner kbd=new Scanner(System.in);

     System.out.print("Enter the meters = ");
     meters=kbd.nextInt();
     System.out.print("\n");


     System.out.print("Enter the centi meters = ");
     centiMeters=kbd.nextInt();
     System.out.print("\n");

   }

  public void display()
  {
    System.out.printf("Lenth of an object = %dm %dCm\n",meters,centiMeters);
  }

 public void convert()
  {
    newMeter=meters+(centiMeters/100.0);
    yards = (newMeter)*1.09361;
    System.out.printf("Lenth in Yards = %s",yards);
    System.out.print("\n");
    feet = (newMeter)*3.28084;
    System.out.printf("Lenth in Feets = %s",feet);
    System.out.print("\n");
    inches = (newMeter)*39.37;
    System.out.printf("Lenth in Inches = %s",inches);
  }
}
Advertisement
View Answers

March 1, 2011 at 11:12 AM


import java.util.Scanner;
public class Length
{
  public int meters;
  public int centiMeters;
  public double yards;
  public double feet;
  public double inches;
  public double newMeter;

  public void read()
   {
     Scanner kbd=new Scanner(System.in);

     System.out.print("Enter the meters = ");
     meters=kbd.nextInt();
     System.out.print("\n");


     System.out.print("Enter the centi meters = ");
     centiMeters=kbd.nextInt();
     System.out.print("\n");

   }

  public void display()
  {
    System.out.printf("Lenth of an object = %dm %dCm\n",meters,centiMeters);
  }

 public void convert()
  {
    newMeter=meters+(centiMeters/100.0);
    yards = (newMeter)*1.09361;
    System.out.printf("Lenth in Yards = %s",yards);
    System.out.print("\n");
    feet = (newMeter)*3.28084;
    System.out.printf("Lenth in Feets = %s",feet);
    System.out.print("\n");
    inches = (newMeter)*39.37;
    System.out.printf("Lenth in Inches = %s",inches);
  }
  public static void main(String[]args){
      Length l=new Length();
      l.read();
      l.display();
      l.convert();
  }
}