Ads

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

Ads

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

Ads

Related Tutorials/Questions & Answers:

Ads

- Java Tutorials
- Java Code example
- Java Programming
- Java Beginners Examples
- Applet Tutorials
- Awt Tutorials
- Java Certification
- Interview Question
- Java Servlets Tutorial
- Jsp Tutorials
- Java Swing Tutorials
- JDBC Tutorial
- EJB Tutorials
- Java Server Faces (JSF) Tutorial
- WAP Tutorial
- Struts Tutorial
- JAXB Tutorial
- Spring FrameWork Tutorial
- SOA&Web Services Tutorials
- Bioinformatics Tutorials
- MySQL Tutorials
- JAVA DOM Tutorial
- XML Tutorial
- EAI Articles
- Many Programming Tutorials Links
- Tutorials Books
**Java Script Tutorial****Ajax Tutorial****Dojo Tutorials****Programming Books****Trainings****Flex****Ant****RDF**

Ads