Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


mehul jain
class distance
1 Answer(s)      3 years and 11 months ago
Posted in : Java Beginners


class distance-integer data member km1,km2,km3,m1,m2,m3. run()-to input the two distance and add them in the third. display()-to display the total distance. display the constructor if required.


Advertisement
View Answers

January 18, 2011 at 11:24 AM


Hi Friend,

Try this:

import java.util.*;
class  distance
{
    int km1,km2,km3;
    public void run(){
    Scanner input=new Scanner(System.in);
    System.out.print("Enter km1: ");
    km1=input.nextInt();

    System.out.print("Enter km2: ");
    km2=input.nextInt();
    km3=km1+km2;
    }
    public void display(){
        System.out.println("Total distance is: "+km3);
    }
    public static void main(String[] args) 
    {
    distance d=new distance();
    d.run();
    d.display();
    }
}

Thanks



Related Tutorials/Questions & Answers:
class distance
class distance  class distance-integer data member km1,km2,km3,m1,m2,m3. run()-to input the two distance and add them in the third. display()-to display the total distance. display the constructor if required
Edit Distance
Edit Distance  I want java programming ask from user input two string and the program find the edit distance between two strings and find table and optimal solution using GUI
Advertisements
Distance conversion - Java Beginners
Distance conversion  Write an application that reads a distance... the distance to kilometres, feet and inches, according to the user?s selection...() for the user selection. ? Write a method to read a distance in metres from
Delhi to Udaipur by road distance
Delhi to Udaipur by road distance  delhi to udaipur by road distance
Another distance conversion - Java Beginners
Another distance conversion  Write an application that reads a distance in metres. The program will then convert the distance to kilometres, feet... = 1640.5 feet 500 * 39.37 = 19685 inches   import java.io.*; public class
Distance in meters - Java Beginners
Distance in meters  Write a program that asks the user to enter a distance in meters. The program will then present the following menu of selections... the program The program will convert the distance to kilometers, inches
Hill stations near Delhi distance
Hill stations near Delhi distance   Hi, Can any one tell the distances of the Hill stations near Delhi? Thanks
Road distance using Java - Java Beginners
Road distance using Java  Dear All i am calculating the straight line distance between two latlong points using the simple mathematical formula but i need the Real Road Driving Distance // protected double distance(double pX
Distance learning business management
Distance learning business management courses are on high demand today... nature is regular or class courses and don't suit for a working professional. But those students should not worry as many institutions have started distance
GUI and how to convert a distance - Java Beginners
application that can be is used to convert a distance unit in miles into its... java.awt.event.*; import java.util.regex.*; import java.text.*; class ConvertMile...=new JTextField(20); t5=new JTextField(20); l1=new JLabel("Enter distance
loop to input multiple points to calculate final distance and speed
loop to input multiple points to calculate final distance and speed  import java.util.Scanner; public class Travel { private double time; private double distance; public Travel() { time=0; distance=0
Hill Stations near Delhi distance
Distance of Major Hill Stations From Delhi  In this page we have listed all the Hill Stations near Delhi with their distance from central Delhi... and northeastern India. List of Hill Stations near Delhi with distance Sr
VoIP Long Distance
VoIP Long Distance          VoIP Designing a Long-Distance Network The long-distance Voice over IP (VoIP) network solution is a set of network design
How can i display the distance of a line drawing randomly?
How can i display the distance of a line drawing randomly?  How can i display the distance of a line drawing randomly
class
class  Is a class a subclass of itself
class
is a class to represent a country in medal tally. It has an attribute of country... medals. In this class, you should also define constructors, and assessor, mutator methods. Task 2 MedalTally.java is a class to model a medal tally, containing
Class
Class, Object and Methods       Class : Whatever we can see in this world all the things... is termed as a class. All the objects are direct interacted with its class
Super class of an Exception class
Super class of an Exception class  hello,,, What is super class of an Exception class?   hii,, the super class of an exception is throwable class. and the super class of an throwable class is the object class
Class
Class       This section explores the concept of a class in reference to object oriented programming techniques. A class defines the properties of  objects and methods used
Explain final class, abstract class and super class.
Explain final class, abstract class and super class.  Explain final class, abstract class and super class.   Explain final class, abstract class and super class. A final class cannot be extended. A final class
class file
class file  How to create class file in jsf easily
class loaders
class loaders   Explain static and dynamic class loaders
.class and .tld
.class and .tld  how to create .class and .tld file
inner class
inner class  what is mean by inner class   Inner class is a non-static class which is defined inside another class
Node class
Node class   hii, What is a node class?   hello, A node class is a class that has added new services or functionality beyond the services inherited from its base class
Matrix Class
Matrix Class   A class to manage matrices and add them. Create in the driver class two objects of it and use the add method
Matrix Class
Matrix Class   A class to manage matrices and add them. Create in the driver class two objects of it and use the add method
wrapper class
wrapper class  list wrapper class methods
wrapper class
wrapper class  wrapper class methods
printstrim class
printstrim class  discribe PrintStream class
printstrim class
printstrim class  discribe PrintStream class
 

 

 

DMCA.com