I need help with this seemingly simple homework problem!

Discussion in 'Java' started by ThePacific, Sep 26, 2012.

  1. ThePacific

    ThePacific

    Joined:
    Sep 26, 2012
    Messages:
    1
    So, we're given two classes originally.

    public class Innocent
    {
    public static void main(String[] args)
    {
    String iAmGiving = "honor";
    String result = Evil.bargain(iAmGiving);
    System.out.println("Oh Woe! All I have received is " + result);

    double sum = Evil.plus(2, 2.0);
    System.out.println(sum);
    System.out.println(Evil.plus(3, 4.5));
    }
    }


    and


    public class Evil
    {
    static public String bargain(String whatIsGiven)
    {
    System.out.println("Aha! I have received your " + whatIsGiven);
    String whatIsReturned = "despair";
    return whatIsReturned;
    }
    static public double plus(int a, double b)
    {
    return a + b;
    }
    }


    And the assignment section I don't understand is where it asks me to do this:

    1.)Add a method to Evil that has int[] as an argument which returns the sum of the first three elements in the array.

    2.)In Innocent.main(), create a local variable array with at least 3 initialized elements (curly braces!)

    3.)Add a call to your new Evil method using the array for the argument. Print the result.


    I keep getting error messages like <identifier> expected. Please help!
     
    ThePacific, Sep 26, 2012
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tom Johnson
    Replies:
    4
    Views:
    392
    red floyd
    Aug 15, 2003
  2. Guilherme Polo

    Re: seemingly simple list indexing problem

    Guilherme Polo, Jul 28, 2008, in forum: Python
    Replies:
    3
    Views:
    282
    John Krukoff
    Jul 30, 2008
  3. John Krukoff
    Replies:
    6
    Views:
    295
    John Krukoff
    Jul 30, 2008
  4. Derek Cannon
    Replies:
    11
    Views:
    205
    Phrogz
    Apr 20, 2010
  5. W.Sh
    Replies:
    5
    Views:
    123
    Luke Matuszewski
    Feb 11, 2006
Loading...

Share This Page