0% found this document useful (0 votes)
16 views5 pages

Ali Akhlaqi Homee Work

The document contains 7 Java programs demonstrating different OOP concepts like classes, objects, generics, inheritance, encapsulation etc. Some key examples include: 1. Defining a Student class with id and name attributes and creating an object of it. 2. Using generics to store different data types in a Test class. 3. Creating a parameterized csclass to store multiple data types. 4. Defining a constructor class with a static attribute to initialize objects. 5. Implementing encapsulation in a Regester class with private fields. 6. Creating an Account class with methods to demonstrate bank operations. 7. Defining a Box class with methods to calculate volume of boxes of different dimensions

Uploaded by

akhlaqiali79
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)
16 views5 pages

Ali Akhlaqi Homee Work

The document contains 7 Java programs demonstrating different OOP concepts like classes, objects, generics, inheritance, encapsulation etc. Some key examples include: 1. Defining a Student class with id and name attributes and creating an object of it. 2. Using generics to store different data types in a Test class. 3. Creating a parameterized csclass to store multiple data types. 4. Defining a constructor class with a static attribute to initialize objects. 5. Implementing encapsulation in a Regester class with private fields. 6. Creating an Account class with methods to demonstrate bank operations. 7. Defining a Box class with methods to calculate volume of boxes of different dimensions

Uploaded by

akhlaqiali79
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/ 5

AliAkhlaqi homework.

public class testStudent{


public static void main(String[]args){
Student s1 = new Student();

System.out.println(s1.id=12);
System.out.println(s1.name = "ali");
}
}
class Student {
int id;
String name;

public class student1 {


public static void main(String[] args) {
Test<Integer> a=new Test<Integer>(123);
Test<String> a1=new Test<String>("mahdi");
Test<Double> a2=new Test<Double>(123.123);
a.display();
a1.display();
a2.display();
}
}
class Test<T>{
T obj;
Test(T a){
obj=a;
}
void display(){
System.out.println(obj);
}}

// Created by mahdi on 4/26/2023.

public class Student2 {


public static void main(String[] args) {
csclass<Integer,String >difob ;
difob=new csclass<Integer,String>(13,"This is String ");

csclass<String,Integer> difob2;
difob2=new csclass<String,Integer>("this is String",14);
difob.display();
difob2.display();

}
}
class csclass<T,U>{
T obj1;
U obj2;
csclass(T o1, U o2){
obj1=o1;
obj2=o2; }
void display(){
System.out.print(obj1+" , ");
System.out.print(obj2+"\n");
AliAkhlaqi homework.

public class testStudent{


public static void main(String[]args){
Student s1 = new Student();

System.out.println(s1.id=12);
System.out.println(s1.name = "ali");
}
}
class Student {
int id;
String name;

}
}

// Created by mahdi on 4/26/2023.

public class Student3 {


public static <M> void print(M[] inpuArray){
for (M elment: inpuArray){
System.out.print(elment+" ");
}
System.out.println();
}
public static void main(String[] args) {
Integer intArray[]={12,3,12,23,2,2,4432,3,42,3};
Double doubleArray[]={34.243,2.234,24332.4,24.243,24.24,234.23};
Character charArray []={'f','3','f','h'};
print(intArray);
print(doubleArray);
print(charArray);
}
}

// Created by mahdi on 4/26/2023.

public class Student4 {


public static void main(String[] args) {
constractor c=new constractor();
constractor c1=new constractor();
System.out.println(c.a);
System.out.println(c1.a);
}}
class constractor{
int a;
constractor(){
a=100;
}}

import com.sun.xml.internal.bind.v2.model.core.ID;
AliAkhlaqi homework.

public class testStudent{


public static void main(String[]args){
Student s1 = new Student();

System.out.println(s1.id=12);
System.out.println(s1.name = "ali");
}
}
class Student {
int id;
String name;

// Created by mahdi on 4/26/2023.

public class student5 {


public static void main(String[] args) {
Regester s1=new Regester("mahdi",32);
Regester s2=new Regester("Ali",14);
Regester s3=new Regester("mohamad",23);
s1.display();
s2.display();
s3.display();
}
}
class Regester{
private int ID;
private String name;
private int age;
public static int regester;
public Regester(String name,int age ) {
this.age=age;
this.name=name;
this.ID=id();

}static int id(){


regester=regester+1;
return regester; }
public void display(){
System.out.println("ID :"+ID);
System.out.println("name :"+ name);
System.out.println("age :"+age);
System.out.println();
}
}

public class Student6 {


public static void main(String[] args) {
Account a1=new Account();
Account a2=new Account();
a1.createAccont(200,"mahdi",20000);
a1.display();
a1.deposit(3000);
a1.chickBlance();
a1.withdroaw(6000);
a1.chickBlance(); }
AliAkhlaqi homework.

public class testStudent{


public static void main(String[]args){
Student s1 = new Student();

System.out.println(s1.id=12);
System.out.println(s1.name = "ali");
}
}
class Student {
int id;
String name;

}
//=================================================================================
class Account{
int acc_ON;
String name;
float amuint;
//............................................................................
void createAccont(int acc_ON,String name,float amuint ){
this.acc_ON=acc_ON;
this.name=name;
this.amuint=amuint; }
//............................................................................
void display(){
System.out.println("name :"+name+"\n acc_on :"+acc_ON+"\n amuint :"+amuint); }
//............................................................................
void deposit(float am){
this.amuint=amuint+am;
System.out.println("ouy deposit "+am+"now");}
//............................................................................
void chickBlance(){
System.out.println("now tour account is:"+amuint);
}
void withdroaw(float amt) {
if (amuint < amt) {
System.out.println("insufficient Balance");
} else {
this.amuint = amuint - amt;
System.out.println("ouy withdrow "+amt+"now");}}
}

public class student7 {


public static void main(String[] args) {
Box b1=new Box();
b1.boxdemo();
System.out.println(b1.valume());
//............................
Box b2=new Box();
b2.boxdemo1(10,5,8);
System.out.println(b2.valume());
}
}
//.............................................................................
class Box{
AliAkhlaqi homework.

public class testStudent{


public static void main(String[]args){
Student s1 = new Student();

System.out.println(s1.id=12);
System.out.println(s1.name = "ali");
}
}
class Student {
int id;
String name;

double height;
double width;
double dept;
//...........................................
void boxdemo(){
height =80;
width=40;
dept=20;}
//...........................................
void boxdemo1(double h,double w,double d){
height=h;
width=w;
dept=d;}
//.......................................
double valume(){
return height*width*dept; }
//.........................................
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy