Commit 6150bc48 authored by Qazi Zain's avatar Qazi Zain

deletion done

parent 418b9d93
package Class;
public abstract class Animal { // its an abstract class which can contain abstract and concreate both method.
protected void eat() //concreate method.
{
System.out.println("Eat Food");
}
abstract void makeSound(); //abstract method.
}
package Class;
public interface AudioPlayer {
void playMusic();
void stopMusic();
}
package Class;
public class Car implements AudioPlayer,Engine{
Car()
{
System.out.println("Object created");
}
// Audio player implementation
@Override
public void playMusic()
{
System.out.println("The Music is Playing");
}
@Override
public void stopMusic() {
System.out.println("The Music is Stop");
}
// Engine implementation.
@Override
public void startCar()
{
System.out.println("The car is start");
}
@Override
public void stopCar() {
System.out.println("The car is stop");
}
}
package Class;
public class Cat extends Animal{
Cat()
{
System.out.println("Object is created");
}
@Override
void makeSound()
{
super.eat(); // to use that parent function here.
System.out.println("Meoow");
}
}
package Class;
public interface Engine {
void startCar();
void stopCar();
}
package Class;
public class SuperClass {
}
package Class;
public class main {
public static void main(String[] args) {
// part here is accesing abstrract and its concreate class.
Cat obj = new Cat();
obj.makeSound();
obj.eat(); // its not cat class function but as cat is inheriting animal so it can access animal class method as well.
// interface implementation.
Car alto = new Car();
alto.playMusic();
alto.stopMusic();
alto.startCar();
alto.stopCar();
}
}
package Constructors;
public interface Bank {
void deposit(double b);
void withdraw(double b);
}
package Constructors;
public class CurrentAccount implements Bank{
private int accountNo;
protected double balance;
protected float tax;
// default constructor
CurrentAccount(){
System.out.println("Default constructor calls");
}
//parametrize constructor
CurrentAccount(int accountNo, double balance,float tax)
{
this.balance=balance;
this.accountNo=accountNo;
this.tax=tax;
System.out.println("Parametrizle connstructor run and values intialize");
}
CurrentAccount (CurrentAccount account1)
{
this.accountNo = account1.accountNo;
this.balance = account1.balance;
this.tax = account1.tax;
System.out.println("Copy connstructor runs and copy the account 1 value!");
}
// getters
public double getBalance() {
return balance;
}
@Override
public void deposit(double b)
{
balance+=b;
System.out.println("Money Deposited");
}
@Override
public void withdraw(double b)
{
balance-=b;
balance-=tax;
System.out.println("Money Withdrawed");
}
void printBalance()
{
System.out.println("Your account balance is: "+balance);
}
}
package Constructors;
import java.util.Scanner;
public class Main {
public static void main(String[] args) { // constituennt is part of an object having its attribute and methods.
Scanner obj= new Scanner(System.in);
System.out.println("Enter Account no:");
int accountNo= obj.nextInt();
System.out.println("Enter Balance");
double balance= obj.nextDouble();
System.out.println("Enter tax value");
float tax= obj.nextFloat();
CurrentAccount account2= new CurrentAccount(); // for default constructor run. // instannsiation of object as well.
CurrentAccount account1 = new CurrentAccount(accountNo, balance,tax); // also 200 added because we added during intializing in parametrize constructor.
account2.printBalance();
account1.printBalance();
account1.deposit(balance);
account1.printBalance();
account1.withdraw(balance);
account1.printBalance();
CurrentAccount account3; // declaretion of object.
account3 = new CurrentAccount(account1); // instansiation and intialization of object.
account3.printBalance();
}
}
package Constructors;
public class SavingAccounnt implements Bank {
private int accountNo;
protected double balance;
protected float tax;
//parametrize constructor
SavingAccounnt(int accountNo, double balance,float tax)
{
this.balance=balance;
this.accountNo=accountNo;
this.tax=tax;
}
// getters
public double getBalance() {
return balance;
}
@Override
public void deposit(double b)
{
balance+=b;
System.out.println("Money Deposited");
}
@Override
public void withdraw(double b)
{
balance-=b;
System.out.println("Money Withdrawed");
}
void printBalance()
{
System.out.println("Your account balance is: "+balance);
}
}
package DataTypes;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner obj = new Scanner(System.in);
PremativeDatatype Obj = new PremativeDatatype();
System.out.println("Enter name:");
String name = obj.nextLine();
System.out.println("Enter Age:");
int age = obj.nextInt();
System.out.println("Enter percentage");
float percentage = obj.nextFloat();
System.out.println("Enter income:");
double income = obj.nextDouble();
Obj.setAge(age);
Obj.setName(name);
Obj.setIncome(income);
Obj.setPercentage(percentage);
Obj.displayItems();
// using refrence variable usage.
RefrenceDatatype ref = new RefrenceDatatype();
// taking marks array is input.
int marks[]= new int[5];
for(int i=0;i<5;i++)
{
marks[i] = obj.nextInt();
}
ref.setMark(marks);
ref.setName("Zain");
ref.printStudentData();
}
}
package DataTypes;
import java.util.Scanner;
public class PremativeDatatype {
public int age;
public String name;
public Float percentage;
public Double income;
PremativeDatatype()
{
System.out.println("Object Created");
age=0;
name = "Null";
percentage = 0.0F;
income= 0.00000;
}
// setters
public void setAge(int age) {
this.age = age;
}
public void setName(String name)
{
this.name = name;
}
public void setPercentage(Float percentage)
{
this.percentage = percentage;
}
public void setIncome(Double income)
{
this.income=income;
}
public void displayItems()
{
System.out.println("Your name is :"+age);
System.out.println("Your age is :"+name);
System.out.println("Your Percentage is :"+percentage);
System.out.println("Your Income is :"+income);
}
}
package DataTypes;
public class RefrenceDatatype {
public int mark[] = new int[5];
public String name;
RefrenceDatatype()
{
System.out.println("Object is created");
name ="";
}
public void setName(String name) {
this.name = name;
}
public void setMark(int[] mark) {
this.mark = mark;
}
public void printStudentData()
{
System.out.println("Name is :"+name);
for(int i=0;i<5;i++)
{
System.out.println("Marks of this: "+mark[i]);
}
}
}
package ListInterface.ArrayList;
import java.util.ArrayList;
import java.util.Collections;
public class CoustomArrayList { // It is a data structure it use, to store objects and size is not fixed like array.
public ArrayList<Integer> list = new ArrayList<>(); // list is an object of array list. (Integer is a wrapper class of int holds int value as object)
CoustomArrayList()
{
System.out.println("Object is created");
}
void arrayListFunctions()
{
list.add(2);
list.add(3);
list.add(4);
list.add(7);
list.add(6);
list.add(7);
list.add(8);
System.out.println("Here is your list: ["+list+"]");
int element = list.get(2);
System.out.println("printing element on index 2 is:"+element);
// adding values on any particular index.
list.add(3,5);
System.out.println("Here is your list: ["+list+"]");
// set element present on any particular index.
list.set(4,05);
System.out.println("Here is your list: ["+list+"]");
//delete elements from list.
list.remove(4);
System.out.println("Here is your list: ["+list+"]");
// size
int size = list.size();
System.out.println(size);
list.add(0,12);
list.add(2,11);
list.add(3,9);
System.out.println("Here is your list: ["+list+"]");
// sorting assending.
Collections.sort(list);
System.out.println("Here is your list: ["+list+"]");
//printing array using loop
for(int i=0;i<list.size();i++)
{
System.out.println(list.get(i));
}
}
}
package ListInterface.ArrayList;
import ListInterface.ArrayList.CoustomArrayList;
public class Main {
public static void main(String[] args) {
CoustomArrayList obj = new CoustomArrayList();
obj.arrayListFunctions();
}
}
package ListInterface.LinkedList;
import java.util.*;
public class CoustomLinkdList {
LinkedList<Integer> obj = new LinkedList<>();
public CoustomLinkdList() {
System.out.println("Object is Created!");
}
public void LinkdList() {
// Adding in LinkedList
obj.add(3);
obj.add(4);
System.out.println("LinkedList: " + obj);
// Adding at a particular index
obj.add(1, 7);
obj.add(2, 1);
System.out.println("LinkedList after adding at specific index: " + obj);
// Adding elements at the first and last position
obj.addFirst(10);
obj.addLast(20);
System.out.println("LinkedList after adding first and last: " + obj);
// Removing elements
obj.remove(2); // Removes element at index 2
System.out.println("LinkedList after removal at index 2: " + obj);
obj.removeFirst(); // Removes the first element
obj.removeLast(); // Removes the last element
System.out.println("LinkedList after removing first and last: " + obj);
// Accessing elements
int firstElement = obj.getFirst();
int lastElement = obj.getLast();
System.out.println("First element: " + firstElement);
System.out.println("Last element: " + lastElement);
System.out.println("Element at index 1: " + obj.get(1));
// Checking if the list contains an element
boolean contains7 = obj.contains(7);
System.out.println("Contains 7? " + contains7);
// Getting the size of the list
int size = obj.size();
System.out.println("Size of LinkedList: " + size);
// Clearing the list
obj.clear();
System.out.println("LinkedList after clearing: " + obj);
// Re-adding elements after clearing
obj.add(50);
obj.add(60);
System.out.println("LinkedList after re-adding elements: " + obj);
}
}
package ListInterface.LinkedList;
public class Main {
public static void main(String[] args) {
CoustomLinkdList obj = new CoustomLinkdList();
obj.LinkdList();
}
}
package MapInterface.CoustomHashMap;
import java.util.*;
public class CoustomHashMap
{
HashMap<Integer,String> obj = new HashMap<>();
CoustomHashMap()
{
System.out.println("Coustom HaspMap object is created!");
}
void displayHashMap()
{
// add value in HashMap.
obj.put(1,"zain");
obj.put(2,"ali");
obj.put(3,"zain"); // value iss duplicate and key is unique it will add.
obj.put(1,"zain"); // this will not add because key isn't unique.
System.out.println("Values in Hash Map:"+obj);
// Searching in map.
if(obj.containsKey(2))
{
System.out.println("ali is in hash table as a record");
}
// get value
System.out.println("value of key 3 is:"+obj.get(3));
}
}
package MapInterface.CoustomHashMap;
public class Main {
public static void main(String[] args) {
}
}
package Methods;
import java.util.Scanner;
public class Library {
int bookNo;
String bookTitle;
String yearOfPublish;
long price;
int tax;
Library() // constructor.
{
bookNo = 0;
bookTitle = "";
yearOfPublish = "";
tax =0;
}
public int getBookNo() { // they are usually Methods which return the value and there type is take nothing return something.
return bookNo;
}
public String getBookTitle() {
return bookTitle;
}
public long getPrice() {
return price;
}
public String getYearOfPublish()
{
return yearOfPublish;
}
//setter also types of method which use to set the or change the value of variable;
// Type of this method is Take something return nothing.
public void setYearOfPublish(String yearOfPublish) {
this.yearOfPublish = yearOfPublish;
}
public void setBookNo(int bookNo) {
this.bookNo = bookNo;
}
public void setBookTitle(String bookTitle) {
this.bookTitle = bookTitle;
}
public void setPrice(long price) {
this.price = price;
}
// Function take nothing return nothing.
public void printBook()
{
System.out.println("Book name is: "+bookTitle);
System.out.println("Book publish date: "+yearOfPublish);
System.out.println("Book id no: "+bookNo);
System.out.println("Book price is: "+price);
}
// take something return something.
public int sendTax(int t)
{
System.out.println("Enter the Tax: ");
Scanner obj = new Scanner(System.in);
tax=obj.nextInt();
tax+=t;
return tax;
}
}
\ No newline at end of file
package Methods;
public class Main {
public static void main(String[] args) {
Library obj = new Library();
obj.setBookNo(5);
obj.setBookTitle("Academic");
obj.setPrice(5000);
obj.setYearOfPublish("11-Nov-2004");
obj.printBook();
int tax = obj.sendTax(286);
System.out.println("The tax after adding 1usd:"+tax);
}
}
package SetInterface.HashSet;
import java.util.*;
public class CoustomHashSet
{
HashSet<String> obj = new HashSet<>();
CoustomHashSet()
{
System.out.println("Object is Created!");
}
void displayHasetFunction()
{
//adding elements in HashSet.
obj.add("zain");
obj.add("Maaz");
obj.add("Hurriyah");
obj.add("Fatima");
obj.add("zain"); // would not add duplicate values.
System.out.println("Your Hashset is:"+obj);
// search in hashset
if( obj.contains("zain"))
{
System.out.println("Present in The List");
}
// for delete in HashSet
obj.remove("Hurriyah");
System.out.println("Your Hashset is:"+obj);
}
}
package SetInterface.HashSet;
public class Main {
public static void main(String[] args) {
CoustomHashSet obj = new CoustomHashSet();
obj.displayHasetFunction();
}
}
package Syntax;
public class Circle extends Shape{ // class name must be start with capital letter.
@Override
int calculateArea(int a , int b) // camle case use here
{
int area = a*b;
return area;
}
}
package Syntax;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
int area;
Scanner object = new Scanner(System.in);
System.out.println("Enter length: ");
int length = object.nextInt();
System.out.println("Enter Breadth: ");
int breadth = object.nextInt();
Circle obj = new Circle ();
area=obj.calculateArea(length,breadth);
System.out.println("The total area is : "+area);
}
}
package Syntax;
abstract class Shape {
Shape()
{
System.out.println("Object Intialize");
}
abstract int calculateArea(int a, int b);
}
package Variables;
public class Main {
public static void main(String[] args) {
Students obj = new Students();
Students obj1 = new Students();
Students obj2 = new Students();
obj2.setName("Zain");
obj.setName("Qazi");
obj1.setName("Haseeb");
obj2.displayStudentData();
}
}
package Variables;
public class Students {
public static int NO_OF_STUDENTS=0; // static variable
public String name;
//constructor
Students()
{
name = "";
//NO_OF_STUDENTS= 0; if we do this it will always reset our value.
System.out.println("Object Created");
NO_OF_STUDENTS++;
}
//setter
public void setName(String name) {
this.name = name;
}
// getter.
public static int getNoOfStudents()
{
return NO_OF_STUDENTS;
}
public void displayStudentData()
{
System.out.println("Your name is: "+name);
System.out.println("No of student Enroll: "+NO_OF_STUDENTS);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment