Answer to Question #166411 in Java | JSP | JSF for Chandra sena reddy

Question #166411

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

Input

  • The first line of input contains a string brand
  • The second line of input contains a string ram
  • The third line of input contains a number battery
  • The fourth line of input contains a string song
  • The fifth line of input contains a boolean isOnCall

Output

  • The first line of output is a string containing
  • battery before charging, as shown in the sample outputs
  • The second line of output is a string based on
  • battery, as shown in the sample outputs
  • The third line of output is a string containing
  • song, as shown in the sample outputs
  • The fourth line of output is a string "Music stopped"
  • The fifth line of output is a string "No ongoing call to end" or "Call Ended"
  • The sixth line of output is a string "Calling..."
  • The seventh line of output is a string "Call Ended"

Constraints

0 <=

battery <= 100


1
Expert's answer
2021-02-26T16:16:51-0500
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();

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog