Mobile
You are given an incomplete
Mobile class.A Mobile object created using the
Mobile class should have the properties like brand, ram, battery, isOnCall, and song.Implement the
Mobile class to initialize the mentioned properties and add the following methods,
MethodDescriptionchargingWhen this method is called, it should set the value of the battery to 100, if the battery is already 100 then log "Mobile Fully Charged" and call removeChargingremoveChargingIt should log "Please remove charging"playMusicIt should log a text with the song, as shown in the sample outputstopMusicIt should log "Music Stopped"makeCallWhen this method is called, it should set the value of the isOnCall to true and log "Calling ..."endCallWhen this method is called, it should log "No ongoing call to end" if isOnCall is false, else log "Call Ended" and set the value of the isOnCall to false
0 <=
battery <= 100
public class Mobile {
private String brand;
private String ram;
private int battery;
private String song;
private boolean isOnCall;
public Mobile() {
}
public Mobile(String brand, String ram, int battery, String song, boolean isOnCall) {
this.brand = brand;
this.ram = ram;
this.battery = battery;
this.song = song;
this.isOnCall = isOnCall;
}
public String getBrand() {
return brand;
}
public void setBrand(String brand) {
this.brand = brand;
}
public String getRam() {
return ram;
}
public void setRam(String ram) {
this.ram = ram;
}
public int getBattery() {
return battery;
}
public void setBattery(int battery) {
if (battery >= 0 && battery <= 100)
this.battery = battery;
}
public String getSong() {
return song;
}
public void setSong(String song) {
this.song = song;
}
public boolean isOnCall() {
return isOnCall;
}
public void setOnCall(boolean isOnCall) {
this.isOnCall = isOnCall;
}
public void descriptioncharging() {
if (battery == 100) {
System.out.println("Mobile Fully Charged");
removeChargingremoveCharging();
} else {
this.battery = 100;
}
}
public void removeChargingremoveCharging() {
System.out.println("Please remove charging");
}
public void playMusicIt() {
System.out.println("Sam Brown:\"Stop\"");
}
public void outputstopMusicIt() {
System.out.println("Music Stopped.");
}
public void makeCallWhen() {
System.out.println("No ongoing call to end");
this.isOnCall = true;
System.out.println("Calling");
}
public void endCallWhen() {
if (isOnCall == false) {
System.out.println("No ongoing call to end");
} else if (isOnCall == true) {
System.out.println("Call Ended");
isOnCall = false;
}
}
@Override
public String toString() {
return "Mobile [brand=" + brand + ", ram=" + ram + ", battery=" + battery + ", song=" + song + ", isOnCall="
+ isOnCall + "]";
}
public static void main(String[] args) {
Mobile mobile = new Mobile();
mobile.setBattery(100);
mobile.descriptioncharging();
mobile.playMusicIt();
mobile.outputstopMusicIt();
mobile.makeCallWhen();
mobile.endCallWhen();
Comments
Leave a comment