summary refs log tree commit diff stats
path: root/java/code
diff options
context:
space:
mode:
authorSudipto Mallick <smlckz@termux-alpine>2024-01-24 16:44:31 +0000
committerSudipto Mallick <smlckz@termux-alpine>2024-01-24 16:44:31 +0000
commit6766b6479a1d30680c1eb59df4c4b720eb22ce1c (patch)
tree19af8079fbed64732f891da09c69356153cc0170 /java/code
parent8fb719f58f91d1f1f187a1db974682fb3736ee05 (diff)
downloadzadania-6766b6479a1d30680c1eb59df4c4b720eb22ce1c.tar.gz
Implement Java Assignment #15 and more
java/{code/ParentWithTwoChildren.java, output/ParentWithTwoChildren.typ, text/ParentWithTwoChildren.typ}: Code, output and assignment text for Java assignment #15
java/state.sql: Update for Java assignment #15
java/template.typ: Allow for long program description to be left aligned
and justified, instead of centered
java/tobedone: Update to show assignment numbers (implicitly `rowid`)
Diffstat (limited to 'java/code')
-rw-r--r--java/code/ParentWithTwoChildren.java60
1 files changed, 60 insertions, 0 deletions
diff --git a/java/code/ParentWithTwoChildren.java b/java/code/ParentWithTwoChildren.java
new file mode 100644
index 0000000..20b04cb
--- /dev/null
+++ b/java/code/ParentWithTwoChildren.java
@@ -0,0 +1,60 @@
+class Parent {
+    int id;
+    String name;
+    String address;
+
+    Parent(int id, String name, String address) {
+        this.id = id;
+        this.name = name;
+        this.address = address;
+    }
+
+    void display() {
+        String className = this.getClass().getSimpleName();
+        System.out.println(className + ": ID: " + id + ", Name: " + name + ", Address: " + address);
+    }
+}
+
+class ChildOne extends Parent {
+    int marks;
+
+    ChildOne(int id, String name, String address, int marks) {
+        super(id, name, address);
+        this.marks = marks;
+    }
+
+    @Override
+    void display() {
+        super.display();
+        System.out.println("    Marks: " + marks);
+    }
+}
+
+class ChildTwo extends Parent {
+    String qualification;
+    double salary;
+
+    ChildTwo(int id, String name, String address, String qualification, double salary) {
+        super(id, name, address);
+        this.qualification = qualification;
+        this.salary = salary;
+    }
+
+    @Override
+    void display() {
+        super.display();
+        System.out.println(".   Qualification: " + qualification + ", Salary: " + salary);
+    }
+}
+
+class ParentWithTwoChildren {
+    public static void main(String[] args) {
+        Parent parent1 = new Parent(1, "John Doe", "123 Main St.");
+        ChildOne child1 = new ChildOne(2, "Jane Doe", "456 Elm St.", 85);
+        ChildTwo child2 = new ChildTwo(3, "Mike Smith", "789 Oak St.", "B.Tech", 50000);
+
+        parent1.display();
+        child1.display();
+        child2.display();
+    }
+}