QuestionAsk Questions?

import java.io.*; class Distance { int feet; int inch; void read(int feet, int inch) { 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 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(d1,d2); d3.distanceDisplay(); } }

View Answers

March 31, 2011 at 12:03 PM

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

Related Tutorials/Questions & Answers: