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 2 of 2

Thread: problem of java programing

  1. #1
    Junior Member
    Join Date
    May 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default problem of java programing

    IN THE NAME OF GOD
    hello
    this program is not run in java & i will be thanked that you answer me
    we must define 2 class named book that have name of book id number of book & it price &class bookstore that has its name & we must define 2 object of bookstore & print the name of bookstore that has the most price of its books.
    class book
    {
    private String name;
    private String idnum;
    private int pri;
    public void setb(String n,String id,int p)
    {name=n;
    idnum=id;
    pri=p;}

    book(String cn,String cid,int cp)
    {setb(cn,cid,cp);}

    public String getname()
    {return name;}

    public String getidnum()
    {return idnum;}

    public int getpri()
    {return pri;}

    public String toString()
    {return name+" "+idnum+" "+pri;}

    public int f(book []b)
    {

    int sum=0;
    for(int i=0;i<2;i++)
    sum+=b[i].pri;
    return sum;
    }}
    class bookstore
    {
    bookstore()
    {}
    private book b;
    private String namestore;
    public void set(String n,book l)
    {
    namestore=n;
    b=b.setb(l);}
    bookstore(String cn,book cl)
    {set(cn,cl);}

    public int compareto(bookstore s)
    {
    return sum-s.sum;
    }

    public String toString(book l)
    {return namestore+" "+l.toString;}
    }
    class B
    {
    public static void main(String []w)
    {
    book []c=new book[2];
    book []b=new book[2];

    bookstore b1=new bookstore("fg",b);
    bookstore c2=new bookstore("gf",c);

    b[0]=new book("b1","1",100);
    b[1]=new book("b2","12",120);
    c[0]=new book("c1","2",106);
    c[1]=new book("c2","21",190);

    if(b1.compareto(c2)>0)
    System.out.println(b1);
    else System.out.println(c2);
    } }


  2. #2
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: problem of java programing

    Welcome mahnaz

    Please see the announcements page for the use of code tags and other helpful information.

    Does the code compile or are there compile errors? Post the full text of any error message with the code and question.
    What is your question with the code?

Similar Threads

  1. Java programing style
    By maple1100 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: January 5th, 2013, 05:24 PM
  2. Is AJAX related with java programing or .Net?
    By sagar124 in forum Java Theory & Questions
    Replies: 1
    Last Post: December 26th, 2012, 11:28 PM
  3. Java programing help plz!
    By qazwsx in forum Java Theory & Questions
    Replies: 1
    Last Post: July 21st, 2012, 07:01 PM
  4. need help with Doubly-Linked list programing in java
    By bulutbey in forum Algorithms & Recursion
    Replies: 3
    Last Post: August 22nd, 2011, 01:51 PM
  5. java thread programing.
    By parisa in forum Member Introductions
    Replies: 1
    Last Post: July 26th, 2011, 01:38 PM