Advertisement
Guest User

Untitled

a guest
Sep 2nd, 2015
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. public class ConstructorEx3 {
  2.  
  3. int Speed;
  4. int Distance;
  5. int Minute;
  6. public int getTime (){
  7. return ((Distance/Speed)*Minute);
  8. }
  9. ConstructorEx3 (){
  10. Distance = 60;
  11. Speed = 30;
  12. Minute = 60;
  13. }
  14. ConstructorEx3 (int D, int S, int M){
  15. Distance = D;
  16. Speed = S;
  17. Minute = M;
  18. }
  19. public static void main (String []arsh){
  20. ConstructorEx3 Bike1,Bike2;
  21. Bike1 = new ConstructorEx3();
  22. Bike2 = new ConstructorEx3(40,80,60);
  23.  
  24. System.out.println("Bike one is travelling at : "+ Bike1.getTime());
  25. System.out.println("Bike two is travelling at : "+ Bike2.getTime());
  26.  
  27. }
  28. }
  29.  
  30. Distance = 40;
  31. Speed = 80;
  32. Minute - 60;
  33.  
  34. Distance / Speed = 0.5;
  35.  
  36. public class ConstructorEx3 {
  37.  
  38. int Speed;
  39. int Distance;
  40. int Minute;
  41. public int getTime (){
  42. double v = ((double)Distance/(double)Speed);
  43. v= v * (double)Minute;
  44. return (int)v;
  45. // return ((Distance/Speed)*Minute);
  46. }
  47. ConstructorEx3 (){
  48. Distance = 60;
  49. Speed = 30;
  50. Minute = 60;
  51. }
  52. ConstructorEx3 (int D, int S, int M){
  53. Distance = D;
  54. Speed = S;
  55. Minute = M;
  56. }
  57. public static void main (String []arsh){
  58. ConstructorEx3 Bike1,Bike2;
  59. Bike1 = new ConstructorEx3();
  60. Bike2 = new ConstructorEx3(40,80,60);
  61.  
  62. System.out.println("Bike one is travelling at : "+ Bike1.getTime());
  63. System.out.println("Bike two is travelling at : "+ Bike2.getTime());
  64.  
  65. }
  66. }
  67.  
  68. Bike one is travelling at : 120
  69. Bike two is travelling at : 30
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement