153 lines
3.1 KiB
Java
153 lines
3.1 KiB
Java
package Exam;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
public abstract class shapes {
|
|
private int length, breadth, radius;
|
|
|
|
public shapes(){
|
|
print("Here");
|
|
|
|
}
|
|
public shapes(int length, int breadth){
|
|
this.length = length;
|
|
this.breadth = breadth;
|
|
}
|
|
|
|
public shapes(int radius){
|
|
this.radius = radius;
|
|
}
|
|
|
|
public shapes(float radius){
|
|
this.radius = (int) radius;
|
|
}
|
|
|
|
public int getArea(){
|
|
return this.length * this.breadth;
|
|
}
|
|
|
|
public float getCircleArea(){
|
|
return (float) (this.radius * this.radius * 3.14);
|
|
}
|
|
|
|
public int getPerimeter(){
|
|
return 2 * (this.length + this.breadth);
|
|
}
|
|
|
|
public float getCirclePerimeter(){
|
|
return (float) (2 * this.radius * 3.14);
|
|
}
|
|
|
|
public static int shape(int length, int breadth){
|
|
return length * breadth;
|
|
}
|
|
|
|
public static double shape(double radius){
|
|
return radius * radius * 3.14;
|
|
}
|
|
public <t> t shape(t a){
|
|
return a;
|
|
}
|
|
|
|
// toString() method
|
|
public String toString(){
|
|
// System.out.println("Length: " + this.length + " Breadth: " + this.breadth);
|
|
if (this.length == 0 && this.breadth == 0){
|
|
return "Radius: " + this.radius;
|
|
}
|
|
else {
|
|
return "Length: " + this.length + " Breadth: " + this.breadth;
|
|
}
|
|
}
|
|
|
|
public static <t> void print() {
|
|
print(null);
|
|
}
|
|
|
|
|
|
public static <t> void print(t a){
|
|
System.out.println(a);
|
|
}
|
|
}
|
|
|
|
class shape2 extends shapes{
|
|
|
|
public shape2(){
|
|
|
|
}
|
|
public shape2(int length, int breadth){
|
|
super(length, breadth);
|
|
}
|
|
|
|
public String toString(){
|
|
print(super.toString());
|
|
return"This is shape2 class";
|
|
}
|
|
|
|
public static void main(String... args) {
|
|
shape2 s = new shape2();
|
|
// System.out.println(s);
|
|
try{
|
|
print("Hello");
|
|
}
|
|
finally {
|
|
print("Finally");
|
|
}
|
|
}
|
|
}
|
|
|
|
class testMarks {
|
|
// Generic score
|
|
public static String getScore(double score){
|
|
// double score;
|
|
//
|
|
// try {
|
|
// score = Double.parseDouble(a.toString());
|
|
// }
|
|
// catch (Exception e){
|
|
// return "E";
|
|
// }
|
|
|
|
if (75 <= score && score <= 100) {
|
|
return "A";
|
|
} else if (60 <= score && score < 75) {
|
|
return "B";
|
|
} else if (40 <= score && score < 60) { // 40 <= score < 60
|
|
return "C";
|
|
} else if (0 <= score && score < 40) {
|
|
return "F";
|
|
}
|
|
else {
|
|
return "E";
|
|
}
|
|
}
|
|
|
|
public String toString(){
|
|
return "This is testMarks class";
|
|
}
|
|
|
|
public static void main(String... args) {
|
|
testMarks t = new testMarks();
|
|
System.out.println(t);
|
|
System.out.println(getScore(90));
|
|
}
|
|
}
|
|
|
|
class rec{
|
|
public void printname(){
|
|
System.out.println("Val a");
|
|
}
|
|
}
|
|
|
|
class sq extends rec{
|
|
public void printname(){
|
|
System.out.println("Val b");
|
|
}
|
|
}
|
|
|
|
class test3{
|
|
public static void main(String... args) {
|
|
sq s = new sq();
|
|
s.printname();
|
|
}
|
|
} |