Home Answers Viewqa Java-Beginners help me to solve this problem..

 
 


siti umairah
help me to solve this problem..
1 Answer(s)      2 years and 4 months ago
Posted in : Java Beginners

Given below is a class definition for Book. Type and compile the class, and answer the following questions:

class Book { String title; //bookâ??s title double price; //bookâ??s price

public Book(String t, double p) { title = t; price = p; } public String getTitle() { return title; }

public double getPrice() { return price; } }

Write a program in a class TestBook that can do the following:

  1. Read an integer, n (representing the number of books), from the keyboard and then create an array name myLibrary of type Book with size n.

  2. Using loop, create n objects of type Book and put them in the array myLibrary after reading the title and price for each book from the keyboard.

  3. Print out the title of the book with the highest price.

  4. Print out all titles of books that contain the term â??Javaâ?? in their title.

View Answers

January 29, 2011 at 11:57 AM


Hi Friend,

Try this:

import java.util.*;

 class Book{
    String title;
    double price;
    public Book(String t, double p) {
    title = t;
    price = p; 
    } 
    public String getTitle(){
        return title;
    }
    public double getPrice(){
        return price;
    }
}

public class BookInformation{
    public static void main(String[]args){
        Scanner input=new Scanner(System.in);
        System.out.println("Enter no of books: ");
        int n=input.nextInt();
        Book myLibrary[]=new Book[n];
        for(int i=0;i<myLibrary.length;i++){
        System.out.print("Title: ");
        String title=input.next();
        System.out.print("Price: ");
        double  price=input.nextDouble();
            myLibrary[i]=new Book(title,price);
        }
        double max = Double.MIN_VALUE;
        for(int i=0;i<myLibrary.length;i++){
            if(myLibrary[i].getPrice() > max) {
                max = myLibrary[i].getPrice();
         }
        }
        for(int i=0;i<myLibrary.length;i++){
            if(myLibrary[i].getPrice()==max){
                System.out.println(myLibrary[i].getTitle()+"-"+myLibrary[i].getPrice());
            }
        }
        for(int i=0;i<myLibrary.length;i++){
            int index=myLibrary[i].getTitle().indexOf("Java");
        if(index>=0){
                System.out.println(myLibrary[i].getTitle());
        }
        }
        }   
}

Thanks









Related Pages:
help me to solve this problem..
help me to solve this problem..  Given below is a class definition for Book. Type and compile the class, and answer the following questions: class Book { String title; //bookâ??s title double price; //bookâ??s price
help me to solve this question
help me to solve this question  Write a program that inputs a series of integers into an array. The numbers are in the range 0 to 100. Calculate and display : a) The Largest number b) The Smallest Number c)The sum of the numbers
help me to solve this question...
help me to solve this question...  Given below is a class definition for Book. Type and compile the class, and answer the following questions: class Book { String title; //bookâ??s title double price; //bookâ??s
help me to solve this question
help me to solve this question   A user needs to key in data into system in order to save data into array. The data are: a. Lecturer ID, Lecturer name, School, course code, course name, session, semester A user can edit the data
Solve this problem plzzz
kindly help me and check all those files and solve my problem as soon as possible...Solve this problem plzzz  Prashant.jsp (this is my JSP file) <..." value="Click me"/> </form> </BODY>
solve this problem
in table please tell me the solution for thid problem import java.io.*; import...solve this problem  I typed this program and compiled.The program is compiled but when i eneterd url in tomcat server. Its not giving error but only
can interface solve this problem in java
can interface solve this problem in java  I have a JDialog which... this calander class. can interface solve this problem. If yes then how. pls help me   Please visit the following link: http://www.roseindia.net
Please Help To Solve My Problem
Please Help To Solve My Problem  PHP I Have 6 Textbox and 1 ok... With B Team when A Team Play With B Team Again Then Generate Error. I Am Solve This Problem With If...Else If...Else Statement But When the More Team
please help me solve this problem when i am create database connection using servlecontext
please help me solve this problem when i am create database connection using servlecontext  hi... I have create a database connection using... understand what is the problem .... the code are as follows. the servlet context
i need help to solve this problem
i need help to solve this problem  Write a stack class ArrayStack.java implements PureStack interface that reads in strings from standard input and prints them in reverse order. and Show step by step what queue will look like
help me about to solve my qustion
help me about to solve my qustion   An employee receives 15 SR per hour for the first 8 hours of week. After 8 hours (overtime) his rate becomes 20 SR per hour . Write a java class that ask a user to enter the number of hours he
please help me to solve this question about array
please help me to solve this question about array  write a program thatt stores vowels (a,e,i,o and u)in an array. Ask the user to enter any character. The program should ignore the case of that character (uppercase or lowercase
please help me to this problem..
please help me to this problem..  i wrote a program like keyboard... inside the JTextField) but i want to make this program to let me write where i clicked (i.e allows me to write any thing at the field where i clicked
help me - Java Beginners
help me  helo guys can you share me a code about Currency Conversion.Money will convert according to the type of currency.would you help me please... into 2 decimal places sample 1.25) Mexican_________ guys help me..thank
how to solve an internet connection problem
how to solve an internet connection problem  when i run my application it give me this error: Exception in thread "AWT-EventQueue-0" java.lang.UnsupportedOperationException: Not yet implemented the problem is that i don`t know
CAN ANYONE SOLVE THIS FOR ME. URGENT HELP NEEDED. PLEASE HELP
CAN ANYONE SOLVE THIS FOR ME. URGENT HELP NEEDED. PLEASE HELP   The Task Write a class whose objects will represent students. The class should have three fields for representing a studentâ??s
CAN ANYONE SOLVE THIS FOR ME. URGENT HELP NEEDED. PLEASE HELP
CAN ANYONE SOLVE THIS FOR ME. URGENT HELP NEEDED. PLEASE HELP   Write a class whose objects will represent students.The class should have three fields for representing a studentââ?¬â?¢s name, this studentââ?¬â?¢s
Help me on the given problem of String
Help me on the given problem of String  class Test { string s1="Hello",s2="lo"; System.out.println((s1=="Hel"+"lo")); System.out.println((s1=="Hel"+lo)); } The above program prints true
please help me to overcome this problem
please help me to overcome this problem  how to make it easy to write java code. can u please give me suggestions
help me
help me  Hi I'm loges. I'm doing my final year project now, I have some problem in my project and i need some help on it. NowI'm doing a site... button, and nationality I'm using dropdown list. Please help me. your kindness
Please help me to solve these programs in Python - Java Beginners
Please help me to solve these programs in Python  1. Write a program that prints an n-level stair case made of text. The user should choose the text character and the number of stairs in the stair case
Simple problem to solve - JSP-Servlet
Simple problem to solve  Respected Sir/Madam, I am R.Ragavendran.. Thanks for your kind and timely help for the program I have asked.... But in that I am facing a very very minute problem. The alert boxes are displayed
Simple problem to solve - JSP-Servlet
Simple problem to solve  Respected Sir/Madam, I am R.Ragavendran.. Thanks for your kind and timely help for the program I have asked.... But in that I am facing a very very minute problem. The alert boxes are displayed
Help me
Help me  HI I am using Tomcat6.0 this is the problem i got wen i run the code java.lang.NullPointerException org.apache.jsp.loginjsp.jspInit... in advance.   Hi Friend, Problem lies in your code. Try the following
Help me
Help me  HI I am using Tomcat6.0 this is the problem i got wen i run the code , i am using login.html ,login .jsp,login.java and web.xml code java.lang.NullPointerException org.apache.jsp.loginjsp.jspInit(login_jsp.java:23
ajax code please help to solve this........
ajax code please help to solve this.  in this i am trying to get data... null; } please help me when i am running this it show an error...;<a href="help.jsp">help instruction</a></li> <
facing problem plz help me out - Framework
Facing problem plz help me out  hi i am new to servlet i deployed... the web.xml file too parallel to the classes folder now i am facing this problem.plz tell me what to do... error:The requested resource (Servlet servlet
problem in writing coding. Please help me.
problem in writing coding. Please help me.  Hi sir, my name is Logeswaran. I have problem in writing JSP coding for my university assigments... like? I'm really stuck on this. Please help me. By the way, I'm using Access
How to solve button problem - Java Beginners
to solve this problem. Thank you Sir, Yours truly, T.Ramesh Puttaparthy...How to solve button problem  I have created button (Open File Dialog... Open Dialog Box and from that displaying image files. But problem is Iâ??ve used
plz help me for this question
plz help me for this question  Apply simplex procedure to solve the L.P.P. maximize z = 3x1 + 4x2 subject to 5x1 + 4x2 â?¤ 200; 3x1 + 5x2 â?¤ 150; 5x1 + 4x2 â?¥ 100; 8x1 + 4x2 â?­â?¥ 80, x1 â?¥ 0, x2 â?¥ 0
plz help me - Java Interview Questions
" you should solve this problem in two ways: using iteration and recursion 2...plz help me  1)Rewrite the method in exercise 10 such that it use...; if they are not equal , the problem is reduced to searching half of the array
please help me
please help me  Dear sir, I have a problem. How to write JSP coding, if a user select a value from drop down list for example department, the another... before. This name list should get from the database. Please help me. By the way, I'm
Please help me urgent...........
Please help me urgent...........  For what kind of a problem would use a Tree Set and not a Tree Map For what kind of a problem would use a Tree Map and not a Tree Set   Hello Friend, If you want to display the list
Help Me plzzz
Help Me plzzz  org.apache.jasper.JasperException: Unable to compile class for JSP Generated servlet error: D:\prash\workspace.metadata.plugins........how to solve dis error
solve it - Java Beginners
solve it  Hi friend, I want to use switch case in jsp please let me know how to call page in jsp using include tag i want call this file using include tag please help me use switch statement in jsp
help me in solving this error
help me in solving this error  Hello, i have installed tomcat 6.0, i... that problem may be in your code. So please post your code. Thanks   Hello Friend, It seems that problem may be in your code. So please post your code. Thanks
please help me here
please help me here  please show me how can this show the right output that i need please continue doing this program using only if else and do while please please" here is the problem Automatic Teller Machine [B] Balance [D
please help me here
please help me here  please show me how can this show the right output that i need please continue doing this program using only if else and do while please please" here is the problem Automatic Teller Machine [B] Balance [D
problem
problem  hi'sir mai niit student hu.mujhe java ka program samaj me nhi aata mai kya karu and mai kaise study karu please help me.   Learn Java from the given link: Java Tutorials
plz help me out with this problem...please write the program for me.thanxxxxx
plz help me out with this problem...please write the program for me.thanxxxxx  Write a program that will print out a hydro bill. The bill will be formatted as the example on the next page. The following information
plz help me out with this problem...please write the program for me.thanxxxxx
plz help me out with this problem...please write the program for me.thanxxxxx  Write a program that will print out a hydro bill. The bill will be formatted as the example on the next page. The following information
i have a problem to do this question...pls help me..
i have a problem to do this question...pls help me..  Write a program that prompts the user to input an integer and the output the number with the digits reversed. For example if the input is 12345, the output should be 54321
population problem plz help me befor 16 March 2011 !!
population problem plz help me befor 16 March 2011 !!  the Q is : How can i count how many years it will take for the population of a town to go over 30.000 .. consider that it Increases 10% every year ?? And this is my code &
Help
Help  Hi; Can anyone help me to solve this errors. I use J2ME(wirlesee Toolkit 2.5.2. for CLDC Project "SlideImageMIDlet" loaded Project settings saved Building "SlideImageMIDlet" C:\Documents and Settings\???? ?????\j2mewtk
plz help me - Java Beginners
plz help me  Thanks deepak continue response..i face some problem i hv a these file index.jsp,sessionvalid.jsp, both r store in project folder... give me reponse my persinal given id  Hi ragni, i am sending
help me in disabling checked checkboxes
as enabled. I have stuck this problem from last 2 days....so please, help me out. Thank you for your help in advance...help me in disabling checked checkboxes  <%@ page language="java
Give me the source code for this problem
Give me the source code for this problem  Ram likes skiing a lot. That's not very surprising, since skiing is really great. The problem with skiing... help to know the longest run possible with the given peaks. That altitude
plz help meto solve this question
plz help meto solve this question  for a file that exist what will be the length() method in the file class return
help me in these - Java Interview Questions
help me in these  hello every body i have some question if you cam plz answer me it is important to me and these are the questions : 1)Write... wrote in exercise 5 8)this is a classic comuter science problem called "towers

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.