Ilaans Record

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 16

import java.util.

*;

public class Student

String name, dob;

int roll;

public void inputdata()

Scanner sc=new Scanner(System.in);

System.out.println("enter name");

name=sc.nextLine();

System.out.println("enter date of birth");

dob=sc.nextLine();

System.out.println("enter roll number");

roll=sc.nextInt();

public void printdata()

System.out.println();

System.out.println();

System.out.print("Name : ");

System.out.println(name);

System.out.print("Date Of Birth : ");

System.out.println(dob);

System.out.print("Roll No. :");

System.out.println(roll);

}
import java.util.*;

public class marks extends Student

float p, c, m, cts, e;

float tot, per;

char gd;

public void readdata()

Scanner sc=new Scanner(System.in);

System.out.println("enter marks(out of 100) in:-");

System.out.print("Physics : ");

p=sc.nextFloat();

System.out.print("Chemistry : ");

c=sc.nextFloat();

System.out.print("Math : ");

m=sc.nextFloat();

System.out.print("Computer Science : ");

cts=sc.nextFloat();

System.out.print("English : ");

e=sc.nextFloat();

public void compute()

tot=p+c+m+cts+e;

per=tot/5;

if(per>=90)

gd='A';

else if(per>=60)

gd='B';

else if(per>=40)

gd='C';
else

gd='D';

public void showdata()

System.out.println();

System.out.println("Marks(out of 100) in:-");

System.out.print("Physics : ");

System.out.println(p);

System.out.print("Chemistry : ");

System.out.println(c);

System.out.print("Math : ");

System.out.println(m);

System.out.print("Computer Science : ");

System.out.println(cts);

System.out.print("English : ");

System.out.println(e);

System.out.println();

System.out.println("Total : " + tot);

System.out.println("Percentage : " + per);

System.out.println("Grade : " + gd);

public class Prog_1_Main

public static void main()

marks obj=new marks();

obj.inputdata();

obj.readdata();
obj.compute();

obj.printdata();

obj.showdata();

}
/*A class Iscores defines the scores of a candidate in six

subjects and another class bestfour defines the best of the four subjects:

The details of both classes are given below:-

Class Name : Iscores

Data Members:

int number[6][2] - contains marks for six subjects and subject code[numeric]

Member Functions:

Iscores - constructor to accept the marks

int point() - to return the point in each subject according to the following:

Marks Points

>=90 1

80-89 2

70-79 3

60-69 4

50-59 5

40-49 6

00-39 7

Class Name : bestfour

Member Functions:

void bestsubjects() - to display the total points and best of four subjects

codes using concept of inheritance

Specify the details of both the classes using the concept of inheritance.
Specify the details of the class, the functions and the main. */

public class Iscores

int[][] number=new int[6][2];

void accept(int i, int j, int input)

number[i][j] = input;

int point(int marks)

if(marks>=90)

return 1;

else if(marks>=80)

return 2;

else if(marks>=70)

return 3;

else if(marks>=60)

return 4;

else if(marks>=50)

return 5;

else if(marks>=40)

return 6;

else

return 7;
}

public class bestfour extends Iscores

void bestsubjects()

int total=0;

for(int i=0; i<6; i++)

total+= point(number[1][i]);

int temp1;

int temp2;

for(int i=1; i<6; i++)

int j;

j=i;

temp1=number[1][i];

temp2=number[0][i];

for(;j>0 && temp1<number[1][j-i]; j++)

number[1][j]=number[1][j-1];

number[0][j]=number[0][j-1];

number[1][j]=temp1;

number[0][j]=temp2;

System.out.println("Best Four Subjects:");


for(int i=0; i<6; i++)

System.out.println(number[0][i]);

}
public class Account

protected int accountNumber;

protected double principal;

Account(int accnum, double prin)

accountNumber=accnum;

principal=prin;

void display()

System.out.println("Account Number = " + accountNumber);

System.out.println("Principal = " + principal);

public class Simple extends Account

double rate;

double time;

Simple(double r, double t, int accnum, double prin)

super(accnum,prin);

rate=r;

time=t;

double calculate()

return (super.principal*rate*time)/100;

void display()
{

System.out.println("Rate = " +rate);

System.out.println("Time = " + time);

System.out.println("Interest = " + calculate());

public class Compound extends Account

double rate;

double time;

Compound(double r, double t, int accnum, double prin)

super(accnum,prin);

rate=r;

time=t;

double calculate()

return super.principal*(Math.pow((1 + (rate/100)),time)) - super.principal;

void display()

System.out.println("Rate = " +rate);

System.out.println("Time = " + time);

System.out.println("Interest = " + calculate());

}
import java.util.*;

public class Prog4

public static void main()

Scanner sc=new Scanner(System.in);

System.out.println("Enter account number");

int accountNum=sc.nextInt();

System.out.println("Enter principal amount");

double principal=sc.nextDouble();

System.out.println("

}
/*Implement the following heirarchy

* BankAc ------- SavingsAc

Class BankAc contains details about the account holder. New account number is obtained via a static
member AccNo which is incremented with every account creation.

Methods:-

deposit()

withdraw()

getBalance()

display()

Class SavingsAc inherits from BankAc and additionally stores rate of interest(monthly).

Methods:-

addInterest() - computes interest and adds it to balance.

display() - It overrides 'display()' method of BankAc.

Algorithm for class 'BankAc':-

void deposit():

Step 1 - Start

Step 2 - increment the 'AccNo'

Step 3 - take user input for amount to be deposited

Step 4 - End

void withdraw():

Step 1 - Start

Step 2 - access the scanner class

Step 3 - take user input for amount to be withdrawn


Step 4 - End

double getBalance():

Step 1 - Start

Step 2 - return the balance

Step 3 - End

void display():

Step 1 - Start

Step 2 - display the account number

Step 3 - End

Algorithm for class 'SavingsAc':-

void addInterest():

Step 1 - Start

Step 2 - assign a value to the rate of interest(assigned 12%)

Step 3 - call the 'getBalance()' method and store the return value

Step 4 - calculate interest and add it to the stored balance

Step 5 - End

void display():

Step 1 - Start

Step 2 - call the 'display()' function of the parent class

Step 3 - print the rate of interest

Step 4 - Check if balance is more than 0. If yes then print the balance else print the appropriate
message

Step 5 - End
Algorithm for Prog6:-

void main():

Step 1 - Start

Step 2 - create an object of the 'SavingsAc' class

Step 3 - call the functions 'deposit()', 'withdraw()', 'addInterest()' and 'display()'

Step 4 - End

*/

import java.util.*;

public class BankAc

static long AccNo=1;

double balance;

void deposit()

AccNo++;

balance=0;

Scanner sc=new Scanner(System.in);

System.out.println("Enter amount to be deposited");

balance+=sc.nextDouble();

void withdraw()

Scanner sc=new Scanner(System.in);

System.out.println("Enter amount to be withdrawn");

balance-=sc.nextDouble();

double getBalance()

return balance;

}
void display()

System.out.println("Account Number = " + AccNo);

public class SavingsAc extends BankAc

int rate;

double bal;

void addInterest()

rate=12;

bal= super.getBalance();

double interest= bal*rate/100;

bal+=interest;

void display()

super.display();

System.out.println("Rate = " + rate +"%");

if(bal>0)

System.out.println("Balance = " + bal);

else

System.out.println("Insufficient Balance");

public class Prog6


{

public static void main()

SavingsAc obj=new SavingsAc();

obj.deposit();

obj.withdraw();

obj.addInterest();

obj.display();

You might also like