Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Page 2 of 2 FirstFirst 12
Results 26 to 36 of 36

Thread: Program goes into infinite compilation. University project - Library Program.

  1. #26
    Member clarky2006's Avatar
    Join Date
    Nov 2012
    Posts
    84
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default Re: Program goes into infinite compilation. University project - Library Program.

    Quote Originally Posted by Norm View Post
    My impression of several IDEs is that they are for giving students the flavor of programming without requiring them to know all the dirty details.
    If you want to be a programmer, you need to know the dirty details. Then the question is, When do you teach them? I'll leave that to the academics to figure out the best way to teach a subject.
    Well said, You are right, they are trying not to bombard us with too much info..In Blue j u actually are able to create an object and call the methods. You actually see what you are doing graphically, which makes it more interesting for the students. But its no gud for me because its a pathway to my Networking course. I wont get a second chance, as I have to follow a specific path to my network degree, but I ve enjoyed the 7 wks introduction to programming so much, I want more than just the basics. Im thinking of diversifying to programming. thanx

    --- Update ---

    Quote Originally Posted by clarky2006 View Post
    Well said, You are right, they are trying not to bombard us with too much info..In Blue j u actually are able to create an object and call the methods. You actually see what you are doing graphically, which makes it more interesting for the students. But its no gud for me because its a pathway to my Networking course. I wont get a second chance, as I have to follow a specific path to my network degree, but I ve enjoyed the 7 wks introduction to programming so much, I want more than just the basics. Im thinking of diversifying to programming. thanx
    I still need your help though to finish the project..Im trying to figure out how to write an If statement on my book Class..The scenario is they want us to add if the book is fiction or non-fiction as part of the details and thinking about it I can only use Boolean. I ll post a copy the code as i re-written it today and it compiles fine.
    /**
     * This is the book Class and would hold information on the books 
     * collection.
     * 
     * @author (Michael Clark) 
     * @version (30th October 2012, version 0.1)
     */
    public class Book
    {
        // instance variables 
        private int bookId;
        private String author;
        private String title;
        private boolean isFiction;
     
        /**
         * Constructor for objects of class Book with parameters.
         */
        public Book(int id, String author, String title, boolean isFiction)
        {
            // Instance variables
            this.bookId = 0;
            this.author = author;
            this.title = title;
            this.isFiction = true;
        }
     
        /**
         *  This is a default constructor method with no parameters for 
         *  the books Class.
         *
         *  
         */
         public Book()
         {
     
         }
     
        /**
         * This method is for returning the name of the books Author. 
         */
     
        public String getautor()
        {
     
            return author;
        }
     
        /**
         * This method returns the book ID.
         */
     
        public int getId()
        {
            return bookId;
        }
     
        /**
         * 
         * This method would return the Book title.
         */
        public String getTitle()
        {
            return title;
        }
     
        /**
         * 
         * This mutator method should change or set the book author's name 
         * when called.
         * 
         */
        public void setAuthor(String authorName)
        {
            author = authorName;
        }
     
        /**
         * 
         * This method sets the book ID when invoked.
         */
        public void setId(int newBookId)
        {
            bookId = newBookId;
        }
     
        /**
         * 
         * This method when invoked would prompt the user to set/change the book title 
         * by entering a string name in the parameter.
         * 
         */
        public void setTitle(String bookTitle)
        {
            title = bookTitle;
        }
     
        /**
         * This method when called would print all the book's details including the
         * book author, book ID, book title and whether its fiction or non fiction.
         * 
         */
        public void printDetails()
        {
        {
            System.out.println("bookId  "+ bookId + "#");
            System.out.println("author " + author + "#");
            System.out.println("bookTitle " + title + "#");
     
            System.out.println("?????????");
     
        }
     
    }
     
    }

  2. #27
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Program goes into infinite compilation. University project - Library Program.

    how to write an If statement
    Which part of the if statement is giving you problems. I would imagine it would be the boolean expression. Can you explain?

    the book is fiction or non-fiction
    A boolean variable could be used for that. Its value would be true if fiction, false if non-fiction.


    See: The if-then and if-then-else Statements (The Java™ Tutorials > Learning the Java Language > Language Basics)
    If you don't understand my answer, don't ignore it, ask a question.

  3. #28
    Member clarky2006's Avatar
    Join Date
    Nov 2012
    Posts
    84
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default Re: Program goes into infinite compilation. University project - Library Program.

    Quote Originally Posted by Norm View Post
    Which part of the if statement is giving you problems. I would imagine it would be the boolean expression. Can you explain?


    A boolean variable could be used for that. Its value would be true if fiction, false if non-fiction.

    cheers I would have look on that site now..If you look at the code i posted.. the variable="private boolean isfiction"


    See: The if-then and if-then-else Statements (The Java™ Tutorials > Learning the Java Language > Language Basics)
    Have a look at the code i posted please. i need to add if fiction or not in the print method..cheers.................................... .............

  4. #29
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Program goes into infinite compilation. University project - Library Program.

    What do you want the print() method to do with respect to how it uses the isFiction variable?

    The ternary operator could be useful. It's sort of like an inline method that returns one of two values depending on the value of a boolean expression. Use Google to find examples.
    Also see: http://docs.oracle.com/javase/tutori...bolts/op2.html
    If you don't understand my answer, don't ignore it, ask a question.

  5. #30
    Member clarky2006's Avatar
    Join Date
    Nov 2012
    Posts
    84
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default Re: Program goes into infinite compilation. University project - Library Program.

    Quote Originally Posted by Norm View Post
    What do you want the print() method to do with respect to how it uses the isFiction variable?

    The ternary operator could be useful. It's sort of like an inline method that returns one of two values depending on the value of a boolean expression. Use Google to find examples.
    Also see: Equality, Relational, and Conditional Operators (The Java™ Tutorials > Learning the Java Language > Language Basics)
    public boolean fiction()
    {
        if(boolean == true)
        System.out.println("This book is ficion");
     
        else 
        if(false)
        System.out.println("This book is non-fiction");
     
     
     
    }

    struggling to get this to print

  6. #31
    Junior Member
    Join Date
    Nov 2012
    Location
    Germany
    Posts
    20
    My Mood
    Bored
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Default Re: Program goes into infinite compilation. University project - Library Program.

    Quote Originally Posted by clarky2006 View Post
    if(boolean == true)
    You can't compare a declarator with something.

  7. The Following User Says Thank You to minju For This Useful Post:

    clarky2006 (November 10th, 2012)

  8. #32
    Member clarky2006's Avatar
    Join Date
    Nov 2012
    Posts
    84
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default Re: Program goes into infinite compilation. University project - Library Program.

    Quote Originally Posted by minju View Post
    You can't compare a declarator with something.
    How can i get it to print? what do you suggest?

  9. #33
    Junior Member
    Join Date
    Nov 2012
    Location
    Germany
    Posts
    20
    My Mood
    Bored
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Default Re: Program goes into infinite compilation. University project - Library Program.

    You have to put the boolean variable's name instead of "boolean".

  10. #34
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Program goes into infinite compilation. University project - Library Program.

    if(boolean == true)
    That line should be coded like this:
    if(booleanVariableNameHere)

    You need to have a boolean variable that is true if a book is ....(your choice for fiction or non-fiction)
    If you don't understand my answer, don't ignore it, ask a question.

  11. #35
    Member clarky2006's Avatar
    Join Date
    Nov 2012
    Posts
    84
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default Re: Program goes into infinite compilation. University project - Library Program.

    Quote Originally Posted by Norm View Post
    That line should be coded like this:
    if(booleanVariableNameHere)

    You need to have a boolean variable that is true if a book is ....(your choice for fiction or non-fiction)
    public boolean fiction()
    {
        if(true)
        {
        System.out.println("This book is fiction");
       }
     
        else 
        if(false)
        {
        System.out.println("This book is non-fiction");
       }
     
     
     
     
    }

    Hia, This is how I ve coded it but it says "missing return statement"
    cheers.

  12. #36
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,165
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Program goes into infinite compilation. University project - Library Program.

    Before you write the code for the fiction() method you need to decide what it is supposed to do.
    The way it is coded it is supposed to return a boolean value: true of false are the two boolean values.
    What do you want the method to do? Print a message and/or return a value?

    The condition in the if statement should give a boolean value of either true or false. You have hardcoded a value of true which means that the if statement will ALWAYS execute(because its value is true) and the else statement will NEVER execute.

    Examples of a boolean expression:
    2 > someVar
    aVar > 4
    aVar2 != anotherVar

    Look in your text about boolean expressions or ask Google.
    Also see: http://docs.oracle.com/javase/tutori...bolts/op2.html
    If you don't understand my answer, don't ignore it, ask a question.

Page 2 of 2 FirstFirst 12

Similar Threads

  1. [SOLVED] Simple Library Program / Need feedback.
    By ziplague in forum What's Wrong With My Code?
    Replies: 22
    Last Post: May 2nd, 2014, 09:03 PM
  2. Help With My Library Program please.
    By jaydac12 in forum What's Wrong With My Code?
    Replies: 26
    Last Post: September 29th, 2012, 09:31 AM
  3. Having Trouble Using a Project as a Library
    By snowguy13 in forum Java IDEs
    Replies: 0
    Last Post: July 5th, 2012, 08:11 PM
  4. I'm creating a sudoku program that is somehow in an infinite loops.
    By Leiferson in forum What's Wrong With My Code?
    Replies: 4
    Last Post: November 18th, 2011, 03:21 AM
  5. Unable to execute the program (no compilation error)
    By Alexie91 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: September 16th, 2011, 02:39 PM