-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
78 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package P; | ||
|
||
import P1.TwoDim; | ||
import P2.ThreeDim; | ||
import java.util.Scanner; | ||
|
||
public class ProgramExample { | ||
public static void main(String[] args) { | ||
Scanner sc = new Scanner(System.in); | ||
TwoDim obj; | ||
|
||
System.out.println("Choose type of coordinates:"); | ||
System.out.println("1. TwoDim (2D)"); | ||
System.out.println("2. ThreeDim (3D)"); | ||
int choice = sc.nextInt(); | ||
|
||
switch (choice) { | ||
case 1: | ||
obj = new P1.TwoDim(3, 4); | ||
break; | ||
case 2: | ||
obj = new ThreeDim(5, 6, 7); | ||
break; | ||
default: | ||
System.out.println("Invalid choice!"); | ||
return; | ||
} | ||
|
||
System.out.println(obj.toString()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package P1; | ||
|
||
public class TwoDim { | ||
private int x; | ||
private int y; | ||
|
||
public TwoDim() { | ||
this.x = 0; | ||
this.y = 0; | ||
} | ||
|
||
public TwoDim(int x, int y) { | ||
this.x = x; | ||
this.y = y; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "TwoDim Coordinates: (" + x + ", " + y + ")"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package P2; | ||
|
||
import P1.TwoDim; | ||
|
||
public class ThreeDim extends TwoDim { | ||
private int z; | ||
|
||
// Default constructor | ||
public ThreeDim() { | ||
super(); | ||
this.z = 0; | ||
} | ||
|
||
// Parameterized constructor | ||
public ThreeDim(int x, int y, int z) { | ||
super(x, y); | ||
this.z = z; | ||
} | ||
|
||
// Override toString() to display three-dimensional coordinates | ||
@Override | ||
public String toString() { | ||
return "ThreeDim Coordinates: (" + super.toString().substring(18) + ", " + z + ")"; | ||
} | ||
} |
Binary file not shown.
This file was deleted.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.