Page 3 of 3 FirstFirst 123
Results 41 to 48 of 48
  1. #41
    afrttoh is offline Member
    Join Date
    Nov 2008
    Location
    London
    Posts
    39
    Rep Power
    0

    Default

    :) Finally I have managed to do it correctly

    Thanks to every one

  2. #42
    afrttoh is offline Member
    Join Date
    Nov 2008
    Location
    London
    Posts
    39
    Rep Power
    0

    Default

    Now this is very similar task to the first program this time I need to do is to create a method and call it calculateBill.

    I have edited this prog and here what I have managed to do so far:


    first this is the program before editing:
    import javax.swing.JOptionPane;

    public class bill7
    {
    public static void main(String[] args)
    {
    String alb = JOptionPane.showInputDialog("how many albums did you buy?");
    String ialb = JOptionPane.showInputDialog("how many individual tracks did you buy?");

    int albums = Integer.parseInt(alb);
    int individualalbums = Integer.parseInt(ialb);


    System.out.println("The total cost of albums: " + albums*899 + " p");
    System.out.println("The total cost of individual tracks: " + individualalbums*79+ " p");
    System.out.println("The total cost of albums and individual tracks per month is: " + (albums*899+ individualalbums*79) + " p");


    }
    }

    NOW this is after editing:


    import javax.swing.JOptionPane;

    public class bill7
    {
    public static void main(String[] args)
    {
    String alb = JOptionPane.showInputDialog("how many albums did you buy?");
    String ialb = JOptionPane.showInputDialog("how many individual tracks did you buy?");

    int albums = Integer.parseInt(alb);
    int individualalbums = Integer.parseInt(ialb);
    int res = calculateBill (int albums ,int individualalbums);
    }
    private static int calculateBill (int albums ,int individualalbums)
    {

    System.out.println("The total cost of albums: " + albums*899 + " p");
    System.out.println("The total cost of individual tracks: " + individualalbums*79+ " p");
    System.out.println("The total cost of albums and individual tracks per month is: " + (albums*899+ individualalbums*79) + " p");



    return calculateBill;
    }
    }


    ---------- Compile Java Source ----------
    bill7.java:12: '.class' expected
    int res = calculateBill (int albums ,int individualalbums);
    ^
    bill7.java:12: <identifier> expected
    int res = calculateBill (int albums ,int individualalbums);
    ^
    bill7.java:12: not a statement
    int res = calculateBill (int albums ,int individualalbums);
    ^
    bill7.java:12: ';' expected
    int res = calculateBill (int albums ,int individualalbums);
    ^
    4 errors

    Output completed (1 sec consumed)
    Last edited by afrttoh; 11-28-2008 at 10:47 PM.

  3. #43
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    8

    Default calculateBill

    • In the caculateBill method, you are trying to return a variable, calculateBill, that hasn't been defined anyplace in the program, let alone in the method. If I understand the program correctly, it should be defined in the calculateBill method and returned to the calling method.

    • Also, you are redefining the albums & individulaalbums arguments when calling the calculateBill method:

    Java Code:
    int res = calculateBill (int albums ,int individualalbums);
    Get rid of the int types (just leave the variables)

    Luck,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  4. #44
    afrttoh is offline Member
    Join Date
    Nov 2008
    Location
    London
    Posts
    39
    Rep Power
    0

    Default

    Quote Originally Posted by CJSLMAN View Post
    • In the caculateBill method, you are trying to return a variable, calculateBill, that hasn't been defined anyplace in the program, let alone in the method. If I understand the program correctly, it should be defined in the calculateBill method and returned to the calling method.

    • Also, you are redefining the albums & individulaalbums arguments when calling the calculateBill method:

    Java Code:
    int res = calculateBill (int albums ,int individualalbums);
    Get rid of the int types (just leave the variables)

    Luck,
    CJSL
    Thanks a lot..

    Note: the task is :write a method called
    calculateBill, which calculates the total bill amount. Call this method
    from within the main method, and display its return value


    now this is what i have done:

    import javax.swing.JOptionPane;

    public class bill7
    {
    public static void main(String[] args)
    {
    String alb = JOptionPane.showInputDialog("how many albums did you buy?");
    String ialb = JOptionPane.showInputDialog("how many individual tracks did you buy?");

    int albums = Integer.parseInt(alb);
    int individualalbums = Integer.parseInt(ialb);
    int res = calculateBill (albums , individualalbums);
    }
    private static int calculateBill (int albums ,int individualalbums)
    {

    System.out.println("The total cost of albums: " + albums*899 + " p");
    System.out.println("The total cost of individual tracks: " + individualalbums*79+ " p");
    System.out.println("The total cost of albums and individual tracks per month is: " + (albums*899+ individualalbums*79) + " p");



    return calculateBill;
    }
    }

    ---------- Compile Java Source ----------
    bill7.java:23: cannot find symbol
    symbol : variable calculateBill
    location: class bill7
    return calculateBill;
    ^
    1 error

    Output completed (3 sec consumed)



    I know i have to defined calculateBill , but I honestly tried with no luck!
    Hope you could help me.
    Last edited by afrttoh; 11-28-2008 at 11:30 PM.

  5. #45
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    8

    Default

    afrttoh... I have the feeling you have absolutely no idea what you are doing. To define a variable means to give it a type (int, string, array, etc). Then you have to assign an amount/value to that variable. So give the cauclateBill variable a value (HINT: it's in one of the println in the calculateBill method).

    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  6. #46
    afrttoh is offline Member
    Join Date
    Nov 2008
    Location
    London
    Posts
    39
    Rep Power
    0

    Default

    Quote Originally Posted by CJSLMAN View Post
    afrttoh... I have the feeling you have absolutely no idea what you are doing. To define a variable means to give it a type (int, string, array, etc). Then you have to assign an amount/value to that variable. So give the cauclateBill variable a value (HINT: it's in one of the println in the calculateBill method).

    CJSL
    thanks mate ,
    dnt just have a feeling be sure as well lol!

  7. #47
    racerxadam is offline Member
    Join Date
    Jul 2008
    Posts
    68
    Rep Power
    0

    Default

    Quote Originally Posted by afrttoh View Post
    thanks mate ,
    dnt just have a feeling be sure as well lol!
    In that case start here Sun's Java Tutorial

  8. #48
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    8

    Default And the result was?

    • Did your program work?
    • If yes, post it so other people in the forum can learn from it.
    • if your program is working, it indicate that it is solved (in Thread Tools)
    • Please follow racerxadam suggestion and study the tutorials


    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

Page 3 of 3 FirstFirst 123

Similar Threads

  1. Pls Help me for Newton-Raphson method by Java
    By kienph2004 in forum Advanced Java
    Replies: 3
    Last Post: 08-13-2008, 06:07 PM
  2. Call Java Method
    By hussainzim in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 05-15-2008, 08:22 AM
  3. Any method for improving of java thread
    By code453 in forum Java Applets
    Replies: 0
    Last Post: 12-20-2007, 09:29 AM
  4. Java constructor method
    By carl in forum New To Java
    Replies: 2
    Last Post: 07-31-2007, 03:15 PM
  5. The main method in java...
    By lenny in forum New To Java
    Replies: 1
    Last Post: 07-31-2007, 07:21 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •