Results 1 to 4 of 4
  1. #1
    Deon's Avatar
    Deon is offline Member
    Join Date
    Jan 2008
    Posts
    12
    Rep Power
    0

    Default Need help on this question

    Hello guys,

    I need help again~ for this project question . I have done half way and got stuck

    here is the output i must get:



    i have make 2 class file and 1 driver file

    The class file are call "Customer" and "bookDetail"
    and 1 driver file is call "BookStore"

    i can't slove the problem in "BookStore" and the code is incomplete

    "Customer":
    PHP Code:
    public class Customer{
    
          //attributes
          private String Name;
          private String Address;
          private int Contact;
    
          //three-argument constructor
          public Customer (String newName, String newAddress, int newContact){
                             Name = newName;
                             Address = newAddress;
                             Contact = newContact;
          }
          
          
          
         public String getName(){
              return Name;
         
         }
    
         public String getAddress(){
              return Address;
    
        }
    
        public int getContact(){
             return Contact;
    
        }
    }




    "bookDetail:"

    PHP Code:
    public class bookDetail
    {
    	String Cata = "";
    	String Title = "";
    	String Author = "";
    	int Cost = 0;
    
    	public bookDetail()
    	{
    		Cata = "";
    		Title = "";
    		Author = "";
    		Cost = 0;
    	}
    
    	public void update(String xCata, String xTitle, String xAuthor, int xCost)
    	{
    		Cata = xCata;
    		Title = xTitle;
    		Author = xAuthor;
    		Cost = xCost;
    	}
    
    	public void display()
    	{
    		System.out.println("Catalogry: " + Cata);
    		System.out.println("Title: " + Title);
    		System.out.println("Author: " + Author);
    		System.out.println("Cost : " + Cost);
    	}
    
    	
    	public String getCata()
    	{
    		return Cata;
    	}
    	
    	public String getTitle()
    	{
    		return Title;
    	}
    	
    	public String getAuthor()
    	{
    		return Author;
    	}
    
    	public int getCost()
    	{
    		return Cost;
    	}	
    }



    and finally my driver file

    "BookStore:"

    PHP Code:
    import java.util.Scanner;
    
    public class BookStore
    {
    	public static void main(String args[])
    	{
    		String nName,newAddress,receipt,customer,choice,movies,cont="N";
    	
    		int Cost,custTel;
    	
    		//int BookCata = 0;
    		String BookTitle = "";
    		//string BookAuthor = "";
    		//double BookCost = 0;
    		
    		String YesAndNo = "";
    		Scanner in= new Scanner(System.in);
    
    		
    		int NumOfBook = 15;
    		bookDetail[] book = new bookDetail[NumOfBook];
    
    		for(int i = 0; i < NumOfBook; i++)
    		{
    
    			book[i] = new bookDetail();
    
    		}
    
    		book[0].update("0001", "The Secret", "Rhonda Byrne", 10);
    		book[1].update("0002", "Secrets of Self-Made Millionaires", "Adam Khoo", 10);
    		book[2].update("0003", "An Illustrated Biography of the World’s Most Successful Investor", "Warren Buffet", 15);	
    		book[3].update("0004", "How good do we have to be ?", "Harold Kushnere", 8);
    		book[4].update("0005", "Half a Life", "V. S. Naipaul", 5);
    		book[5].update("0006", "Subconscious Mind", "Murphy McMahan", 6);
    		book[6].update("0007", "The Road Less Travelled", "M. Scott Peck", 5);
    		book[7].update("0008", "Stop the insanity!", "Susan Powter", 5);
    		book[8].update("0009", "Business As Usual", "Anita Roddick", 6);
    		book[9].update("0010", "Rich Kid, Smart Kid", "Robert Kiyosaki", 6)	;
    		book[10].update("0011", "Secrets of the Millionaire Mind", "Harv Eker", 10);
    		book[11].update("0012", "Where have all the leaders gone?", "Lee Iacocca", 15);
    		book[12].update("0013", "If success is a game, these are the rules", "Cherie Carter", 8);
    		book[13].update("0014", "Think Big", "Donald Trump", 15);
    		book[14].update("0015", "Blink", "Malcolm Gladwell", 10);
    
    		
    		
    		System.out.print("Enter the title of book: ");
    		BookTitle = in.nextLine();
    		BookTitle = BookTitle.toUpperCase();
    		
    		String CheckBookTitle = "";
    		
    		int index = 0;
    
    		for(int i = 0; i < NumOfBook; i++)
    		{
    			CheckBookTitle = book[i].getTitle();
    			CheckBookTitle = CheckBookTitle.toUpperCase();
    			
    			if(BookTitle.compareTo(CheckBookTitle) == 0)
    			{
    				System.out.println(BookTitle.compareTo(CheckBookTitle));
    				
    				index = i;
    				System.out.println("Book title: " + BookTitle +" found");
    
    				System.out.println("Detail for the book title " + book[i].getTitle());
    				System.out.println("Author: " + book[i].getAuthor());
    				System.out.println("Catalogue " + book[i].getCata());
    				System.out.println("Cost: $" + book[i].getCost());
    				System.out.println("");
    				System.out.println(book[i].getTitle() + " Is available");
    				System.out.println("Cost to rent is " + book[i].getCost());
    
    				System.out.println("Proceed to rent? (Y/N) :");
    				choice= in.nextLine();
    
    			if(choice.equalsIgnoreCase("Y"))
    			{
    				//customer particulars
               			System.out.print("Please enter customer's name: ");
               			nName=in.nextLine();
               
              			 System.out.print("Please enter customer's address: ");
              			 newAddress =in.nextLine();
               
               			System.out.print("Please enter customer's telephone number: ");
               			custTel= in.nextInt(); 
               
    				
                    		Customer aCust = new Customer(nName,newAddress,custTel);
                    
                    
                			customer="\nPrinting out receipt for " + aCust.getName()+ "..."+ "\n" + 
                		     		"Address: " + aCust.getAddress() +"\n\n"; 
                		     	
                			receipt="Renting out " + BookTitle + " for " + " $ "+ book[i].getCost()  +"\n"+"\n"+
                			 	"\nThank You For renting our Books please come again" + "\n\nServing next customer.......";
                	
                			System.out.println(customer + receipt );
                	
                		}			
    			}
    		}
    		
    		if(choice.equalsIgnoreCase(""))
    			{
    				System.out.print("??");
    			}		
    			
    		
    			if(choice.equalsIgnoreCase("N"))
    			{
    				System.out.println("Serving next customer....");
    				cont=in.nextLine();
    			}
    
    		while(cont.equalsIgnoreCase("Y"));
    		System.out.println("GoodBye!! ");
               	System.exit(0);
    
    			
    
            } //main
    } //class
    Last edited by Deon; 01-27-2008 at 09:21 AM.
    I LOVE JAVA!

  2. #2
    CaptainMorgan's Avatar
    CaptainMorgan is offline Moderator
    Join Date
    Dec 2007
    Location
    NewEngland, US
    Posts
    835
    Rep Power
    8

    Default

    If I understand your problem correctly, do you want a GUI class to display your output? or can you display your table of results horizontally on the console?

    Also, have a look at this line:
    Java Code:
            if(BookTitle.compareTo(CheckBookTitle) == 0);
    Correct me if I'm wrong, but I don't think the semicolon is meant to be there... take that out and try it again.

    I think I need more specification from you on what exactly you need...
    Vote for the new slogan to our beloved Java Forums! (closes on September 4, 2008)
    Want to voice your opinion on your IDE/Editor of choice? Vote now!
    Got a little Capt'n in you? (drink responsibly)

  3. #3
    Deon's Avatar
    Deon is offline Member
    Join Date
    Jan 2008
    Posts
    12
    Rep Power
    0

    Default

    thx Captain Morgan i have edit my "BookStore" by deleting the semicolon u told mi too and it work.. but now i have add new code then got new errors with the looping ..

    PHP Code:
    import java.util.Scanner;
    
    public class BookStore
    {
    	public static void main(String args[])
    	{
    		String nName,newAddress,receipt,customer,choice,movies,cont="N";
    	
    		int Cost,custTel;
    	
    		//int BookCata = 0;
    		String BookTitle = "";
    		//string BookAuthor = "";
    		//double BookCost = 0;
    		
    		String YesAndNo = "";
    		Scanner in= new Scanner(System.in);
    
    		
    		int NumOfBook = 15;
    		bookDetail[] book = new bookDetail[NumOfBook];
    
    		for(int i = 0; i < NumOfBook; i++)
    		{
    
    			book[i] = new bookDetail();
    
    		}
    
    		book[0].update("0001", "The Secret", "Rhonda Byrne", 10);
    		book[1].update("0002", "Secrets of Self-Made Millionaires", "Adam Khoo", 10);
    		book[2].update("0003", "An Illustrated Biography of the World’s Most Successful Investor", "Warren Buffet", 15);	
    		book[3].update("0004", "How good do we have to be ?", "Harold Kushnere", 8);
    		book[4].update("0005", "Half a Life", "V. S. Naipaul", 5);
    		book[5].update("0006", "Subconscious Mind", "Murphy McMahan", 6);
    		book[6].update("0007", "The Road Less Travelled", "M. Scott Peck", 5);
    		book[7].update("0008", "Stop the insanity!", "Susan Powter", 5);
    		book[8].update("0009", "Business As Usual", "Anita Roddick", 6);
    		book[9].update("0010", "Rich Kid, Smart Kid", "Robert Kiyosaki", 6)	;
    		book[10].update("0011", "Secrets of the Millionaire Mind", "Harv Eker", 10);
    		book[11].update("0012", "Where have all the leaders gone?", "Lee Iacocca", 15);
    		book[12].update("0013", "If success is a game, these are the rules", "Cherie Carter", 8);
    		book[13].update("0014", "Think Big", "Donald Trump", 15);
    		book[14].update("0015", "Blink", "Malcolm Gladwell", 10);
    
    		
    		
    		System.out.print("Enter the title of book: ");
    		BookTitle = in.nextLine();
    		BookTitle = BookTitle.toUpperCase();
    		
    		String CheckBookTitle = "";
    		
    		int index = 0;
    		boolean checkdata = false;
    
    		for(int i = 0; i < NumOfBook; i++)
    		{
    			CheckBookTitle = book[i].getTitle();
    			CheckBookTitle = CheckBookTitle.toUpperCase();
    			
    			if(BookTitle.compareTo(CheckBookTitle) == 0)
    			{
    				System.out.println(BookTitle.compareTo(CheckBookTitle));
    				
    				index = i;
    				System.out.println("Book title: " + BookTitle +" found");
    
    				System.out.println("Detail for the book title " + book[i].getTitle());
    				System.out.println("Author: " + book[i].getAuthor());
    				System.out.println("Catalogue " + book[i].getCata());
    				System.out.println("Cost: $" + book[i].getCost());
    				System.out.println("");
    				System.out.println(book[i].getTitle() + " Is available");
    				System.out.println("Cost to rent is " + book[i].getCost());
    
    				System.out.println("Proceed to rent? (Y/N) :");
    				choice= in.nextLine();
    				checkdata = true;
    				break;
    	
    
    		}
    		}
    
    			if(checkdata == false)
    		{
    			System.out.println(BookTitle + " is not available");
    		}
    
    
    			if(choice.equalsIgnoreCase("Y"))
    			{
    				//customer particulars
               			System.out.print("Please enter customer's name: ");
               			nName=in.nextLine();
               
              			 System.out.print("Please enter customer's address: ");
              			 newAddress =in.nextLine();
               
               			System.out.print("Please enter customer's telephone number: ");
               			custTel= in.nextInt(); 
               
    				
                    		Customer aCust = new Customer(nName,newAddress,custTel);
                    
                    
                			customer="\nPrinting out receipt for " + aCust.getName()+ "..."+ "\n" + 
                		     		"Address: " + aCust.getAddress() +"\n\n"; 
                		     	
                			receipt="Renting out " + BookTitle + " for " + " $ "+ book[i].getCost()  +"\n"+"\n"+
                			 	"\nThank You For renting our Books please come again" + "\n\nServing next customer.......";
                	
                			System.out.println(customer + receipt );
                		
              }
    		}
    }
    	
    
    		
    			if(choice.equalsIgnoreCase("N"))
    			{
    				System.out.println("Serving next customer....");
    				cont=in.nextLine();
    			
      			
    			}			
    			
    		
               	System.exit(0);
    
    			
    
            } //main
    } //class

    My program is to work like a Book rental shop.. at the start i will put type in what books the customer want (the books data are in the arrary of "BookStore"), when the book title matches with what's in my arrary , it will show the book details and asking whether the customer want to rent it or not

    if the customer want to rent it will proceed to entering customer name, addess and phone, and finally print out a receipt for the customer.

    IF customer don want to rent it it will end the loop and restart the program to the beginning

    IF the book is not found it will end the loop and restart the progam to the beginning



    Last edited by Deon; 01-27-2008 at 01:46 PM.
    I LOVE JAVA!

  4. #4
    Deon's Avatar
    Deon is offline Member
    Join Date
    Jan 2008
    Posts
    12
    Rep Power
    0

Similar Threads

  1. Question mark colon operator question
    By orchid in forum Advanced Java
    Replies: 9
    Last Post: 12-19-2010, 09:49 AM
  2. JSP Question
    By maheshkumarjava in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 03-29-2008, 11:51 AM
  3. JNI question
    By javaplus in forum New To Java
    Replies: 0
    Last Post: 12-24-2007, 11:18 AM
  4. Need help with a question please
    By sonal in forum New To Java
    Replies: 1
    Last Post: 11-29-2007, 10:17 PM
  5. question about rmi
    By leonard in forum New To Java
    Replies: 1
    Last Post: 08-06-2007, 05:19 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
  •