Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ConstructorEx3 {
- int Speed;
- int Distance;
- int Minute;
- public int getTime (){
- return ((Distance/Speed)*Minute);
- }
- ConstructorEx3 (){
- Distance = 60;
- Speed = 30;
- Minute = 60;
- }
- ConstructorEx3 (int D, int S, int M){
- Distance = D;
- Speed = S;
- Minute = M;
- }
- public static void main (String []arsh){
- ConstructorEx3 Bike1,Bike2;
- Bike1 = new ConstructorEx3();
- Bike2 = new ConstructorEx3(40,80,60);
- System.out.println("Bike one is travelling at : "+ Bike1.getTime());
- System.out.println("Bike two is travelling at : "+ Bike2.getTime());
- }
- }
- Distance = 40;
- Speed = 80;
- Minute - 60;
- Distance / Speed = 0.5;
- public class ConstructorEx3 {
- int Speed;
- int Distance;
- int Minute;
- public int getTime (){
- double v = ((double)Distance/(double)Speed);
- v= v * (double)Minute;
- return (int)v;
- // return ((Distance/Speed)*Minute);
- }
- ConstructorEx3 (){
- Distance = 60;
- Speed = 30;
- Minute = 60;
- }
- ConstructorEx3 (int D, int S, int M){
- Distance = D;
- Speed = S;
- Minute = M;
- }
- public static void main (String []arsh){
- ConstructorEx3 Bike1,Bike2;
- Bike1 = new ConstructorEx3();
- Bike2 = new ConstructorEx3(40,80,60);
- System.out.println("Bike one is travelling at : "+ Bike1.getTime());
- System.out.println("Bike two is travelling at : "+ Bike2.getTime());
- }
- }
- Bike one is travelling at : 120
- Bike two is travelling at : 30
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement