Merge pull request #2 from SowinskiBraeden/changes_trishaan
Changes trishaan
This commit is contained in:
6 files changed
+125
-17
No files matched your search
@@ -10,16 +10,22 @@ package ca.bcit.comp2522.lab03;
|
|||||||
* @version 1.0.0
|
* @version 1.0.0
|
||||||
*/
|
*/
|
||||||
public abstract class IDevice {
|
public abstract class IDevice {
|
||||||
|
private final static int MIN_PURPOSE_CHARACTER = 1;
|
||||||
|
private final static int MAX_PURPOSE_CHARACTER = 255;
|
||||||
|
|
||||||
private final String purpose;
|
private final String purpose;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* IDevice constructor
|
* IDevice constructor
|
||||||
|
*
|
||||||
* @param purpose of IDevice
|
* @param purpose of IDevice
|
||||||
*/
|
*/
|
||||||
public IDevice(final String purpose) {
|
public IDevice(final String purpose)
|
||||||
|
{
|
||||||
|
|
||||||
// TODO: validate String inputs
|
stringValidator(purpose,
|
||||||
|
MIN_PURPOSE_CHARACTER,
|
||||||
|
MAX_PURPOSE_CHARACTER);
|
||||||
this.purpose = purpose;
|
this.purpose = purpose;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -30,6 +36,7 @@ public abstract class IDevice {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* getPurpose of IDevice
|
* getPurpose of IDevice
|
||||||
|
*
|
||||||
* @return purpose of IDevice
|
* @return purpose of IDevice
|
||||||
*/
|
*/
|
||||||
public String getPurpose() {
|
public String getPurpose() {
|
||||||
@@ -38,10 +45,42 @@ public abstract class IDevice {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* toString returns details of IDevice
|
* toString returns details of IDevice
|
||||||
|
*
|
||||||
* @return purpose of IDevice
|
* @return purpose of IDevice
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return this.purpose;
|
return this.purpose;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* stringValidator checks if the string is within character
|
||||||
|
* bounds and if it is blank, null or empty.
|
||||||
|
* @param toBeValidated passes the string that needs to be validated.
|
||||||
|
* @param maxCharacterCount passes the maximum number of characters that can be accepted
|
||||||
|
* as an integer.
|
||||||
|
* @param minCharacterCount passes the minimum number of characters that can be accepted
|
||||||
|
* as an integer.
|
||||||
|
* */
|
||||||
|
public void stringValidator(final String toBeValidated,
|
||||||
|
final int minCharacterCount,
|
||||||
|
final int maxCharacterCount)
|
||||||
|
throws IllegalArgumentException
|
||||||
|
{
|
||||||
|
|
||||||
|
if (toBeValidated == null) {
|
||||||
|
throw new IllegalArgumentException("Value cannot be null");
|
||||||
}
|
}
|
||||||
|
if (toBeValidated.isEmpty()) {
|
||||||
|
throw new IllegalArgumentException("Value cannot be empty");
|
||||||
|
}
|
||||||
|
if (toBeValidated.isBlank()) {
|
||||||
|
throw new IllegalArgumentException("Value cannot be blank");
|
||||||
|
}
|
||||||
|
if (toBeValidated.length() < minCharacterCount || toBeValidated.length() > maxCharacterCount) {
|
||||||
|
throw new IllegalArgumentException("Value length must be between"
|
||||||
|
+ minCharacterCount + "and " + maxCharacterCount + " characters");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -11,6 +11,9 @@ package ca.bcit.comp2522.lab03;
|
|||||||
*/
|
*/
|
||||||
public class IPad extends IDevice {
|
public class IPad extends IDevice {
|
||||||
|
|
||||||
|
private final static int MAX_OSVERSION_CHARACTERS = 10;
|
||||||
|
private final static int MIN_OSVERSION_CHARACTERS = 1;
|
||||||
|
|
||||||
private final boolean hasCase;
|
private final boolean hasCase;
|
||||||
private final String OSVersion;
|
private final String OSVersion;
|
||||||
|
|
||||||
@@ -24,9 +27,10 @@ public class IPad extends IDevice {
|
|||||||
final String OSVersion
|
final String OSVersion
|
||||||
) {
|
) {
|
||||||
super("learning");
|
super("learning");
|
||||||
|
|
||||||
// TODO: validate String inputs
|
|
||||||
this.hasCase = hasCase;
|
this.hasCase = hasCase;
|
||||||
|
stringValidator(OSVersion,
|
||||||
|
MIN_OSVERSION_CHARACTERS,
|
||||||
|
MAX_OSVERSION_CHARACTERS);
|
||||||
this.OSVersion = OSVersion;
|
this.OSVersion = OSVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,9 @@ package ca.bcit.comp2522.lab03;
|
|||||||
* @version 1.0.0
|
* @version 1.0.0
|
||||||
*/
|
*/
|
||||||
public class IPhone extends IDevice {
|
public class IPhone extends IDevice {
|
||||||
|
private static final int MIN_CAREER_CHARACTERS = 3;
|
||||||
|
private static final int MAX_CAREER_CHARACTERS = 15;
|
||||||
|
private static final double NO_MINUTES_REMAINING = 0.0;
|
||||||
private static final int IPHONE_HASH = 11;
|
private static final int IPHONE_HASH = 11;
|
||||||
private static final int IPHONE_HASH_CODE = 101;
|
private static final int IPHONE_HASH_CODE = 101;
|
||||||
|
|
||||||
@@ -24,12 +26,16 @@ public class IPhone extends IDevice {
|
|||||||
*/
|
*/
|
||||||
public IPhone(
|
public IPhone(
|
||||||
final double remainingPhonePlanMinutes,
|
final double remainingPhonePlanMinutes,
|
||||||
final String carrier
|
final String carrier)
|
||||||
) {
|
{
|
||||||
super("talking");
|
super("talking");
|
||||||
|
|
||||||
// TODO: validate String inputs, possibly other inputs too
|
minutesValidator(remainingPhonePlanMinutes);
|
||||||
this.remainingPhonePlanMinutes = remainingPhonePlanMinutes;
|
this.remainingPhonePlanMinutes = remainingPhonePlanMinutes;
|
||||||
|
|
||||||
|
stringValidator(carrier,
|
||||||
|
MIN_CAREER_CHARACTERS,
|
||||||
|
MAX_CAREER_CHARACTERS);
|
||||||
this.carrier = carrier;
|
this.carrier = carrier;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,8 +73,17 @@ public class IPhone extends IDevice {
|
|||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
|
||||||
// TODO: convert to StringBuilder, refer to IPad
|
final StringBuilder iphoneDetails;
|
||||||
return super.toString() + " " + this.remainingPhonePlanMinutes + " " + this.carrier;
|
|
||||||
|
iphoneDetails = new StringBuilder();
|
||||||
|
|
||||||
|
iphoneDetails.append(super.toString());
|
||||||
|
iphoneDetails.append(" ");
|
||||||
|
iphoneDetails.append(this.remainingPhonePlanMinutes);
|
||||||
|
iphoneDetails.append(" ");
|
||||||
|
iphoneDetails.append(this.carrier);
|
||||||
|
|
||||||
|
return iphoneDetails.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -112,4 +127,14 @@ public class IPhone extends IDevice {
|
|||||||
return hash;
|
return hash;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void minutesValidator(final double mins)
|
||||||
|
throws IllegalArgumentException
|
||||||
|
{
|
||||||
|
if(mins < NO_MINUTES_REMAINING)
|
||||||
|
{
|
||||||
|
throw new IllegalArgumentException("Minutes cannot be negative");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -10,8 +10,9 @@ package ca.bcit.comp2522.lab03;
|
|||||||
* @version 1.0.0
|
* @version 1.0.0
|
||||||
*/
|
*/
|
||||||
public class IPhone16 extends IPhone {
|
public class IPhone16 extends IPhone {
|
||||||
|
private static final int BASE_VARIANT_MEMORY = 128;
|
||||||
private static final int IPHONE_HASH_WITH_HIGH_RES = 103;
|
private static final int IPHONE_HASH_WITH_HIGH_RES = 103;
|
||||||
|
private static final int IS_A_MULTIPLE_OF_BASE_VARIANT = 0;
|
||||||
|
|
||||||
final boolean highResolutionCamera;
|
final boolean highResolutionCamera;
|
||||||
final int memoryGB;
|
final int memoryGB;
|
||||||
@@ -31,9 +32,9 @@ public class IPhone16 extends IPhone {
|
|||||||
) {
|
) {
|
||||||
super(remainingPhonePlanMinutes, carrier);
|
super(remainingPhonePlanMinutes, carrier);
|
||||||
|
|
||||||
// TODO: validate memoryGB input?
|
|
||||||
|
|
||||||
this.highResolutionCamera = highResolutionCamera;
|
this.highResolutionCamera = highResolutionCamera;
|
||||||
|
|
||||||
|
memoryGBValidator(memoryGB);
|
||||||
this.memoryGB = memoryGB;
|
this.memoryGB = memoryGB;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,4 +118,18 @@ public class IPhone16 extends IPhone {
|
|||||||
return hash;
|
return hash;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* memoryGBValidator makes sure the right memory storage is assigned
|
||||||
|
* since it needs to be a multiple of 128.
|
||||||
|
* @param memoryGB passes the value of the memory to the method.
|
||||||
|
* */
|
||||||
|
public void memoryGBValidator(final int memoryGB)
|
||||||
|
throws IllegalArgumentException
|
||||||
|
{
|
||||||
|
if (memoryGB % BASE_VARIANT_MEMORY != IS_A_MULTIPLE_OF_BASE_VARIANT)
|
||||||
|
{
|
||||||
|
throw new IllegalArgumentException("Invalid Memory value (GB)");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -11,6 +11,7 @@ package ca.bcit.comp2522.lab03;
|
|||||||
*/
|
*/
|
||||||
public class IPod extends IDevice {
|
public class IPod extends IDevice {
|
||||||
|
|
||||||
|
private static final int NO_SONGS = 0;
|
||||||
private static final int IPOD_HASH = 7;
|
private static final int IPOD_HASH = 7;
|
||||||
private static final int IPOD_HASH_CODE = 97;
|
private static final int IPOD_HASH_CODE = 97;
|
||||||
|
|
||||||
@@ -28,9 +29,9 @@ public class IPod extends IDevice {
|
|||||||
) {
|
) {
|
||||||
super("music");
|
super("music");
|
||||||
|
|
||||||
// TODO: validate numberOfSongs input
|
numberOfSongsValidator(numberOfSongs);
|
||||||
|
|
||||||
this.numberOfSongs = numberOfSongs;
|
this.numberOfSongs = numberOfSongs;
|
||||||
|
|
||||||
this.maxVolumeDecibels = maxVolumeDecibels;
|
this.maxVolumeDecibels = maxVolumeDecibels;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,8 +69,17 @@ public class IPod extends IDevice {
|
|||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
|
||||||
// TODO: change this to StringBuilder, refer to IPad
|
final StringBuilder ipodDetails;
|
||||||
return super.toString() + " " + this.numberOfSongs + " " + this.maxVolumeDecibels;
|
|
||||||
|
ipodDetails = new StringBuilder();
|
||||||
|
|
||||||
|
ipodDetails.append(super.toString());
|
||||||
|
ipodDetails.append(" ");
|
||||||
|
ipodDetails.append(this.numberOfSongs);
|
||||||
|
ipodDetails.append(" ");
|
||||||
|
ipodDetails.append(this.maxVolumeDecibels);
|
||||||
|
|
||||||
|
return ipodDetails.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -113,4 +123,18 @@ public class IPod extends IDevice {
|
|||||||
return hash;
|
return hash;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* numberOfSongsValidator makes sure the number of songs being
|
||||||
|
* passed are not negative.
|
||||||
|
* @param songNumber passes the value of the number of songs.
|
||||||
|
* */
|
||||||
|
public void numberOfSongsValidator(final int songNumber)
|
||||||
|
throws IllegalArgumentException
|
||||||
|
{
|
||||||
|
if(songNumber < NO_SONGS)
|
||||||
|
{
|
||||||
|
throw new IllegalArgumentException("Number of songs cannot be less than 0");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -69,6 +69,7 @@ public class Main {
|
|||||||
final IPhone iphone1;
|
final IPhone iphone1;
|
||||||
final IPhone iphone2;
|
final IPhone iphone2;
|
||||||
final IPhone iphone3;
|
final IPhone iphone3;
|
||||||
|
|
||||||
iphone1 = new IPhone(120.0, "Verizon"); // 120 minutes, carrier Verizon
|
iphone1 = new IPhone(120.0, "Verizon"); // 120 minutes, carrier Verizon
|
||||||
iphone2 = new IPhone(180.0, "T-Mobile"); // 180 minutes, carrier T-Mobile
|
iphone2 = new IPhone(180.0, "T-Mobile"); // 180 minutes, carrier T-Mobile
|
||||||
iphone3 = new IPhone(120.0, "AT&T"); // 120 minutes, carrier AT&T
|
iphone3 = new IPhone(120.0, "AT&T"); // 120 minutes, carrier AT&T
|
||||||
|
|||||||
Reference in new issue
Block a user