File tree 7 files changed +95
-0
lines changed
7 files changed +95
-0
lines changed Original file line number Diff line number Diff line change
1
+ package Example_2 ;
2
+
3
+ import java .util .Objects ;
4
+
5
+ public class AppleStore {
6
+ public static Phone getPhone (String name ){
7
+ if (Objects .equals (name ,"IPhone14" ))
8
+ return new IPhone14 ();
9
+ else if (Objects .equals (name ,"IPhone14Pro" ))
10
+ return new IPhone14Pro ();
11
+ else if (Objects .equals (name ,"IPhone14ProMax" ))
12
+ return new IPhone14ProMax ();
13
+ else
14
+ return new UnavailablePhone ();
15
+ }
16
+ }
Original file line number Diff line number Diff line change
1
+ package Example_2 ;
2
+
3
+ public class Client {
4
+ public static void main (String []args ){
5
+ Phone iphone14 =AppleStore .getPhone ("IPhone14" );
6
+ System .out .println (iphone14 .getdescription ());
7
+ System .out .println (iphone14 .getPrice ());
8
+ System .out .println ();
9
+ Phone iphone13 =AppleStore .getPhone ("IPhone13" );
10
+ System .out .println (iphone13 .getdescription ());
11
+ System .out .println (iphone13 .getPrice ());
12
+ }
13
+ }
Original file line number Diff line number Diff line change
1
+ package Example_2 ;
2
+
3
+ public class IPhone14 extends Phone {
4
+ public IPhone14 (){
5
+
6
+ }
7
+ @ Override
8
+ public String getdescription (){
9
+ return "This is IPhone14" ;
10
+ }
11
+ @ Override
12
+ public double getPrice (){
13
+ return 55000.00 ;
14
+ }
15
+ }
Original file line number Diff line number Diff line change
1
+ package Example_2 ;
2
+
3
+ public class IPhone14Pro extends Phone {
4
+ public IPhone14Pro (){
5
+
6
+ }
7
+ @ Override
8
+ public String getdescription (){
9
+ return "This is IPhone14 Pro" ;
10
+ }
11
+ @ Override
12
+ public double getPrice (){
13
+ return 80000.00 ;
14
+ }
15
+ }
Original file line number Diff line number Diff line change
1
+ package Example_2 ;
2
+
3
+ public class IPhone14ProMax extends Phone {
4
+ public IPhone14ProMax (){
5
+
6
+ }
7
+ @ Override
8
+ public String getdescription (){
9
+ return "This is IPhone14 Pro Max" ;
10
+ }
11
+ @ Override
12
+ public double getPrice (){
13
+ return 125000.00 ;
14
+ }
15
+ }
Original file line number Diff line number Diff line change
1
+ package Example_2 ;
2
+
3
+ public abstract class Phone {
4
+ abstract double getPrice ();
5
+ abstract String getdescription ();
6
+ }
Original file line number Diff line number Diff line change
1
+ package Example_2 ;
2
+
3
+ public class UnavailablePhone extends Phone {
4
+ public UnavailablePhone (){
5
+
6
+ }
7
+ @ Override
8
+ public String getdescription (){
9
+ return "This phone is not available" ;
10
+ }
11
+ @ Override
12
+ public double getPrice (){
13
+ return 0.00 ;
14
+ }
15
+ }
You can’t perform that action at this time.
0 commit comments