Answer to Question #214665 in Java | JSP | JSF for Fdfd

Question #214665
Create two classes DM and DB to store the value of distances.DM stores distances in meters and centimetres and DB in feet and inches. Write a program that can read values for the class object and add one object of DM with another object of DB. Use a friend function to carry out the addition operation. The object that stores the results may be a DM or DB object depending on the units in which the results are required. Type display should be in feet-inches or meter-centimetre depending on the object of display.
1
Expert's answer
2021-07-07T06:16:12-0400
class DB {
private float feet, inches;
DB(float f, float i){
    feet = f;
    inches = i;
}
float getFeet(){
    return feet;
}
float getInches(){
    return inches;
}
void  getDistanceDB(){
    System.out.println("Feet:  " +feet+ "\tInches:  "+ inches);
}
}




class DM {
    private double meters;
    private double centimeters;
    DM(double m, double c){
        meters =m;
        centimeters = c;
    }


    double getMeters(){
        return meters;
    }
    double getCentimeters(){
        return centimeters;
    }
    void getDistanceDM(){
       System.out.println("Feet:  " +meters+ "\tInches:  "+centimeters);
        
    }
}
public class Q214665 {
    int n = 10;
    int h = 5;
    DM m = new DM(n, h);
    DB v = new DB(2, 4);
void addDistance(){
     double total_distance;
     total_distance = m.getMeters() + (m.getCentimeters() / 100 ) + (v.getFeet() +( v.getInches() / 12) / 3.2808399);
     String distance = String.valueOf(total_distance);
     String [] arr_distance = distance.split(".",2);
    System.out.print(total_distance);
}
   

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS