Task1 - 921321205074
Task1 - 921321205074
TASK 2:
package uniquedigit;
import java.util.*;
abstract class Shape {
abstract void rectangleArea(int length, int breadth);
abstract void squareArea(int side);
abstract void circleArea(double radius);
}
area.rectangleArea(length, breadth);
area.squareArea(side);
area.circleArea(radius);
}
}
Output:
5
4
3
3.0
20
9
28.27
2)
import java.util.*;
interface ShapeCalculator {
void calc(int n);
}
square.calc(input);
circle.calc(input);
}
}
Output:
5
25 20
78.54 31.42
3)
import java.util.*;
void add() {
double real = real1 + real2;
double imag = imag1 + imag2;
System.out.println("Addition:\n\t" +
String.format("%.4f", real) + " +" + String.format("%.4f", imag)
+ " i");
}
void subtract() {}
void multiply() {}
void divide() {}
}
void add() {}
void multiply() {}
void divide() {}
}
void multiply() {
double real = real1 * real2 - imag1 * imag2;
double imag = real1 * imag2 + imag1 * real2;
System.out.println("Multiplication:\n\t" +
String.format("%.4f", real) + " +" + String.format("%.4f", imag)
+ " i");
}
void add() {}
void subtract() {}
void divide() {}
}
void divide() {
double denominator = real2 * real2 + imag2 * imag2;
double real = (real1 * real2 + imag1 * imag2) /
denominator;
double imag = (imag1 * real2 - real1 * imag2) /
denominator;
System.out.println("Division:\n\t" +
String.format("%.4f", real) + " +" + String.format("%.4f", imag)
+ " i");
}
void add() {}
void subtract() {}
void multiply() {}
}
double r1 = sc.nextDouble();
double i1 = sc.nextDouble();
double r2 = sc.nextDouble();
double i2 = sc.nextDouble();
4)
import java.util.*;
abstract class Marks {
abstract double getPercentage();
}
double getPercentage() {
return (marks1 + marks2 + marks3) / 3.0;
}
}
double getPercentage() {
return (marks1 + marks2 + marks3 + marks4) / 4.0;
}
}
int m1 = sc.nextInt();
int m2 = sc.nextInt();
int m3 = sc.nextInt();
A studentA = new A(m1, m2, m3);
System.out.println(String.format("%.2f",
studentA.getPercentage()));
int m4 = sc.nextInt();
B studentB = new B(m1, m2, m3, m4);
System.out.println(String.format("%.2f",
studentB.getPercentage()));
}
}
Output:
4
5
4
4.33
5)
package uniquedigit;
import java.util.*;
import java.util.Arrays;
interface SortInterface {
int minFrontMoves(int[] arr);
}
int moves = 0;
for (int i = 0; i < n; i++) {
if (arr[i] != sortedArr[moves]) {
moves++;
}
}
return moves;
}
}
int n = sc.nextInt();
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = sc.nextInt();
}
Output:
5
23 45 34 45 21
4
6)
import java.util.*;
void add() {
sum = num1 + num2;
}
void result() {
System.out.println(sum);
}
}
Output: 4 5
9
7)
import java.util.Scanner;
// Constructor
public Wooden(int quantity, double costPerUnit, double
basePrice) {
this.quantity = quantity;
this.costPerUnit = costPerUnit;
this.basePrice = basePrice;
}
// Constructor
public Electronics(String type, double basePrice, double
additionalCharge) {
this.type = type;
this.basePrice = basePrice;
this.additionalCharge = additionalCharge;
}
Output:
1
10
1000
10000.0
20000.0
Task1:
1)
import java.util.Scanner;
interface Employee {
void getDetails();
int computeSalary();
}
@Override
public void getDetails() {
System.out.println("Name: " + name);
System.out.println("ID: " + id);
}
@Override
public int computeSalary() {
return basicSalary + bonus;
}
}
@Override
public void getDetails() {
System.out.println("Name: " + name);
System.out.println("ID: " + id);
}
@Override
public int computeSalary() {
return ratePerHour * hoursWorked;
}
}
sc.close();
}
}
Output:
keerthana
21
4
10
keerthanadevi
20
5
9
Name: keerthana
ID: 21
Total salary: 14
Name: keerthanadevi
ID: 20
Total salary: 45
2)
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;
@Override
double calculateInterest(Date endDate) {
long months = (endDate.getTime() - startDate.getTime()) /
(1000L * 60 * 60 * 24 * 30);
return balance * interestRate * months / 12;
}
}
@Override
double calculateInterest(Date endDate) {
long months = (endDate.getTime() - startDate.getTime()) /
(1000L * 60 * 60 * 24 * 30);
return balance * interestRate * months / 12;
}
}
Account account;
if (accountType == 1) {
account = new SavingsAccount(name, accountNumber,
balance, startDate);
} else {
account = new CurrentAccount(name, accountNumber,
balance, startDate);
}
System.out.println(account.calculateInterest(endDate));
sc.close();
}
}
Output:
1
Karthick
101521502
7000
22/04/2013
22/04/2016
2520.0
3)
import java.util.*;
class Vehicle {
void move(String message) {
System.out.println(message);
}
}
sc.close();
}
}
Output:
are sweet
mangoo
mangoo
are sweet
4)
public class Main {
public static void main(String[] args) {
System.out.println("Hi");
main("Hello World");
main("Tom", "Jerry");
}
Output:
Hi
Overloaded: Hello World
Overloaded: Tom & Jerry
5)
import java.util.*;
class Hello {
void sayHello() {
System.out.println("Hello");
}
sc.close();
}
}
Output:
keerthana
Hello
Hello keerthana