Results 1 to 10 of 10
  1. #1
    aldrin0987 is offline Member
    Join Date
    Jul 2015
    Posts
    4
    Rep Power
    0

    Default help with get and set method

    import java.util.Scanner;
    class Book
    {
    public static void main(String [] args)
    {
    String title;
    int numberOfPages;
    System.out.println("Enter the title of the book; ");
    Scanner sc = new Scanner(System.in);
    title= sc.nextLine();
    System.out.println("Enter the pages of the book; ");
    numberOfPages=sc.nextInt();
    System.out.println("Title of the book; " + title);
    System.out.println("Pages of the book: " + numberOfPages);
    gettitle();
    {
    return;
    }
    settitle();
    {
    return;
    }
    }
    }
    Line: 19
    cannot find symbol
    symbol: method gettitle()
    location: class Book
    Line: 23
    cannot find symbol
    symbol: method settitle()
    location: class Book
    how can i debug it? help


    help with get and set method-untitled.jpg

  2. #2
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    12

    Default Re: help with get and set method

    Debugging is something you do when your code compiles but does not do what it is expected to do.

    What you have here are simple compile errors, so you read the error, go to the line it reports and see what is wrong with it. In this case you're trying to define two methods 'gettitle()' and 'settitle()' in the wrong place and in all the wrong ways.

    Java Code:
    import java.util.Scanner;
    
    class Book {
        public static void main(String[] args) {
            String title;
            int numberOfPages;
            System.out.println("Enter the title of the book; ");
            Scanner sc = new Scanner(System.in);
            title = sc.nextLine();
            System.out.println("Enter the pages of the book; ");
            numberOfPages = sc.nextInt();
            System.out.println("Title of the book; " + title);
            System.out.println("Pages of the book: " + numberOfPages);
    
            gettitle(); // what is this?
            {
                return;
            }
            settitle(); // what is this?
            {
                return;
            }
        }
    }
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  3. #3
    aldrin0987 is offline Member
    Join Date
    Jul 2015
    Posts
    4
    Rep Power
    0

    Default Re: help with get and set method

    that's my problem sir.. and i dont know how to fix it.. that's why im here and asking for someone help.

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    27

    Default Re: help with get and set method

    What is it you are trying to do?

    Are you supposed to have getTitle() and setTitle() methods somewhere?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    aldrin0987 is offline Member
    Join Date
    Jul 2015
    Posts
    4
    Rep Power
    0

    Default Re: help with get and set method

    help with get and set method-untitled.jpg

    this is the problem
    and i dont know if i do the right things.
    help me and i need an explanation so i can understand..thanks

  6. #6
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    12

    Default Re: help with get and set method

    An explanation of what? It looks like you simply don't know how to write the code yet, so you should be studying rather than just guessing to write the code.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  7. #7
    aldrin0987 is offline Member
    Join Date
    Jul 2015
    Posts
    4
    Rep Power
    0

    Default Re: help with get and set method

    ok thnks

  8. #8
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    27

    Default Re: help with get and set method

    The first thing is, you don't need a main() method.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  9. #9
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    14

    Default Re: help with get and set method

    I think this should be moved to New to Java.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  10. #10
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    12,059
    Rep Power
    26

    Default Re: help with get and set method

    Agreed, and so moved.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Replies: 1
    Last Post: 12-12-2013, 07:08 PM
  2. Replies: 7
    Last Post: 04-11-2013, 05:31 AM
  3. Replies: 4
    Last Post: 03-28-2013, 08:40 PM
  4. Replies: 2
    Last Post: 03-23-2012, 04:53 AM
  5. Replies: 1
    Last Post: 10-17-2011, 01:00 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
  •