Advertisements
import java.io.*; class Distance { int feet,inch; void read() { System.out.println("Enter distance in feet and inches "); feet=Integer.parseInt(ob.readLine()); inch=Integer.parseInt(ob.readLine()); } void add(int d1,int d2) { int f,i; feet=d1+d2; inch=d1+d2; if(inch>=12) { f=inch/12; i=inch%12; feet=feet+f; inch=i; } } void display() { System.out.println("Distance in feet "+feet); System.out.println("Distance in inches "+inch); } public static void main(String[] args) throws IOException { DataInputStream ob = new DataInputStream(System.in); Distance d1 = new Distance(); Distance d2 = new Distance(); Distance d3 = new Distance(); d1.read(); d2.read(); d3.add(10,20); d3.display(); } }
import java.io.*; class Distance { int feet; int inch; DataInputStream ob = new DataInputStream(System.in); void read()throws Exception { System.out.println("Enter distance in feet and inches "); feet=Integer.parseInt(ob.readLine()); inch=Integer.parseInt(ob.readLine()); } void distanceDisplay() { System.out.println("Distance in feet "+feet); System.out.println("Distance in inches "+inch); } void add(Distance d1,Distance d2) { int f,i; feet=d1.feet + d2.feet; inch=d1.inch + d2.inch; if(inch>=12) { f=inch/12; i=inch%12; feet=feet+f; inch=i; } } public static void main(String[] args) throws Exception { Distance d1 = new Distance(); Distance d2 = new Distance(); Distance d3 = new Distance(); d1.read(); d2.read(); d3.add(d1,d2); d3.distanceDisplay(); } }