Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-27-2008, 05:58 AM
Deon's Avatar
Member
 
Join Date: Jan 2008
Posts: 12
Deon is on a distinguished road
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 newNameString newAddressint 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 xCataString xTitleString xAuthorint 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 0NumOfBooki++)
        {

            
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 0NumOfBooki++)
        {
            
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) :");
                
choicein.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: ");
                       
custTelin.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 
__________________
I LOVE JAVA!

Last edited by Deon : 01-27-2008 at 09:21 AM.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 01-27-2008, 08:57 AM
CaptainMorgan's Avatar
Moderator
 
Join Date: Dec 2007
Location: NewEngland, US
Posts: 839
CaptainMorgan will become famous soon enoughCaptainMorgan will become famous soon enough
Send a message via AIM to CaptainMorgan
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:
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...
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
to our beloved Java Forums!
(closes on September 4, 2008)
Want to voice your opinion on your IDE/Editor of choice?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
!
Got a little Capt'n in you? (drink responsibly)
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 01-27-2008, 09:37 AM
Deon's Avatar
Member
 
Join Date: Jan 2008
Posts: 12
Deon is on a distinguished road
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 0NumOfBooki++)
        {

            
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 0NumOfBooki++)
        {
            
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) :");
                
choicein.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: ");
                       
custTelin.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



__________________
I LOVE JAVA!

Last edited by Deon : 01-27-2008 at 01:46 PM.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 01-27-2008, 04:58 PM
Deon's Avatar
Member