Java Code - Class 1 and Class 2

//Main Class
public class Main {

    public static void main(String[] args) {
        CalculatorClass c1 = new CalculatorClass();
        double tempValue =  c1.printByteValue(1,"SS","bb",'s');
        System.out.println(tempValue);
        CalculatorClass c2 = new CalculatorClass();
        c2.printByteValue(2,"SS","bb",'s');

        CalculatorClass.printInteger();
        System.out.println(CalculatorClass.byteValue);
    }
}

 

//Calculator Class


public class CalculatorClass {

    public static byte byteValue = 20;

    private short shortValue = 2432;
    private int intValue = 31241242;
    private long longValue = 32;
    private double interestValue = 0.10;
    private char charValue = 'S';
    private String StrValue = "asdfasf";


    public double printByteValue(int param1,String param2 , String Param3 ,char param4) {
        System.out.println(param2 + Param3 + param4);
        System.out.println('R');

        double tempValue = (param1 * interestValue) / 100;
        return tempValue;
    }

    public static void printInteger(){
        System.out.println("Static");
        System.out.println(byteValue);
    }

}

Java Code - Class 3

//main method

 

public class main {
    public static void main(String[] args) {

        TireClass tireClass = new TireClass();
        Accl a2  = new Accl();

        AccelarationClass a1 = new AccelarationClass();

        double tirePressure = a1.TirePressureIncreasesWhenAccerlated(tireClass, a2);
        System.out.println(tirePressure);
    }
}

//AccelarationClass method

 

public class AccelarationClass {

    public double TirePressureIncreasesWhenAccerlated(TireClass tclass, Accl a){
        double CurrentTirePressure = tclass.returnTirePressure() * a.returnSpeed();
        System.out.println(tclass.returnTirePressure() * a.returnAirSpeed());
        return CurrentTirePressure;
    }
}

//Accl methods

 

public class Accl {
    private int Speed = 30;

    public int returnSpeed(){
        return Speed;
    }

    public int returnAirSpeed(){
        return 35;
    }

}

//TireClass methods

 

public class TireClass {

    private double pressureTire1 = 33.6;
    private double pressureTire2 = 33.6;
    private double pressureTire3 = 33.6;
    private double pressureTire4 = 33.6;

    public double returnTirePressure(){
        return pressureTire1;
    }
}

first program

public class CalculatorClass {

    public static byte byteValue = 20;
    private short shortValue = 2432;
    private int intValue = 31241242;
    private long longValue = 32;
    private double interestValue = 0.10;
    private char charValue = 'S';
    public String StrValue = "Bharath";


    public double printByteValue(int param1) {
//        double tempValue = (param1 * interestValue) / 100;
//        return tempValue;

        return interestValue;
    }

    public void thisFunctionReturnsString(CalculatorClass c1){
        c1.StrValue = "Sarath";
        System.out.println(c1.StrValue);
    }

    public String printString(){
        System.out.println(StrValue);
        return StrValue;
    }

}

public class ReferenceClass {

    public ReferenceClass thisFunctionReturnsString(CalculatorClass calC){
        calC.printString();
        ReferenceClass ref2 = new ReferenceClass();
        return ref2;
    }
}


public class Main {

    public static void main(String[] args) {

      //Calculator class object
      CalculatorClass calClass1 = new CalculatorClass();

     //ReferenceClass object
      ReferenceClass ref = new ReferenceClass();

      //calling function from reference class and passing the calculator object
      ReferenceClass ref2 = ref.thisFunctionReturnsString(calClass1);

      calClass1.thisFunctionReturnsString(calClass1);
      calClass1.printString();
    }
}

Java Code - Class 4

Operators

 

public class OperatorClass {

    public boolean compareTwoString(String str1, String str2){
        if(str1 == str2){
            System.out.println("String Comparision passed");
            return true;
        }else{
            System.out.println("String Comparision Failed");
            return false;
        }
    }

    public boolean compareTwoStringNegative(String str1, String str2){
        if(str1 != str2){
            System.out.println("String Comparision passed");
            return true;
        }else{
            System.out.println("String Comparision Failed");
            return false;
        }
    }

    public boolean compareGreaterThen(int int1, int int2){
        if(int1 > int2){
            System.out.println("integer 1 : " + int1 + " is greater than integer 2: " + int2 );
            return true;
        }else{
            System.out.println("integer 1 : " + int1 + " is lesser than integer 2: " + int2 );
            return false;
        }
    }

    public boolean compareAndOperator(int int1, int int2 , int int3){
        if(int1 > int2 && int1 > int3){
            System.out.println("both comparisions passed" );
            return true;
        }
        else if (int1 > int2 && int1 < int3)
        {
            System.out.println("one comparision failed");
            return false;
        }
        else if (int1 > int2 || int1 < int3)
        {
            System.out.println("one comparision failed");
            return false;
        }
        else
        {
            System.out.println("both comparisions failed");
            return false;
        }
    }

    public void runForLoop(int length){

        for(int i=2; i < 10; i += 2){
            System.out.println("Integer : " + i);
            if(i == 6){
                System.out.println("Integer : " + i);
                break;
            }
        }
    }
}

Assignments

Questions:

1. Create two functions that can read and write to single dimension String array and call them in main method which is present in another class

2. Create two functions that can read and write to Multi dimension Int array and call them in main method which is present in another class

Class 5 Operators and Arrays

public class OperatorClass {

    public boolean compareTwoString(String str1, String str2){
        if(str1 == str2){
            System.out.println("String Comparision passed");
            return true;
        }else{
            System.out.println("String Comparision Failed");
            return false;
        }
    }

    public boolean compareTwoStringNegative(String str1, String str2){
        if(str1 != str2){
            System.out.println("String Comparision passed");
            return true;
        }else{
            System.out.println("String Comparision Failed");
            return false;
        }
    }

    public boolean compareGreaterThen(int int1, int int2){
        if(int1 > int2){
            System.out.println("integer 1 : " + int1 + " is greater than integer 2: " + int2 );
            return true;
        }else{
            System.out.println("integer 1 : " + int1 + " is lesser than integer 2: " + int2 );
            return false;
        }
    }

    public boolean compareAndOperator(int int1, int int2 , int int3){
        if(int1 > int2 && int1 > int3){
            System.out.println("both comparisions passed" );
            return true;
        }
        else if (int1 > int2 && int1 < int3)
        {
            System.out.println("one comparision failed");
            return false;
        }
        else if (int1 > int2 || int1 < int3)
        {
            System.out.println("one comparision failed");
            return false;
        }
        else
        {
            System.out.println("both comparisions failed");
            return false;
        }
    }

    public void runForLoop(int length){

        for(int i=2; i < 10; i += 2){
            System.out.println("Integer : " + i);
            if(i == 6){
                System.out.println("Integer : " + i);
                break;
            }
        }
    }


   public void SwitchCaseStatement(int intMonth){
       System.out.println(intMonth);

       switch(intMonth){
           case 1:
               System.out.println("Month1");
           case 2:
               System.out.println("Month2");
           case 3:
               System.out.println("Month3");
           case 4:
               System.out.println("Month4");
           default:
               System.out.println("Any other Month");

       }
   }

    public void TestD0While(int intCondition){
        while( intCondition < 4){
            System.out.println(intCondition);
            intCondition++;
        }

        do{
            intCondition++;
            System.out.println(intCondition);
        }while( intCondition < 4);
    }

public class Arrays {

    int[] intArray= { 21,22,23,24};

    String[] strArray = {"RAM","SITA","LAX"};

    int intTwoDimensionArray[][] = {{1,2,3},{1,2,3}};

    int[] intArrayOne = new int[3];


    public void readIntArrayForCurrentArray(){
        for (int i=0;i < intArray.length; i++){
            System.out.println(intArray[i]);
        }
    }

    public void writeTOArray(){
        intArrayOne[0] = 35;
        intArrayOne[1] = 45;
        intArrayOne[2] = 83;
    }

    public void readIntArrayForArray2(){
        for (int i=0;i < intArrayOne.length; i++){
            System.out.println(intArrayOne[i]);
        }
    }
}

Class 6 - Inheritence

//Parent Class 

 

public class ParentClass {
    //Car class this parent class

    public final int intValue = 2;

    public void CarNeedsTire(){
        System.out.println("CarNeedsTireClass");
    }

    public void carNeedsEngine(){
        System.out.println("carNeedsEngine");
    }

    public void carNeedsEngine(int parameter){
        System.out.println("carNeedsEngine" + parameter);
    }

    public void carNeedsEngine(String parameter){
        System.out.println("carNeedsEngine" + parameter);
    }

    public void carNeedsDoors(){
        System.out.println("carNeedsDoors");
    }

    protected void carNeedsFilters(){
        System.out.println("carNeedsFilters");
    }

    private void thisCarColor(){
        System.out.println("Red");
    }
}

// Child Class - Extends the Parent Class

 

public class childClass extends ParentClass {

    public void callParentClasses(){
        carNeedsDoors();
        carNeedsEngine();
        carNeedsEngine();
        carNeedsFilters();
    }

    public void CarNeedsTire(){
        System.out.println("carNeedsChild");
    }

}

// Main Class - Calling an Inherited Parent Class and the Child class

 

public class MainMethod {

    public static void main(String[] args) {
        ParentClass p = new ParentClass();

        ParentClass p1 = new childClass();

        childClass c1 = new childClass();

        p.CarNeedsTire();
        p1.CarNeedsTire();
        c1.CarNeedsTire();

    }
}

 

Class 6 - Interface

// Interface - Represent a contract that needs to be followed by the implementing class

 

public interface BankAccountManagement {

    public void CreateAccount();
    public void LoginToAccountMethod();
    public void LogOutAccountMethod();
}

 

// Implementing an interface

 

public class AccountManagement implements BankAccountManagement {
    @Override
    public void CreateAccount() {
        System.out.println("Create Account Implementation");
    }

    @Override
    public void LoginToAccountMethod() {
        System.out.println("Login To Account Method Implementation");
    }

    @Override
    public void LogOutAccountMethod() {
        System.out.println("LogOut Account Method Implementation");
    }
}

 

// Calling an Interface

 

public class MainMethod {

    public static void main(String[] args) {
     BankAccountManagement bankAccountManagement = new AccountManagement();
     AccountManagement accountManagement = new AccountManagement();
    }
}

Class 6 - Abstract Class

// Abstract Class

public abstract class AbstractClassToBeExtended {

    public void implementedMethod(){
        System.out.println("Method already implemented");
    }

    public abstract void methodToBeImplemented();
}

// Abstract Class Implementation

 

public class AbstractClassImplementation extends AbstractClassToBeExtended {

    @Override
    public void methodToBeImplemented() {
        System.out.println("Method Implemented in the abstact Class");
    }
}

// Main Method

 

public class MainMethod {

    public static void main(String[] args) {
     AbstractClassToBeExtended abstractClassToBeExtended = new AbstractClassImplementation();
     AbstractClassImplementation abstractClassImplementation = new AbstractClassImplementation();
    }
}

Print Print | Sitemap
© 2016 Automation Learn. All rights reserved.