Friday, 26 July 2013

Many Methods with Instances

ASSIGNMENT 12 - MANY METHOD$ WITH INSTANCE$

import java.util.Scanner;
public class Practice{

public static void main(String[] args){
Scanner datain = new Scanner(System.in);
MyClass obj = new MyClass();
MyClass2 obj2 = new MyClass2();

System.out.println("Enter your Name: ");
String text = datain.nextLine();

System.out.println("Enter your friend's Name: ");
String text2 = datain.nextLine();

obj.Display(text);
obj2.Display2(text2);
 } 
 }

class MyClass{
public void Display(String text){
System.out.println("Assalam-o-Alaikum: " +text);
}
}
class MyClass2{
public void Display2(String text2){
System.out.println("Assalam-o-Alaikum: " +text2);
}
}

Tuesday, 23 July 2013

Switch Statement

ASSIGNMENT 11 - SWITCH STATEMENT (DON'T NEED TO CREATE MANY IF STATEMENTS)

public class Practice{

public static void main(String[] args){

int speaker;
speaker = 5;
speaker = speaker - 5;

switch(speaker){
case 1:
System.out.println("You are a True Muslim");
break;
case 2:
System.out.println("You are not a True Muslim");
break;
case 3:
System.out.println("Are you a Muslim");
break;
case 4:
System.out.println("Yes, I am a Muslim");
break;
case 5:
System.out.println("I have interested in Islam");
break;
case 6:
System.out.println("I pray five times a day");
break;
default:
System.out.println("You have no $ense");
break;

}
 }
 }

Sunday, 21 July 2013

Create a Basic Simple Calculator

ASSIGNMENT 10 - CREATING A BASIC SIMPLE CALCULATOR:

import java.util.Scanner;

class Hotel {
public static void main(String[ ] args){
Scanner Ibrar = new Scanner( System.in );
double a, b, z;
System.out.println( "Enter a number: " );
a = Ibrar.nextDouble();
System.out.println( "Enter another number to proceed Calculation: " );
b = Ibrar.nextDouble( );
z = a + b;
System.out.println( "Your Sum is =>  " +z );
System.out.println( );
System.out.println( );
System.out.println( "-----------------------------" );
System.out.println( "Calculator by: Ibrar Ramzan Malik" );
}
}

Friday, 12 July 2013

Method Overriding

ASSIGNMENT 9: METHOD OVERRIDING:

public class Tower {


public static void main(String[] args) {
Youth obj = new Youth();
obj.display();
Youth obj2 = new Old();
obj2.display();
}
}
class Youth{
public void display(){
System.out.println("You got it!");
}
}
class Old extends Youth{
public void display(){
System.out.println("You again got it!");
}
}

Constructors - Multiple Parameters

ASSIGNMENT 8: CONSTRUCTORS using MULTIPLE PARAMETERS:

public class Tower {
String j;
String minitower;

public Tower(String v, String u){
this.j = v;
this.minitower = u;
}

public void display(){
System.out.println(j);
System.out.println(minitower);
}

public static void main(String[] args) {
Tower obj = new Tower("Pakistan", "Singapore");
obj.display();
}
}

Wednesday, 10 July 2013

Arrays - A Saving Bank

ASSIGNMENT 7: ARRAYS - A SAVING BANK:

public class MyJavaProject {

    public static void main(String[] args) {
        //varibale = y;


        int array[] = new int[15];    


        for (int y = 0; y < 15; y++)
        {
            array[y] = y+1;
        }
        for (int y = 0; y < 15; y++)
        {
            System.out.println("array["+y+"] = "+array[y]);
        }

}
   
}

Constructors & Objects - pick service

ASSIGNMENT 6: CONSTRUCTORS & OBJECTS:

public class MyJavaProject {
    public MyJavaProject()
    {
     
    }
    public void mytext(String text)
    {
        System.out.println(text);
    }
   
    public static void main(String[] args) {
            MyJavaProject obj = new MyJavaProject();
            obj.mytext("Ibrar");
            obj.mytext("Malik");
            obj.mytext("is Awesome!"); //function overloading...
   
    }
   
}

Decision Making

ASSIGNMENT 5: DECISION MAKING:

public class MyJavaProject {

    public static void main(String[] args) {
     int a = 4;
     int b = 10;
   
     if (a < b)
     {
         System.out.println("You are cool!");
     }
     else
     {
         System.out.println("You are idiot");
     }
     //******************************************
     if (a > b)
     {
         System.out.println("You are succeeded");
     }
     else
     {
         System.out.println("You are many times idiot");
     }
       
}


}

Exception - Try Catch

ASSIGNMENT 4: EXCEPTION, TRY-CATCH:

public class MyJavaProject {
   


    public static void main(String[] args) {
        int a = 4;
        int b = 0;
        int x = a / b;
        try
        {
            System.out.println("your value is divided");
            System.out.println(x);
        }
        catch(ArithmeticException ex)
        {
            System.out.println("You can't this value by zero");
        }
        // first priority is given to try, if it is possible to calculate. Otherwise an error will be caught.

}

Loops - Call Your Function many times

ASSIGNMENT 3: LOOPS - call your function many times: 
 
public class MyJavaProject {
   

    public static void main(String[] args) {
   
        for (int u = 0; u < 10; u++)

 // 0 < 10 (true); 0 + 1 = 2 (printed); and so on until value offs.
        {
            System.out.println(u);
         }

}
}

Basic Arithmetic


ASSIGNMENT 2: PRINT YOUR CALCULATED VALUE WITH A TEXT:

public class MyFirstProject {

 public static void main(String args[]){
        int a = 5;
        int b = 5;
        int x = a + b;
       
        System.out.println("Your Total sum is: => " + x); 

// Your Total sum is: => 1     
}
}



ASSIGNMENT 1: PRINT YOUR CALCULATED VALUE:
 
public class MyFirstProject {

 public static void main(String args[]){
        int a = 5;
        int b = 5;
        int x = a + b;
       
        System.out.println("x"); // OR;
        System.out.println(a + b);
        System.out.println(a - b);
        System.out.println(a * b);
        System.out.println(a / b);
        System.out.println(a % b); // Remainder (%)
}

}