Assignment 1 Debi
Assignment 1 Debi
Assignment 1 Debi
CODE:
package Assignment1;
import java.util.*;
class Employee {
String name;
double salary;
int age;
employee1.name="Joseph";
employee1.salary=65784.50;
employee1.age=25;
System.out.println("\nEmployee1 details:");
employee1.getData();
System.out.println("\nEmployee2 details:");
employee2.getData();
CODE:
package Assignment1;
class Product{
String prodId;
int quantity;
double price;
static double totalPrice;
void display(){
3. Define a class Deposit. The instance variables of the class Deposit are
mentioned below.
Instance Variable Data Type
Principal Long
Time Integer
Rate Double
TotalAmt Double
Initialize the instance variables Principal, Time, rate through constructors.
Constructors are overloaded with the following prototypes.
Constructor1: Deposit ( )
Constructor2: Deposit (long, int, double)
Constructor3: Deposit (long, int)
Constructor4: Deposit (long, double)
Apart from constructors, the other instance methods are (i) display ( ): to
display the value of instance variables, (ii) calcAmt( ): to calculate the total
amount. totalAmt = Principal + (Principal * rate * Time)/100;
CODE:
package Assignment1;
class Deposit{
long principal;
int time;
double rate, totalAmt;
Deposit(){ //constructor1
void display(){
System.out.println("Principal amount: "+principal+ "\n"
+"Rate of Interest: "+rate+ "\n"
+"Time period: "+time+ "\n"
+"Total Amount: "+totalAmt);
}
void calcAmt(){
totalAmt=principal + (principal * rate * time)/100;
}
}
public class Q3 {
public static void main(String[] args) {
Deposit p1=new Deposit();
Deposit p2=new Deposit(1000,5,20);
Deposit p3=new Deposit(1000,5);
Deposit p4=new Deposit(1000, 20);
p2.calcAmt();
p2.display();
}
}
OUTPUT:
4. Define a base class Employee with instance variable name, age. The
instance variables are initialized through constructors. The prototype of the
constructor is as below.
Employee (string, int)
Define a derived class HR with instance variables Eid, salary. The instance
variables are initialized through constructors. The prototype of the
constructor is as below.
HR (string, int, int, double).
Another instance method of the HR class is DisplayDetails() to display the
information of HR details.
CODE:
package Assignment1;
class Employee1{
String name;
int age;
void displayDetails(){
System.out.println("EMPLOYEE DETAILS");
System.out.println("Name: "+name);
System.out.println("Age: "+age);
System.out.println("ID: "+eID);
System.out.println("Salary: "+salary);
}
}
public class Q4 {
public static void main(String[] args) {
HR e=new HR("Chandan",25,2141013059,70000);
e.displayDetails();
}
}
OUTPUT:
float getPercentage(){
return percentage=(markICP+markDSA+algoDesign)/3;
}
}
float getPercentage(){
return percentage=(markICP+markDSA+enggMechanics)/3;
}
}
public class Q5 {
public static void main(String[] args) {
CSE s1=new CSE(90,85,75);
nonCSE s2=new nonCSE(80,65,95);
System.out.println("The percentage of CSE student: "+s1.getPercentage());
System.out.println("The percentage of NonCSE student: "+s2.getPercentage());
}
}
OUTPUT:
interface DetailInfo{
void display();
int count();
}
@Override
public void display(){
System.out.println("Student name: "+name);
}
@Override
public int count(){
maxCount= name.length();
return maxCount;
}
}
public class Q6 {
public static void main(String[] args) {
Student s1=new Student();
s1.setter("Chandan");
s1.display();
int maxCount = s1.count();
System.out.println("MaxCount: " + maxCount);
}
}
OUTPUT:
7. Design a package that contains two classes: Student & Test. The Student
class has data members as name, roll and instance methods inputDetails()
& showDetails(). Similarly the Test class has data members as mark1,
mark2 and instance methods inputDetails(), showDetails(), Student is
extended by Test. Another package carry interface Sports with 2 attributes
score1, score2. Find grand total mark & score in another class.
CODE:
Student.java
package A1Q7;
import java.util.*;
void inputDetails(){
Scanner in=new Scanner(System.in);
System.out.println("Enter the student name: ");
name=in.nextLine();
System.out.println("Enter the roll number: ");
roll=in.nextInt();
}
void showDetails(){
System.out.println("Student name: "+name);
System.out.println("Roll No: "+roll);
}
}
Test.java
package A1Q7;
import java.util.Scanner;
void inputDetails(){
super.inputDetails();
Scanner in=new Scanner(System.in);
System.out.println("Enter the mark1: ");
mark1=in.nextInt();
System.out.println("Enter the mark2: ");
mark2=in.nextInt();
}
void showDetails(){
super.showDetails();
System.out.println("Mark1 is: "+mark1);
System.out.println("Mark2 is: "+mark2);
}
}
Sports.java
package A1Q7;
interface Sports {
int score1 = 60;
int score2 = 40;
}
Calculate.java
package A1Q7;
Main.java
package A1Q7;
public class Main {
public static void main(String[] args) {
Calculate s1=new Calculate();
s1.inputDetails();
s1.calculate();
}
}
OUTPUT: