hi guys

im an IT student an i have a very important assignment to return in 2 days time and im stuck with it i dnt know what to do. the assignment is as follows.

Write a complete class definition in java for the following.your answer must include at least 2 constructors, a finalizer, a display() method, a menu that allows to test all functions of the class and a main().

Class: MobilePhone

Attributes:ownNumber, calledNumber, status(busy/free)

Methods: dial(), call(), redial(), disconnect(), cancel(), receiveCall(), ValidatePhoneNo().


im counting on you guys your solution will serve me as a very good reference.my book on java is coming only next week i hope i get an answer from you soon.......

thanks a lot.....

Recommended Answers

All 7 Replies

Sory I am not a expert in java, i am only an expert in Vb.net hope some one helps you!!!!!!!!!!!!!!!!!!!

I certainly hope you don't expect us to write the code for you. Not only is it dishonest (we call it "cheating" around here), but there's no point. It's highly doubtful that you'll learn much if anything from it (don't argue, we've heard it before). Maybe you should have paid better attention in class, asked your professor for help, and gotten a book sooner.

On the other hand, if you were to post some incorrect or slightly incomplete code with a description of what's wrong, I'm sure a lot of members would be much more willing to help you get over a couple problems... ;)

hi guys

im an IT student an i have a very important assignment to return in 2 days time and im stuck with it i dnt know what to do. the assignment is as follows.

Write a complete class definition in java for the following.your answer must include at least 2 constructors, a finalizer, a display() method, a menu that allows to test all functions of the class and a main().

Class: MobilePhone

Attributes:ownNumber, calledNumber, status(busy/free)

Methods: dial(), call(), redial(), disconnect(), cancel(), receiveCall(), ValidatePhoneNo().


im counting on you guys your solution will serve me as a very good reference.my book on java is coming only next week i hope i get an answer from you soon.......

thanks a lot.....


im sending you the whole program which i have written but there are lots of missing codes in it plz help me out. example for the method call() what code to write to show the process of calling?

here is the program


import java.io.*;
public class MobilePhone

{
private int ownNumber;
private int calledNumber;
private boolean status; // either busy or free

public MobilePhone()throws IOException
{
BufferedReader r = new BufferedReader(InputStreamReader(System.in));
System.out.println(" Phone details")
System.out.print(" input your own phone number:");
int ownNumber = Integer.parseInt(r.readLine());
System.out.print("Input the number to call:");
int calledNumber = Integer.parseInt(r.readLine());
Boolean status = free;
}
Public void setData()throws IOException

{
BufferedReader r = new BufferedReader(InputStreamReader(System.in));
System.out.println(" Phone details")
System.out.print(" input your own phone number:");
int ownNumber = Integer.parseInt(r.readLine());
System.out.print("Input the number to call:");
int calledNumber = Integer.parseInt(r.readLine());
Boolean status = free;
}

public MobilePhone (int ownNumber, ine calledNumber) throws IOException
{
This.ownNumber = ownNumber;
This.calledNumber = calledNumber;
Boolean status = free;
}

Public void dial()throws IOException
{
BufferedReader r = new BufferedReader(InputStreamReader(System.in));
System.out.println(“Input a number to dial:”);
// there are some codes which need to be added as a user can just dial a number and dnt do anything else or to make a call,disconnect or cancel also.

}

Public void call(0throws IOException

{

Dial();


If(status==busy)
System.out.println(“number busy”);

// some code needed here

Else
System.out.println(“Connecting to number..”);
System.out.println(“call1..”);
Status = busy;

}

Public void redial()throws IOException
{
Call();

// code needed

If(status = = free)
System.out.println(“please wait….”);
System.out.println(“redialing..”);
}

Public void disconnect()throws IOException
{
Call();
Redial();
System.out.println(“Disconnecting…”);

}


Public void receive()throws IOException
{

If (status = = free)

// I really dnt know how to explain it in codes

}

Public void ValidatePhoneNo()throws IOException
{
If (calledNumber = = String)
System.out.println(“Invalid number..”);
// above code is for checking if number input is in characters then error message.
Int len = calledNumber.length
If (len>7 || len<7)
System.out.println(“Invalid phone number..”);

// the part above is to check if it has 7 digits only. I know its not good plz help me out im lost completely.
}


Note:Its been barely 2 months since im learning this language usually I do well in class but this assignment is a little tough because there is no calculations in it and I dnt know how to code these actions.

I wanted to add another method to calculate call duration when a call is being made but I dnt know how to implement it. Ive done some search I know we have to use timemillis to calsulate in milliseconds but im stuck for now. please correct my mistakes and add the codes necessary that are missing.

I will write my main and menu later after I have receive your solution which I must study to be able to continue.please sir help me out.

Number one recommendation: run your code through a compiler. There's a few really simple bugs in it. Like missing semicolons, inconsistent capitalization, and using = = instead of == . Anyways, moving on...

public MobilePhone() throws IOException
  {
    BufferedReader r = new BufferedReader(InputStreamReader(System.in));
    System.out.println(" Phone details")
      System.out.print(" input your own phone number:");
    int ownNumber = Integer.parseInt(r.readLine());
    System.out.print("Input the number to call:");
    int calledNumber = Integer.parseInt(r.readLine());
    Boolean status = free;
  }

You're missing a semicolon after the first System.out.println, and you're trying to declare status locally (and Boolean shouldn't be capitalized, but in this case it should just be removed). If you're using Java 1.5 or later, check out the java.util.Scanner class. It makes input from the console a lot easier, where you can do things like this:

Scanner consoleInput = new Scanner(System.in);
int anInt = consoleInput.nextInt();
String aWord = consoleInput.next();
String aLine = consoleInput.nextLine();

setData is exactly the same as the empty constructor. You could just have the constructor call setData to avoid duplicated code.

Why do you set the number to call in setData when you're just going to prompt for it in dial? Choose one (probably dial). And then dial needs to try connecting and set the status accordingly. That's logic you'll have to figure out.

In call, when you have if(status == busy) , are you checking if the current phone or the dialed one is busy? Depending on your requirements, there might be a need for both. If the current phone is busy, you shouldn't even call dial. To check if the other line is busy, you could have dial return a boolean.

For call, you might want to have it take a phone number as a parameter so you know what number you're calling. That way you can save the last dialed number for when you implement redial (and redial would mainly be call(lastNumberDialed) ).

Receive needs to check if the current line is busy or not. If it is, then you have to tell the caller that somehow (I'd use a boolean again here, and return false). Otherwise, you should set it to busy and tell the caller that the call has been accepted (e.g. return true). You might want to somehow record the number of the caller as well (probably as a parameter) but I think this isn't required for your assignment.

In ValidatePhoneNo, you don't need to check if calledNumber is a String. Since you declared it as an int, it'll be an int. and checking the phone length can be done as if(len != 7) rather than using > || <. If you just want to make sure that it's a 7-digit number, you can just check if String.valueOf(calledNumber).length == 7 rather than the syntactically wrong thing you were doing. And the function should probably return whether the number is valid rather than just printing out the result.

I certainly hope you don't expect us to write the code for you. Not only is it dishonest (we call it "cheating" around here), but there's no point. It's highly doubtful that you'll learn much if anything from it (don't argue, we've heard it before). Maybe you should have paid better attention in class, asked your professor for help, and gotten a book sooner.

On the other hand, if you were to post some incorrect or slightly incomplete code with a description of what's wrong, I'm sure a lot of members would be much more willing to help you get over a couple problems... ;)

im sending you the whole program which i have written but there are lots of missing codes in it plz help me out. example for the method call() what code to write to show the process of calling?

here is the program


import java.io.*;
public class MobilePhone

{
private int ownNumber;
private int calledNumber;
private boolean status; // either busy or free

public MobilePhone()throws IOException
{
BufferedReader r = new BufferedReader(InputStreamReader(System.in));
System.out.println(" Phone details")
System.out.print(" input your own phone number:");
int ownNumber = Integer.parseInt(r.readLine());
System.out.print("Input the number to call:");
int calledNumber = Integer.parseInt(r.readLine());
Boolean status = free;
}
Public void setData()throws IOException

{
BufferedReader r = new BufferedReader(InputStreamReader(System.in));
System.out.println(" Phone details")
System.out.print(" input your own phone number:");
int ownNumber = Integer.parseInt(r.readLine());
System.out.print("Input the number to call:");
int calledNumber = Integer.parseInt(r.readLine());
Boolean status = free;
}

public MobilePhone (int ownNumber, ine calledNumber) throws IOException
{
This.ownNumber = ownNumber;
This.calledNumber = calledNumber;
Boolean status = free;
}

Public void dial()throws IOException
{
BufferedReader r = new BufferedReader(InputStreamReader(System.in));
System.out.println(“Input a number to dial:”);
// there are some codes which need to be added as a user can just dial a number and dnt do anything else or to make a call,disconnect or cancel also.

}

Public void call(0throws IOException

{

Dial();


If(status==busy)
System.out.println(“number busy”);

// some code needed here

Else
System.out.println(“Connecting to number..”);
System.out.println(“call1..”);
Status = busy;

}

Public void redial()throws IOException
{
Call();

// code needed

If(status = = free)
System.out.println(“please wait….”);
System.out.println(“redialing..”);
}

Public void disconnect()throws IOException
{
Call();
Redial();
System.out.println(“Disconnecting…”);

}


Public void receive()throws IOException
{

If (status = = free)

// I really dnt know how to explain it in codes

}

Public void ValidatePhoneNo()throws IOException
{
If (calledNumber = = String)
System.out.println(“Invalid number..”);
// above code is for checking if number input is in characters then error message.
Int len = calledNumber.length
If (len>7 || len<7)
System.out.println(“Invalid phone number..”);

// the part above is to check if it has 7 digits only. I know its not good plz help me out im lost completely.
}


Note:Its been barely 2 months since im learning this language usually I do well in class but this assignment is a little tough because there is no calculations in it and I dnt know how to code these actions.

I wanted to add another method to calculate call duration when a call is being made but I dnt know how to implement it. Ive done some search I know we have to use timemillis to calsulate in milliseconds but im stuck for now. please correct my mistakes and add the codes necessary that are missing.

I will write my main and menu later after I have receive your solution which I must study to be able to continue.please sir help me out.

Ok, I'll put this bluntly: I'm not going to post any code here. You need to figure it out on your own. I gave you a list of things you need to do as well as several suggestions for how to continue after that. I will not do your work for you. I don't have time to do your work. You can't afford to pay me to do your work. You'll need to do your work. Did you even read my second post?

Be honest Be truthful and be thankful when looking for any help from anyone.

Please do read the Infraction second last reply that gonna help you a lot and will surely teach you a lot .

Just give it a try madam

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.