How to know that a method has been called and returning value of a method

Hi, everyone! I have two questions. One is about making judgment about whether a method has been called or not; another one is about how to return "String value+newline character+String value" with a return statement.
Here are the two original problems that I tried to solve.
Write a class definition of a class named 'Value' with the following:
a boolean instance variable named 'modified', initialized to false
an integer instance variable named 'val'
a constructor accepting a single paramter whose value is assigned to the instance variable 'val'
a method 'getVal' that returns the current value of the instance variable 'val'
a method 'setVal' that accepts a single parameter, assigns its value to 'val', and sets the 'modified' instance variable to true, and
a boolean method, 'wasModified' that returns true if setVal was ever called.
And I wrote my code this way:
public class Value
boolean modified=false;
int val;
public Value(int x)
{val=x;}
  public int getVal()
  {return val;}
   public void setVal(int y)
    val = y;
    modified = true;
     public boolean wasModified()
      if(val==y&&modified==true)
      return true;
}I tried to let the "wasModified" method know that the "setVal" has been called by writing:
if(val==y&&modified==true)
or
if(x.setVal(y))
I supposed that only when the "setVal" is called, the "modified" variable will be true(it's false by default) and val=y, don't either of this two conditions can prove that the method "setVal" has been called?
I also have some questions about the feedback I got
class Value is public, should be declared in a file named Value.java
public class Value
cannot find symbol
symbol  : variable y
location: class Value
if(val==y&&modified==true)
*^*
*2 errors*
I gave the class a name Value, doesn't that mean the class has been declared in a file named Value.java*?
I have declared the variable y, why the compiler cann't find it? is it because y has been out of scale?
The other problem is:
Write a class named  Book containing:
Two instance variables named  title and  author of type String.
A constructor that accepts two String parameters. The value of the first is used to initialize the value of  title and the value of the second is used to initialize  author .
A method named  toString that accepts no parameters.  toString returns a String consisting of the value of  title , followed by a newline character, followed by the value of  author .
And this is my response:
public class Book
String title;
String author;
  public Book(String x, String y)
   { title=x; author=y; }
   public String toString()
   {return title;
    return author;
}I want to know that is it ok to have two return statements in a single method? Because when I add the return author; to the method toString, the compiler returns a complain which says it's an unreachable statement.
Thank you very much!

Lets take this slow and easy. First of all, you need to learn how to format your code for readability. Read and take to heart
{color:0000ff}http://java.sun.com/docs/codeconv/html/CodeConvTOC.doc.html{color}
Now as to your first exercise, most of it is OK but not this:   public boolean wasModified()
      if (val == y && modified == true)
            return true;
y being a parmeter to the setValue method exists only within the scope of that method. And why would you want to test that anyways? If modified evaluates to true, that's all you need to know that the value has been modified. So you could have   public boolean wasModified()
      if (modified == true)
            return true;
   }But even that is unnecessarily verbose, as the if condition evaluates to true, and the same is returned. So in the final analysis, all you need is   public boolean wasModified()
      return modified;
   }And a public class has to be declared in a file named for the class, yes.
As for your second assignment, NO you cannot "return" two variables fom a method. return means just that: when the return statement is encountered, control returns to the calling routine. That's why the compiler is complaining that the statement following the (first) return statement is unreachable.
Do you know how to string Strings together? (it's called concatenation.) And how to represent a newline in a String literal?
db

Similar Messages

  • Hi, for Iphone tips page "see when a message was sent " , then how do I know that the message has been read?

    Hi,
    for Iphone tips page "see when a message was sent " , then how do I know that the message has been read? Thanks  

    Hi Bhavesh,
    Please see my replies inline:
    > 1. If i remember your ealier thread correct also, I
    > would suggest that you drill down in Where Did the
    > Error Occur. Instead of no restriction, select
    > Adapter Engine and also your Corresponding Adapter
    > and then trigger the error message and check if the
    > alert is triggered.
    When I click on "Where did the error occur" -> "Adapter Engine", I do not have a choice of errors from the dropdown. I only see one option "*".
    Is this right?
    > 2. ><i>When I click on "Alert Inbox" ->
    > "Subscription", I get a message "The table does not
    > contain any entries". Is this correct?</i>
    >
    > Yes this is correct. You have defined in your alerts
    > as the option as FIED RECIPIENTS. You also have
    > options like Reciepients via User Role and
    > Subscription Authorization in ALRTCADTDEF.
    >
    I see.
    I've also managed to overcome this problem by selecting "Subscription Authorization" in the Alert Category Definition page, and entering SAP_XI_MONITOR as one of the roles.
    After that, I am able to see a the alert category defined. By default it's already subscribed, because I'm using the same user - PISUPER.
    I saw in another post that the option "Suppress Multiple Alerts of this Rule" should be left unchecked. I tried that, but I still do not see any alerts raised in ALRTDISP.
    What did I miss?
    Please help.
    Thanks.
    Ron

  • How to know if a file has been updated in iCloud after modification?

    How to know if a file has been updated in iCloud after modification?
    I work on various app including Keynote on my Mac Pro. And after modification, i close file and I wait.
    When I see no more Internet traffic. I assume that keynote has uploaded all the works I have done into iCloud.
    But when I open the same file on my iPad on the way to work. I do not see the file updated.
    I assume that I did not wait long enough.
    I wished I had a way to enforce the updated file to upload and way to get confirmation that it has been completed.
    In windows I simply push the sync button.
    But for iCloud I do not yet see anything like that.
    Please help.

    you would be better served asking this in the iCloud discussion, where users are more knowledgeable about iCloud. Replies on iOS and iCloud issues are usually unanswered here because of our lack of knowledge.

  • HT4623 In attempting to update my phone software, the program tells me that the backup has been corrupted and needs to be deleated first.  How do I do that?

    In attempting to update my phone software, the program tells me that the backup has been corrupted and needs to be deleated first.  How do I do that?

    Launch iTunes. Go to Preferences, Devices pane. Click on a backup and click Delete.

  • I am receiving a message that my ID has been disabled, and I followed the steps to change the password, but still receive the same message.  Cannot access app store or do updates.

    I am receiving a message that my ID has been disabled, and I followed the steps to change the password, but still receive the same message.  Cannot access app store or do updates.

    In what way are you receiving this message? It is very common to get an email telling you that your ID has been disabled, and asking you to confirm all your details so the sender can steal your identity online.....

  • Can you programatically detect that a form has been called by another form?

    Can you programatically detect that a form has been called by another form using Open_Form?
    When closing a form I want to do one thing if it was opened stand-alone and another thing if it was called using Open_Form by another form.
    Thanks in advance.

    Maybe, Tony, also
    GET_APPLICATION_PROPERTY built-in ; it can
    be used to retrieve information about the calling (parent) and called
    form (child).
    The following example describes a way to perform a query on the child form
    using a value from the parent form; if the form is a child form, it first
    executes a query, otherwise the form goes into insert mode automatically.
              WHEN-NEW-FORM-INSTANCE
              ======================
              BEGIN
                   :GLOBAL.APP_NAME := GET_APPLICATION_PROPERTY(CALLING_FORM);
                   IF :GLOBAL.APP_NAME IS NOT NULL THEN
                        EXECUTE_QUERY;
                   END IF;
              END;Regards

  • HT1689 How do we find out what has been purchased and for how much on an IPhone 4

    How do we find out what has been purschased and for how much on an IPhone 4?

    View Purchase History
    http://support.apple.com/kb/HT2727

  • I lost my iPhone recently. It has since disappeared from support profile. Does this suggest that the phone has been restored and synced with another account?

    I lost my iPhone recently. It has since disappeared from support profile. Does this suggest that the phone has been restored and synced with another account?

    See:
    What to do if your Apple ID has been hacked
    (Fair disclosure: The Safe Mac is my site, and contains a Donate button, so I may receive compensation for providing links to The Safe Mac. Donations are not required.)

  • I received and email from Apple Customer Support that my Id has been stolen and that I am to sign into the link provided and update by changing password. I am not certain that the email came from Apple.

    I received and email from Apple Customer Support that my Id has been stolen and that I am to sign into the link provided and update by changing password. I am not certain that the email came from Apple.

    It did not come from Apple. Do not click on the link and do not supply your password. It is a scam. You can report the phishing email to Apple here:
    Phishing & Other Suspicious Emails
    Once you have done so, delete it.
    Cheers,
    GB

  • HT1539 I purchased the Bu Ray/Digital Copy of "Voyage of the Dawn Treader" today at Best Buy, but when attempt to install the digital copy, I get a message about 3 minutes into the download that says that the download has been interrupted, and to check av

    I purchased the Bu Ray/Digital Copy of "Voyage of the Dawn Treader" today at Best Buy, but when attempt to install the digital copy, I get a message about 3 minutes into the download that says that the download has been interrupted, and to check available download in the store drop down menu in Itunes.  Nothing there!  The digital copy disc does not seem to play smoothly on my Imac, which may be the cause of the problem.  What do I need to do to download the digital copy to my computer/Itunes?
    Thank you, 
    Jonathan Mink

    I purchased the Bu Ray/Digital Copy of "Voyage of the Dawn Treader" today at Best Buy, but when attempt to install the digital copy, I get a message about 3 minutes into the download that says that the download has been interrupted, and to check available download in the store drop down menu in Itunes.  Nothing there!  The digital copy disc does not seem to play smoothly on my Imac, which may be the cause of the problem.  What do I need to do to download the digital copy to my computer/Itunes?
    Thank you, 
    Jonathan Mink

  • How to verify that trust relationship has been set up successfully at client machine ?

    Hello,
    There is trust set up with domain group.Would you please let me know how can I verify that trust relationship has been set up correctly in such a way that i can see the users of trusted group on client machine ?
    Any idea?
    Note :I do not have access on Domain Controller.
    Thanks and Regards,
    Dipti
    Dipti Chhatrapati

    Hi
    As far as I know, trust certificates that have been exchanged between the SharePoint farm and external systems should be visible by going to  the Central Admin->Security->Manage Trusts page.
    Kind Regards
    Bjoern
    http://www.sharepointviking.com
    Twitter: Follow @bjoern_rapp

  • How to get that the invoice has been printed or not?

    Hi Experts,
    I have a issue in Printing Invoice. I have to make 2 copies of an invoice. One is Original and another is Duplicate. I have made that with copy windows. But the requirement is that when the original copy of a selected invoice has been printed then from the second time only the duplicate copy will be printed. How to do that in ABAP? How to get the information that the invoice has been printed or not?
    Regards,
    SURYA

    Hi Surya,
    Try the below approach, i think this is better than the previous approach and takes care of the print from "text menu" as well
    select from z table.
    if sy-subrc eq 0.
      call "SMARTFORM_COPY"
    else.
    While calling the smartform, make sure you import the "JOB_OUTPUT_INFO" parameter,
    and after you call the smartform,
    call "SMARTFORM_ORIG"
    exporting...
    Importing...
    job_output_info = w_job_output_info
    exceptions...
    If sy-subrc eq 0.
      if w_job_output_info EQ 'X'.
        update the Z table.
      else.
        do not update the z table
      endif.
    endif. 
    endif.
    Regards,
    Chen

  • How to verify that the request has been moved to Quality System

    Hi friends,
    I a new abaper and i need ur help in solving this issue.
    I have developed an object and released( as per the suggestions given already in this forum). Its working well and i can see the request in released status in se09.
    No what i really want is , How can i verify that the request has been moved to Quality System by the basis people, assuming that i have only access to dev system.

    Yes, once u release the request, if it is successfullly released will make the request avaialble under released requests
    As an ABAP'er this is enof
    <b>wht abt me Sravanan :-(</b>
    Regards
    - Gopi
    Message was edited by: Gopi Narendra

  • Can't access my email. Receiving error message that my account has been suspended and that I need to contact customer service. How do I get a phone number?

    The details are in the question. Receiving error message that my account has been suspended. Looking for a phone number to call and speak to someone. Or, please have someone call me at '''*removed*'''.
    '''Phone number removed by moderator to protect privacy'''

    Note that mozilla does not have a phone number and would never charge for services, if there is a page that says so, its a lie.

  • TS3276 How to get message when email has been received and read?

    How do I set my Mail so I can get a message when an email has been received and read?

    Read receipt feature is not available in Mail, unfortunately.
    Best.

Maybe you are looking for

  • Indent sales - reject item after performing GR

    Dear SD Gurus, I have a question on the reason for rejection for indent sales. Scenario as follows: 1. Create sales order with sales lines using indent sales. 2. PR automatically created. Released. 3. PO is created. Released. 4. GR performed for the

  • A Buttom from a report

    hi, I need to execute a process when doing click in a Link that also redirects to another page, from a report. How I can do this? I know how use the column link, but I don't know if it's possible to execute a process from there. Thanks a lot!.

  • Popping sound when running WMP in full scr

    Basically, I installed the card with a new computer. The specs are: AMD Athlon 64 3200+ Mother Asus AV8 Memory 2x52 Dual Channel Corsair Xms 80 Gb Matrox 7200 RPM PATA Geforce4 6600 GT AGP X-fi ExtremeMusic TV / Radio AVermedia TV Phone (old TV card)

  • Stock tranport order with scheduling agreement

    Hi All i am trying to do Stock transport order with Scheduling agreement within company between two plants like 1) 2008 2) 2009 2008 :--- supplying plant 2009:---- recieving plant maintain same material in both plants & created Scheduling agreement w

  • Flash Player install Oracle Enterprise 11g

    Hi We have recently upgraded to Oracle Enterprise 11g when loading our real time monitoring graphs they were complaining they needed new plug-in (located on fedora system) so we put in the latest flash player into fedora, the screen stopped saying it