Lab 7

The objective of the lab is to learn how to program android application using java.eclipse (Android SDK)

 

Lab6

This lab is basically create a program that will polymorphically process an array of Movable by calling each of the interface methods.

Code:

package Lab6;

public class Car implements Movable {

@Override
public void moveForward() {
System.out.println(“Car drives forward”);

}

@Override
public void movebackward() {
System.out.println(“Car drives backward”);

}

@Override
public void stop() {
System.out.println(“Car parked”);

}

@Override
public void moveleft() {
System.out.println(“Car turns left”);

}

@Override
public void moveright() {
System.out.println(“Car turns right”);
}

@Override
public void moveBackward() {

}

@Override
public void moveLeft() {

}

@Override
public void moveRight() {

}

}

package Lab6;

public interface Movable {
public void moveForward();
public void moveBackward();
public void stop();
public void moveLeft();
public void moveRight();
void moveright();
void moveleft();
void movebackward();
}
package Lab6;

public class MovableApp {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Movable[] myMovables = new Movable[3];
myMovables[0] = new Plane();
myMovables[1] = new Car();
myMovables[2] = new Ship();

for (Movable m: myMovables){
m.moveForward();
m.movebackward();
m.stop();
m.moveleft();
m.moveright();
System.out.println(“————————-“);
}
}
}
package Lab6;

public class Plane implements Movable {

@Override
public void moveForward() {
System.out.println(“Plane flying forward”);

}

@Override
public void movebackward() {
System.out.println(“Plane taxiing backward”);

}

@Override
public void stop() {
System.out.println(“Plane landen”);

}

@Override
public void moveleft() {
System.out.println(“Plane flying left”);

}

@Override
public void moveright() {
System.out.println(“Plane flying right”);
}

@Override
public void moveBackward() {

}

@Override
public void moveLeft() {

}

@Override
public void moveRight() {

}

}
package Lab6;

public class Ship implements Movable {

@Override
public void moveForward() {
System.out.println(“Ship navigates forward”);

}

@Override
public void movebackward() {
System.out.println(“Ship navigates backward”);

}

@Override
public void stop() {
System.out.println(“Ship docked”);

}

@Override
public void moveleft() {
System.out.println(“Ship navigates left”);

}

@Override
public void moveright() {
System.out.println(“Ship navigates right”);
}

@Override
public void moveBackward() {

}

@Override
public void moveLeft() {

}

@Override
public void moveRight() {

}

}

Screen Sht

lab4

The objective of this lab is to learn about inheritance in Java as well as the proper usage of abstract classes and methods. The program has to be able to follow the hierarchy below through the use of inheritance.
Code

package v2;

public class Android extends SmartPhone{

	private String deviceType;

	public Android(){
		deviceType="Android";	
		}

	public void setDeviceType(String value){
		deviceType=value;
	}

	@Override
	public String getDeviceType(){
		return super.getDeviceType()+"->"+deviceType;
	}
}
package v2;

public class iPhone extends SmartPhone{

	private String deviceType;

	public iPhone(){
		deviceType="iPhone";	
		}

	public void setDeviceType(String value){
		deviceType=value;
	}

	@Override
	public String getDeviceType(){
		return super.getDeviceType()+"->"+deviceType;
	}
}
package v2;

public class MobileDevice{

	public String deviceType;

	public MobileDevice(){
		deviceType="Mobile Device";	
		}

	public void setDeviceType(String value){
		deviceType=value;
	}

	public String getDeviceType(){
		return deviceType;
	}
}
package v2;

public class MobileDeviceClient{
	public static void main (String [] args){
		MobileDevice myMobileDevice= new MobileDevice();
		SmartPhone mySmartPhone=new SmartPhone();
		iPhone myiPhone=new iPhone();
		Android myAndroid=new Android();
		WindowsPhone myWindowsPhone= new WindowsPhone();
		myWindowsPhone.setDeviceType("WindowsPhone");
		System.out.println(myMobileDevice.getDeviceType());
		System.out.println(mySmartPhone.getDeviceType());
		System.out.println(myiPhone.getDeviceType());
		System.out.println(myAndroid.getDeviceType());
		System.out.println(myWindowsPhone.getDeviceType());
	}
}
package v2;

public class SmartPhone extends MobileDevice{

	private String deviceType;

	public SmartPhone(){
		deviceType="Smart Phone";	
		}

	public void setDeviceType(String value){
		deviceType=value;
	}

	@Override
	public String getDeviceType(){
		return super.getDeviceType()+"->"+deviceType;
	}
}

package v2;

public class WindowsPhone extends SmartPhone{

	private String deviceType;

	public WindowsPhone(){
		deviceType="WindowsPhone";	
		}

	public void setDeviceType(String value){
		deviceType=value;
	}

	@Override
	public String getDeviceType(){
		return super.getDeviceType()+"->"+deviceType;
	}
}

Screen sht

Lab5

The objective of this lab is to learn about inheritance in Java as well as the proper usage of abstract classes and methods. The program has to be able to follow the hierarchy below through the use of inheritance.

package v22;

public class Android extends Smartphone{

    private String myAndroid = "Android";

    public void setDeviceType(){
        this.myAndroid = "Android";
    }

    public String getDeviceType(){
        return this.myAndroid;
    }

    @Override
    public String toString(){
        return this.myAndroid;
    }

}
package v22;

public class Ipad extends Tablet {

    private String myIpad = "Ipad";

    public void setDeviceType(){
        this.myIpad = "Ipad";
    }

    public String getDeviceType(){
        return this.myIpad;
    }
    @Override
    public String toString(){
        return this.myIpad;
    }

}
package v22;

public abstract class MobileDevice {

    public String mobileDevice = "Mobile Device";

    public abstract void setDeviceType();

    public String getDeviceType(){
        return this.mobileDevice;
    }

    public String toString(){
        return this.mobileDevice;
    }
}
package v22;

public class MobileDeviceClient {

    public static void main (String[] args){

        MobileDevice[] mobileDevices = new MobileDevice[4];

        mobileDevices[0] = new Tablet();
        mobileDevices[1] = new Smartphone();
        mobileDevices[2] = new Ipad();
        mobileDevices[3] = new Android();

        for (MobileDevice m: mobileDevices){
            System.out.println("This device is: " + m.getDeviceType());
        }
    }
}
package v22;

public class Smartphone extends MobileDevice {

    private String mySmartphone = "Smartphone";

    public void setDeviceType(){
        this.mySmartphone = "Smartphone";
    }

    public String getDeviceType(){
        return this.mySmartphone;
    }
    @Override
    public String toString(){
        return this.mySmartphone;
    }

}
package v22;

public class Tablet extends MobileDevice {

    private String myTablet = "Tablet";

    public void setDeviceType(){
        this.myTablet = "Tablet";
    }

    public String getDeviceType(){
        return this.myTablet;
    }

    @Override
    public String toString(){
        return this.myTablet;
    }

}

Screen

Hello world!

This is the first post on your Learning Blog. Edit or delete it, then start blogging!

NOTE: Remember to add appropriate Category and Tags to your posts. This will help your professors and other visitors find the content they are looking for. The Category “Coursework” and the Tags “OpenLab” and “City Tech” have already been applied to this post. Feel free to make changes!