Level 3 programs

This commit is contained in:
2021-06-11 10:40:16 +05:30
parent f56d525b45
commit f013cd2c3e
3 changed files with 90 additions and 1 deletions

59
AbstractClassProgram.java Normal file
View File

@@ -0,0 +1,59 @@
/*Write a java program to create an abstract class named
Shape that contains two integers and an empty method named
print Area (). Provide three classes named Rectangle, Triangle
and Circle such that each one of the classes extends the class
Shape. Each one of the classes contains only the method print
Area () that prints the area of the given shape.*/
import java.util.*;
abstract class Shape {
int length, breadth, radius;
Scanner input = new Scanner(System.in);
abstract void printArea();
}
class Rectangle extends Shape {
void printArea() {
System.out.println("* Finding the Area of Rectangle *");
System.out.print("Enter length and breadth: ");
length = input.nextInt();
breadth = input.nextInt();
System.out.println("The area of Rectangle is: " + length * breadth);
}
}
class Triangle extends Shape {
void printArea() {
System.out.println("\n** Finding the Area of Triangle **");
System.out.print("Enter Base And Height: ");
length = input.nextInt();
breadth = input.nextInt();
System.out.println("The area of Triangle is: " + (length * breadth) / 2);
}
}
class Cricle extends Shape {
void printArea() {
System.out.println("\n** Finding the Area of Cricle **");
System.out.print("Enter Radius: ");
radius = input.nextInt();
System.out.println("The area of Cricle is: " + 3.14f * radius * radius);
}
}
public class AbstractClassProgram {
public static void main(String[] args) {
Rectangle rec = new Rectangle();
rec.printArea();
Triangle tri = new Triangle();
tri.printArea();
Cricle cri = new Cricle();
cri.printArea();
}
}

View File

@@ -0,0 +1,26 @@
//Write a program in java to demonstrate multilevel inheritance in java.
public class MultiLevelInheritance {
void eat() {
System.out.println("eating...");
}
}
class Dog extends MultiLevelInheritance {
void bark() {
System.out.println("barking...");
}
}
class BabyDog extends Dog {
void weep() {
System.out.println("weeping...");
}
}
class TestInheritance {
public static void main(String args[]) {
BabyDog d=new BabyDog();
d.weep();
d.bark();
d.eat();
}
}

View File

@@ -49,6 +49,8 @@ if the problem still persist then create a issue or use Google/Stack Overlflow f
|23 | [OddEvenNumberOutput.java](https://github.com/psavarmattas/Java-Projects/blob/master/OddEvenNumberOutput.java) | Program to accept a number and check the number is even or not. Prints 1 if the number is even or 0 if the number is odd. | |23 | [OddEvenNumberOutput.java](https://github.com/psavarmattas/Java-Projects/blob/master/OddEvenNumberOutput.java) | Program to accept a number and check the number is even or not. Prints 1 if the number is even or 0 if the number is odd. |
|24 | [CommandLineInput.java](https://github.com/psavarmattas/Java-Projects/blob/master/CommandLineInput.java) | Program in java to demonstrate input from keyboard using Comand Line Argument. | |24 | [CommandLineInput.java](https://github.com/psavarmattas/Java-Projects/blob/master/CommandLineInput.java) | Program in java to demonstrate input from keyboard using Comand Line Argument. |
|25 | [ThreeInteger.java](https://github.com/psavarmattas/Java-Projects/blob/master/ThreeInteger.java) | Program that accepts three integers from the user and return true if the second number is greater than first number and third number is greater than second number. If "abc" is true second number does not need to be greater than first number. | |25 | [ThreeInteger.java](https://github.com/psavarmattas/Java-Projects/blob/master/ThreeInteger.java) | Program that accepts three integers from the user and return true if the second number is greater than first number and third number is greater than second number. If "abc" is true second number does not need to be greater than first number. |
|26 | [MultiLevelInheritance.java](https://github.com/psavarmattas/Java-Projects/blob/master/MultiLevelInheritance.java) | Program in java to demonstrate multilevel inheritance in java. |
|27 | [AbstractClassProgram](https://github.com/psavarmattas/Java-Projects/blob/master/AbstractClassProgram.java) | Program to create an abstract class named Shape that contains two integers and an empty method named print Area (). Provide three classes named Rectangle, Triangle and Circle such that each one of the classes extends the class Shape. Each one of the classes contains only the method print Area () that prints the area of the given shape. |
@@ -84,7 +86,9 @@ if the problem still persist then create a issue or use Google/Stack Overlflow f
|2 | [Voter.java](https://github.com/psavarmattas/Java-Projects/blob/master/Voter.java) | Program to store Voter detail as voter id, voter name & monthly income for a voter in a class. Compute annual income & display the detail. Use parameterized constructor. | |2 | [Voter.java](https://github.com/psavarmattas/Java-Projects/blob/master/Voter.java) | Program to store Voter detail as voter id, voter name & monthly income for a voter in a class. Compute annual income & display the detail. Use parameterized constructor. |
|2 | [ChainConstructor.java](https://github.com/psavarmattas/Java-Projects/blob/master/ChainConstructor.java) | Program in java to demonstrate chain constructor. | |2 | [ChainConstructor.java](https://github.com/psavarmattas/Java-Projects/blob/master/ChainConstructor.java) | Program in java to demonstrate chain constructor. |
|2 | [ThreeInteger.java](https://github.com/psavarmattas/Java-Projects/blob/master/ThreeInteger.java) | Program that accepts three integers from the user and return true if the second number is greater than first number and third number is greater than second number. If "abc" is true second number does not need to be greater than first number. | |2 | [ThreeInteger.java](https://github.com/psavarmattas/Java-Projects/blob/master/ThreeInteger.java) | Program that accepts three integers from the user and return true if the second number is greater than first number and third number is greater than second number. If "abc" is true second number does not need to be greater than first number. |
|3 | [Calculator](https://github.com/psavarmattas/Java-Projects/blob/master/Calculator.java) | Program that implements the arithmetic operation (Calculator) using switch statement. |2 | [MultiLevelInheritance.java](https://github.com/psavarmattas/Java-Projects/blob/master/MultiLevelInheritance.java) | Program in java to demonstrate multilevel inheritance in java. |
|3 | [Calculator](https://github.com/psavarmattas/Java-Projects/blob/master/Calculator.java) | Program that implements the arithmetic operation (Calculator) using switch statement. |
|3 | [AbstractClassProgram](https://github.com/psavarmattas/Java-Projects/blob/master/AbstractClassProgram.java) | Program to create an abstract class named Shape that contains two integers and an empty method named print Area (). Provide three classes named Rectangle, Triangle and Circle such that each one of the classes extends the class Shape. Each one of the classes contains only the method print Area () that prints the area of the given shape. |