From 6766b6479a1d30680c1eb59df4c4b720eb22ce1c Mon Sep 17 00:00:00 2001 From: Sudipto Mallick Date: Wed, 24 Jan 2024 16:44:31 +0000 Subject: 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`) --- java/code/ParentWithTwoChildren.java | 60 ++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 java/code/ParentWithTwoChildren.java (limited to 'java/code') 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(); + } +} -- cgit 1.4.1-2-gfad0