forked from ishanjogalekar/Java-Programs
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path6.Travel_program.java
More file actions
Latest commit
129 lines (126 loc) · 4 KB
/
Copy path6.Travel_program.java
File metadata and controls
129 lines (126 loc) · 4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*Question -
Define an abstract class called Travel [defined in package1] with few appropriate data members and methods for getting and displaying the same, create two subclasses called “InternationalTravel” and “NationalTravel” with new necessary data members respectively.
Create at least three objects for both of the subclasses and just display the info in package2 based on your travel experience so far.
Also create a method which scans the places which you would like to travel along with tentative year, in which you may travel and display that as well.
*/
//Code -
// 1.package1 :-
packagepackage1;
importjava.util.Scanner;
publicclassClass1_19BCE2250 { publicstaticvoidT()
{ Internationals1 = newInternational();
Nationals2 = newNational();
System.out.println("\n");
System.out.println("Enter Your International Travel Details Details");
s1.getData();
System.out.println("Your Details are: ");
s1.printData();
inti = 0;
while (i < 2) {
System.out.println("\nEnter International Travel Details: ");
s1.Interget();
i++;
}
System.out.println("\nEnter Your National Travel Details");
s2.getData();
System.out.println("Your Details are: ");
s2.printData();
intj = 0;
while (j < 2)
{
System.out.println("\nEnter National Travel details: ");
s2.Natget();
j++;
}
}
}
// Creating Abstract
classabstractclassTravel {
Stringcountry_name, city, place, date;
//Method to get data
voidgetData() {
Scannersc = newScanner(System.in);
System.out.println("Enter Country: ");
country_name = sc.nextLine();
System.out.println("Enter City: ");
city = sc.nextLine();
System.out.println("Enter Place: ");
place = sc.nextLine();
System.out.println("Enter Date : ");
date = sc.nextLine();
}
//Method to print data
voidprintData()
{
System.out.println("Country You visited: "+" "+country_name);
System.out.println("City You visited: "+" "+city);
System.out.println("Place You visited:"+" "+place);
System.out.println("Date: "+date);
}
} //Sub-class 1
classInternationalextendsTravel {
@Override
voidgetData()
{
super.getData();
}
@OverridevoidprintData()
{
super.printData();
}
voidInterget()
{
Scanners=newScanner(System.in);
System.out.println("Enter country name: ");
Stringc=s.nextLine();
System.out.println("Enter city name: ");
Stringci=s.nextLine();
System.out.println("Enter date: ");
Stringd=s.nextLine();
System.out.println("Your International Travel Details: ");
System.out.println("You visited "+c+","+ci+" on "+d);
}
}
//Sub-class 2
classNationalextendsTravel {
@Override
voidgetData()
{
super.getData();
}
@Override
voidprintData()
{
super.printData();
}
voidNatget()
{
Scannera = newScanner(System.in);
System.out.println("Enter city you visited in India: ");
Stringcity_India = a.nextLine(); System.out.println("Enter Place: ");
Stringp_India=a.nextLine(); System.out.println("Enter Date: ");
Stringd_India = a.nextLine();
System.out.println("Your National Travel Details: ");
System.out.println("You visited" + city_India +","+p_India+ " on " + d_India);
}
}
//2.package2 :-
packagepackage2;
importpackage1.*;
importjava.util.Scanner;
publicclassClass2_19BCE2250
{
publicstaticvoidmain(String[] args)
{
Class1_19BCE2250.T();
Class2_19BCE2250.wish();
}
publicstaticvoidwish() {
Scannerb = newScanner(System.in);
System.out.println("Enter Country which you want to visit: ");
Stringwc = b.nextLine();
System.out.println("Tentative Date: ");
Stringwd = b.nextLine();
System.out.println("You want to visit " + wc + " on " + wd);
}
}