Commit 016618e0 authored by Zain's avatar Zain

Adding my first commit

parent 09421abe
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
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 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 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