[go: up one dir, main page]

0% found this document useful (0 votes)
378 views6 pages

Rollno Name Percent: 1. Java Program To Create Student Class Class Int Int Static Int

The document contains 4 Java programs: 1. A Student class with constructors to initialize student data and methods to display student information. 2. An Account class with methods to withdraw and deposit funds and constructors to initialize account details. 3. A Time class with constructors, a method to add two Time objects, and a main method to demonstrate usage. 4. A Donor class with constructors, set and display methods, and a main method that searches donor records by blood group and other criteria.

Uploaded by

PALASH KHARE
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
378 views6 pages

Rollno Name Percent: 1. Java Program To Create Student Class Class Int Int Static Int

The document contains 4 Java programs: 1. A Student class with constructors to initialize student data and methods to display student information. 2. An Account class with methods to withdraw and deposit funds and constructors to initialize account details. 3. A Time class with constructors, a method to add two Time objects, and a main method to demonstrate usage. 4. A Donor class with constructors, set and display methods, and a main method that searches donor records by blood group and other criteria.

Uploaded by

PALASH KHARE
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

1.

Java program to create Student class


class​ Student3
{
int​ ​rollno​;
String ​name​;
int​ ​percent​;
static​ ​int​ ​count​=0;
Student3()
{
count++;
rollno​=001;
name​=​"xyz"​;
percent​=10;

}
Student3(​int​ ​x​,String ​y​,​int​ ​z​)
{
Student3 ​temp​=​new​ Student3();
count​++;
Student3.​disp​();
temp​.display();
rollno​=​x​;
name​=​y​;
percent​=​z​;
}
public​ ​static​ ​void​ disp()
{
System.​out​.println(​"The value of count is"​ +​count​);
}
void​ display() {
System.​out​.println(​"Roll No"​ +​rollno​ +​"Name"​ +​name
+​"Percentage"​ +​percent​);
}
}
public​ ​class​ Student {
public​ ​static​ ​void​ main(String ​args​[])
{
Student3 ​s4​=​new​ Student3(233,​"ME"​,89);
s4​.display();
Student3[] ​s1​=​new​ Student3[2];
int​ ​i​;
for​(​i​=0;​i​<2;​i​++)
{
s1​[​i​]=​new​ Student3();
Student3.​count​++;
Student3.​disp(​ );
​ 1​[​i​].display();
s
}

}
}

2. Java program to create Account class

import​ java.util.Scanner;

class​ Account {
int​ ​accno​;
String ​name​;
int​ ​balance​;
static​ ​int​ ​num​=1000;
Account() {
accno​=​num​++;
name​=​null​;
balance​=10000;
}
Account(String ​y​,​int​ ​z​)
{
accno​=​num​++;
name​=​y​;
balance​=​z​;
}
void​ withdrawal(​int​ ​amt​)
{
balance​ = ​balance​-​amt​;
System.​out. ​ println(​"Acc No"​ +​accno​ + ​"Name"​ +​name​ +​"Balance"
+​balance​);
}
void​ deposit(​int​ ​amt1​)
{
balance​=​balance​+​amt1​;
System.​out. ​ println(​"Acc No"​ +​accno​+ ​"Name"​ +​name​+ ​"Balance"
+​balance​);
}
}
public​ ​class​ AccountM {
public​ ​static​ ​void​ main(String ​args​[])
{
Scanner ​sc​=​new​ Scanner(System.​in​);
System.​out. ​ println(​"Enter the first amt?"​);
int​ ​a1​=​sc​.nextInt();
System.​out. ​ println(​"Enter the second amt?"​);
int​ ​a2​=​sc​.nextInt();
Account ​a​=​new​ Account();
Account ​b​=​new​ Account();
a​.withdrawal(​a1​);
b​.deposit(​a2​);

3. Java program Time class

​class​ Time {
​int​ ​hr​,​min​,​sec​;
Time() ​// default constructor
{
​hr​=0;​min​=0;​sec​=0;
}
Time(​int​ ​x​,​int​ ​y​,​int​ ​z​) ​// ​parameterised​ constructor
{
hr​=​x​;
min​=​y​;
sec​=​z​;
}

void​ display()
{
System.​out. ​ println(​hr​ +​":"​ +​min​ +​":"​+​sec​);
}
Time add(Time ​a​,Time ​b​)
{
Time ​c​ = ​new​ Time();
c​.​hr​=​a​.​hr​+​b​.​hr​;
c​.​min​=​a​.​min​+​b​.​min​;
c​.​sec​=​a​.​sec​+​b​.​sec​;
return​ ​c​;
}
}​// end of class Time1
​class​ Time1
{
​public​ ​static​ ​void​ main(String ​args​[]) {
Time ​t​ = ​new​ Time(20,30,40);
​t​.display();
Time ​b​=​new​ Time(30,40,50);
​b​.display();
Time ​d​=​new​ Time();
​d​=​d​.add(​t​,​b​);
​d​.display();
}
}

4. Java program to create Donors class

import​ java.util.Scanner;
class​ Donor1 {
int​ ​dno​;
int​ ​age​;
String ​address​;
String ​gender​;
String ​bg​;
String ​name​;
void​ set() {
Scanner ​sc​ = ​new​ Scanner(System.​in) ​ ;
dno​=​sc​.nextInt();
name​=​sc​.next();
age​=​sc​.nextInt();
address​=​sc​.next();
bg​=​sc​.next();
}
Donor1(){
dno​=0;
name​=​null​;
age​=0;
address​=​null​;
gender​=​null​;
bg​=​null​;
}
Donor1(​int​ ​a​,String ​s​, String ​y​) {
dno​=​a​;
name​=​s​;
address​=​y​;
}
void​ display() {
System.​out. ​ println(​dno​+ ​":"​ + ​address​ +​":"​ +​name​ +​bg​);
}
}
class​ Donor {
public​ ​static​ ​void​ main(String ​args​[]) {
Donor1[] ​d​=​new​ Donor1[1];​// array of object concept
for​(​int​ ​i​=0;​i​<1;​i​++) {
d​[​i​]=​new​ Donor1();
d​[​i​].set();
}
int​ ​ch​;
Scanner ​sc​ = ​new​ Scanner(System.​in) ​ ;
do​ {
System.​out. ​ println(​"Options"​);
System.​out. ​ println(​"1. O +ve"​);
System.​out. ​ println(​"2. B +ve 16-25"​);
System.​out. ​ println(​"3. Blood group A b/w 19-24"​);
ch​=​sc​.nextInt();
if​(​ch​==1)
{
for​(​int​ ​i​=0;​i​<1;​i​++)
{
if​((​d​[​i​].​bg​).equals(​"O +ve"​)) {

d​[​i​].display();
}
}
}
if​(​ch​==2)
{
for​(​int​ ​i​=0;​i​<1;​i​++)
{
​if​(((​d​[​i​].​age​)>=16) && ((​d​[​i​].​age​)<=25)) {

d​[​i​].display();
}
}
}
if​(​ch​==3)
{
for​(​int​ ​i​=0;​i​<1;​i​++)
{ if​(((​d​[​i​].​age​)>=19) && ((​d​[​i​].​age​)<=24) && ((​d​[​i​].​bg​).equals(​"A
+ve"​)))
d​[​i​].display();
}
}
}
while​ (​ch​<=3);
}
}

You might also like