Lab # 5

Description

The main objective for this lab was to create an abstract class followed by a private field and three methods. Once created the classes we had to implement an array of MobileDevice with objects. Furthermore, we had to iterate over the array and for each object and indicate of whether device is a Tablet or a SmartPhone.

 

Codes

MobileDevice

 //Tax, Julio
public class Tablet extends MobileDevice {
	private String deviceType;

	public Tablet() {
		deviceType = "a Tablet";
	}
	@Override
	public String getDeviceType() {
		return deviceType;
	}
	@Override 
	public void setDeviceType() {
		deviceType = "Tablet";
	}
	@Override 
	public String toString() {
		return deviceType;
	}
}

SmartPhone

 

//Tax, Julio
public class Smartphone  extends MobileDevice{

	private String deviceType;
	public Smartphone() {
		deviceType = "SmartPhone";
	}
	@Override
	public String getDeviceType() {
		return deviceType;
	}

	@Override
	public void setDeviceType() {
		deviceType = "SmartPhone";
	}
	@Override
	public String toString() {
		return deviceType;
	}
	}

MobileDeviceApps

//Tax, Julio
public class MobileDeviceApps {

public static void main (String []args) {
	MobileDevice[] mobileDevices = new MobileDevice[4];
	mobileDevices [0] = new Smartphone();
	mobileDevices [1] = new Android();
	mobileDevices [2] = new Tablet();
	mobileDevices [3] = new iPad();

	for ( int x = 0; x
//Tax, Julio
public abstract class MobileDevice {

private String deviceType = "Mobile device";
public abstract void setDeviceType();

public String getDeviceType() {
	return deviceType;
}
@Override 
public String toString() {
	return deviceType;
}
}

iPad

//Tax, Julio
public class iPad extends Tablet {
	private String deviceType;

	public iPad() {
		deviceType = "the new iPad 4th Generation";
	}
	@Override 
	public String getDeviceType() {
		return deviceType;
	}
@Override 
public void setDeviceType() {
	deviceType = "iPad";
}
@Override
public String toString() {
	return deviceType;
}
}

Android

//Tax,Julio
public class Android extends Smartphone  {
	private String deviceType;

	public Android() {
		deviceType= "the new Samsung Galaxy S4";
	}
	@Override
	public String getDeviceType() {
		return deviceType;
	}
	@Override 
	public void setDeviceType() {
		deviceType ="Android";
	}
	@Override 
	public String toString() {
		return deviceType;
	}
}

 

 

 

Screenshots

Lab #4 – Tax, Julio