
Help me in this java question?
Given this MobilePhone class diagram, write out the class in JAVA.
:MobilePhone
——————-
brand : String
model: String
ringTone : String
————
setRingTone() : void
viewDetails () : void
Add 4 constructors to this class :
1) Default constructor, which sets the ringtone to “Happy Birthday”
2) Define a constructor that sets the brand
3 Define a constructor that sets the brand and model
4) Define a constructor that sets the brand, model and ringtone.
How am i to go writing the codes out?
I’m a beginner in Java language.
Is there any other way?
// Save the following class as MobilePhone.java
public class MobilePhone{
private String brand;
private String model;
private String ringTone;
//Constructor with business logic (codings)
public MobilePhone(String brand, String model, String ringTone){
this.brand=brand;
this.model=model;
this.ringTone=ringTone;
}
//Default consturctor
public MobilePhone(){
this(null,null,”Happy Birthday”);
}
//Another overloaded version of the consturctor
public MobilePhone(String brand){
this(brand,null,null);
}
//Another overloaded version of the consturctor
public MobilePhone(String brand, String model){
this(brand,model,null);
}
//Method to set the ringtone
public void setRingTone(String rt){
this.ringTone=ringTone;
}
//Method to print the details on the output stream (i.e.: console)
public void viewDetails(){
System.out.println(“Brand: “+brand);
System.out.println(“Model: “+brand);
System.out.println(“Ring Tone: “+brand);
}
}
//Use the following program to test the above code:
class MobileDemo{
public static void main(String args[]){
MobilePhone p1=new MobilePhone();
MobilePhone p2=new MobilePhone(“Nokia”);
MobilePhone p3=new MobilePhone(“Motorola”, “C155″);
MobilePhone p4=new MobilePhone(“Samsung”, “X640″, “Hello is it me”);
p1.viewDetails(); System.out.println();
p2.viewDetails(); System.out.println();
p3.viewDetails(); System.out.println();
p4.viewDetails(); System.out.println();
}
}
Happy Birthday Song
|
|
SpongeBob SquarePants: The Best Day Ever $5.48 It was only a matter of time before SpongeBob Squarepants became a star big enough to pull off a concept album. Where so many other megawatt celebrities, be they living and land-based or fictional and sea-dwelling, can get all high-minded and grand when cobbling together a theme for their music, though, our man Sponge proves he’s as humble and porous as ever on The Best Day Ever, a 26-track bonanz… |
|
|
Happy Birthday Baby $8.46 … |
|
|
Happy Birthday to You (Vocal Ringtone) $0.89 … |
|
|
Frankie the Fish $29.98 You know Frankie the Fish for that famous Filet O’ Fish commercial that cracked you up to tears! Now you can own Frankie and have him serenade you. Hang him up in the living room, or anywhere guests come to visit to impress them with Franky’s synchromotion mouth and moving tail that will get everyone dancing along to the hilarious and addicting song! Franky the Fish measures 14.5″ x 7″ x 4″ and re… |
Related Articles
No user responded in this post
Leave A Reply