fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. Bus bus1 = new Bus(1);
  13. System.out.println(bus1.trip1.toString());
  14. }
  15. }
  16.  
  17. class Bus
  18. {
  19. private int tripNumber;
  20. private String model;
  21. private String type;
  22. private int age;
  23. private int capacity;
  24. private int remainingCapacity;
  25. private boolean[][] seats;
  26. Trip trip1;
  27.  
  28. public Bus(int tripNumber)
  29. {
  30. this.tripNumber = tripNumber;
  31.  
  32. if (tripNumber==1)
  33. {
  34. this.model = "Setra";
  35. this.type = "2+2";
  36. this.age = 8;
  37. this.capacity = 40;
  38. this.remainingCapacity = 23;
  39.  
  40. this.trip1 = new Trip(this, tripNumber);
  41. }
  42. }
  43. public String toString()
  44. {
  45. return ("\n\tBus Information:\n\t\tBus: " + this.model + "\n\t\tType: " + this.type + "\n\t\tAge: " + this.age + "\n\t\tCapacity" + this.capacity + "\n\t\tRemainingCapacity" + this.remainingCapacity);
  46. }
  47. }
  48.  
  49. class Trip
  50. {
  51. private int tripNumber;
  52. private String date;
  53. private String origin;
  54. private String destination;
  55. private String departureTime;
  56. private String arrivalTime;
  57. private Bus assignedBus;
  58.  
  59. public Trip(Bus bus, int tripNumber)
  60. {
  61. if (tripNumber==1)
  62. {
  63. this.tripNumber = 1;
  64. this.assignedBus = bus;
  65. this.date = "27/11/2022";
  66. this.origin = "Ankara";
  67. this.destination = "Istanbul";
  68. this.departureTime = "00:15";
  69. this.arrivalTime = "06:30";
  70. }
  71. }
  72.  
  73. public String toString()
  74. {
  75. return tripNumber + ") Trip Information: \n\tDate: " + this.date + "\n\tFrom: " + this.origin + " to " + this.destination + "\n\tTrip time: " + this.departureTime + " to " + this.arrivalTime + this.assignedBus.toString();
  76. }
  77. }
Success #stdin #stdout 0.22s 53828KB
stdin
Standard input is empty
stdout
1) Trip Information: 
	Date: 27/11/2022
	From: Ankara to Istanbul
	Trip time: 00:15 to 06:30
	Bus Information:
		Bus: Setra
		Type: 2+2
		Age: 8
		Capacity40
		RemainingCapacity23