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.

Results 1 to 16 of 16

Thread: How to write addTextbook(Textbook) in a method? how to write a tester class?

  1. #1
    Member
    Join Date
    Mar 2013
    Posts
    68
    My Mood
    Angelic
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default How to write addTextbook(Textbook) in a method? how to write a tester class?

    addTextbook(Textbook) adds a new Textbook to the inventory of the bookstore.
    buyTextbook(String id) removes a Textbook object from the list of textbooks of the Bookstore. If the id does not match any Textbook object in the list, an error message is printed to the screen.

    Design a tester class called BookstoreTester. The tester class has a main() method and tests the functionality of the class Bookstore as follows:
    a. Create Bookstore and name it "UWF Bookstore".
    b. Create a minimum of three Textbook objects and add them to the bookstore.
    c. Create 6 Apparel objects, two of each category, and add them to the bookstore.
    d. Setup a loop to:
    e. Display a short menu that allows a user to perform different actions in the bookstore such as looking up textbooks, or apparel items, or purchasing items. Use all of the accessor methods in the Bookstore to access specific items. Use the given methods to make purchases


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: How to write addTextbook(Textbook) in a method? how to write a tester class?

    Do you have any specific questions about your assignment?
    Please post your code and any questions about problems you are having.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Member
    Join Date
    Mar 2013
    Posts
    68
    My Mood
    Angelic
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: How to write addTextbook(Textbook) in a method? how to write a tester class?

    yes i do. how to write add method and fuction for that? My assignment due tonight

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Member
    Join Date
    Mar 2013
    Posts
    68
    My Mood
    Angelic
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: How to write addTextbook(Textbook) in a method? how to write a tester class?

    i know how but i dont know how to write myself

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: How to write addTextbook(Textbook) in a method? how to write a tester class?

    i know how
    Give it a try.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Member
    Join Date
    Mar 2013
    Posts
    68
    My Mood
    Angelic
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: How to write addTextbook(Textbook) in a method? how to write a tester class?

    [code = java]
    public void addTextboox(textbook)
    {
    textbooks.add(textbook);
    }
    [/code]

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: How to write addTextbook(Textbook) in a method? how to write a tester class?

    See the tutorial: Defining Methods (The Java™ Tutorials > Learning the Java Language > Classes and Objects)

    Copy the full text of all error messages and paste it here.

    Look at the formatting of post#7. The code tag is not right.
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Member
    Join Date
    Mar 2013
    Posts
    68
    My Mood
    Angelic
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: How to write addTextbook(Textbook) in a method? how to write a tester class?

    [code =java]
    ----jGRASP exec: javac -g Bookstore.java

    Bookstore.java:62: error: <identifier> expected
    public void addTextbook(textbook)
    ^
    1 error

    ----jGRASP wedge2: exit code for process is 1.
    ----jGRASP: operation complete.
    [/code]

    --- Update ---

    ----jGRASP exec: javac -g Bookstore.java
     
    Bookstore.java:62: error: <identifier> expected
    	  public void addTextbook(textbook)
    	                                  ^
    1 error
     
     ----jGRASP wedge2: exit code for process is 1.
     ----jGRASP: operation complete.

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: How to write addTextbook(Textbook) in a method? how to write a tester class?

    The syntax for the method definition is wrong.
    See the tutorial: Defining Methods (The Java™ Tutorials > Learning the Java Language > Classes and Objects)
    If you don't understand my answer, don't ignore it, ask a question.

  11. #11
    Member
    Join Date
    Mar 2013
    Posts
    68
    My Mood
    Angelic
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: How to write addTextbook(Textbook) in a method? how to write a tester class?

    import java.util.List;
    import java.util.ArrayList; 
     
    public class Bookstore
    {
    	//Instance field
    	/**
         *@param name
    	  *@param textbooks
         *@param apparel
         */
     
    	private String name; //name of the bookstore
       private static ArrayList<Textbook> textbooks; //store Textbook objects
       private static ArrayList<Apparel> apparel; //store Apparel objects
    	private Textbook textbook;
    	private Apparel apparel;
     
     
    	/** 
         *@param name
         */
     
         public Bookstore(String name) 
         {
    	  		this.name = name;
    	  }
     
    	 //Acessor Method     
     
    	  public ArrayList<Textbook> getTextbooks() 
         {
     
    			return textbooks = new ArrayList<Textbook>();
         }
     
         public ArrayList<Textbook> getTextbooks(String name) 
         {
            return textbooks = new ArrayList<Textbook>();
         }
     
         public Textbook getTextbook(String id) 
         {
            return null;     
    	  }
     
         public static ArrayList<Apparel> getApparel() 
         {
            return apparel = new ArrayList<Apparel>();
         }
     
    	  public ArrayList<Apparel> getApparelbyCategory(String name) 
         {
            return apparel = new ArrayList<Apparel>();
         }
     
    	  public Apparel getApparel(String id) 
         {
            return null; 
    	  }
     
    	  public void addTextbook(int t)
    	  { 
    	  		textbooks.add(t); 
    	  }			
     
     
     
     
    }

  12. #12
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: How to write addTextbook(Textbook) in a method? how to write a tester class?

    Did you solve the problem? I don't see any questions or error messages in the last post.
    If you don't understand my answer, don't ignore it, ask a question.

  13. #13
    Member
    Join Date
    Mar 2013
    Posts
    68
    My Mood
    Angelic
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: How to write addTextbook(Textbook) in a method? how to write a tester class?

    -jGRASP exec: javac -g Bookstore.java
     
    Bookstore.java:17: error: variable apparel is already defined in class Bookstore
    	private Apparel apparel;
    	                ^
    Bookstore.java:64: error: no suitable method found for add(int)
    	  		textbooks.add(t); 
    	  		         ^
        method ArrayList.add(int,Textbook) is not applicable
          (actual and formal argument lists differ in length)
        method ArrayList.add(Textbook) is not applicable
          (actual argument int cannot be converted to Textbook by method invocation conversion)
    2 errors

  14. #14
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: How to write addTextbook(Textbook) in a method? how to write a tester class?

    variable apparel is already defined
    A variable can only be defined once. Remove or rename the second definition.

    no suitable method found for add(int)
    textbooks.add(t);
    ^
    method ArrayList.add(int,Textbook) is not applicable
    There is no add() method in the ArrayList class that takes an int for its arg. The arg should be an object of the type used in the definition for textbooks:
    ArrayList<Textbook> textbooks;
    If you don't understand my answer, don't ignore it, ask a question.

  15. #15
    Member
    Join Date
    Mar 2013
    Posts
    68
    My Mood
    Angelic
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: How to write addTextbook(Textbook) in a method? how to write a tester class?

    i know but my assignment say addTextbok(String id)

  16. #16
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: How to write addTextbook(Textbook) in a method? how to write a tester class?

    Where does it say that? It's not what is in post#1
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Re: How to write Entropy class in java?
    By samar in forum Object Oriented Programming
    Replies: 3
    Last Post: December 10th, 2012, 01:22 PM
  2. How to write Entropy class in java?
    By colerelm in forum Object Oriented Programming
    Replies: 2
    Last Post: October 22nd, 2012, 10:31 AM
  3. how to do write this method with more efficiency ?
    By romavolman in forum Algorithms & Recursion
    Replies: 2
    Last Post: October 2nd, 2012, 11:23 AM
  4. Write a method that searches the BST for a given input
    By Jurgen in forum Algorithms & Recursion
    Replies: 4
    Last Post: January 6th, 2012, 11:46 AM
  5. [SOLVED] Why can't I write to file inside a doGet() method?
    By FailMouse in forum Java Servlet
    Replies: 1
    Last Post: July 7th, 2010, 01:15 AM