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

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 Tutorials/Questions & Answers:
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
Advertisements
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
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
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
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
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 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
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 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
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
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
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
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
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
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
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
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 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
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>
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
help me
help me  i have done as u directed but nothing happens gud to me..... . i am using netbeans is that matter at all help me and take me out from trouble where to store jfree api to use it for j2ee based project
help me
help me  HI. Please help me for doing project. i want to send control from one jsp page to 2 jsp pages... is it possible? if possible how to do
help me
help me  please send me the java code to count the number of similar words in given string and replace that word with new one
help me
help me  hi sir pls tell me how to use ajax form validatin from very simple way with two ot three text field pls help me use ajax in php my email id is:- [email protected] pls sir give me some vasic information i know
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
help me..
help me..   what are the component needed by grid computing, cloud computing and ubiquitous computing? discuss about the security of above computing. difference between that 3 computing
help me
help me  MY GLASSFISH SERVER NOT START PROPERLY help me warning shows DPL5404:Specification-Version for the optional package [ GNUJAXP ] in the jarfile [ C:\Program Files\Java\jdk1.7.0_02\jre\lib\ext\gnujaxp.jar
help me...
help me...  Write a program that inputs four words and them displays all possible permutations of the words. So, for example, if the words mad, dog, bites and man are entered, then the following are output : man bites mad dog
help me..
help me..  Write a program that inputs four words and them displays all possible permutations of the words. So, for example, if the words mad, dog, bites and man are entered, then the following are output : man bites mad dog mad
help me...
help me...  there is the picture given - cat - dog - rabbit - mouse a. create a class name b. create its attributes (at least 3 attributes) : species, size, leg c. create its methods ( at least 3 methods) : walk, eat, sleep
help me..
help me..  Design and write a class named Person and its two subclasses named Student and Employee. Make Lecturer and Admin subclasses of Employee. A person has a name, address, phone number and email address. A student has
help me
help me
Help me
Help me  HI I am using Tomcat6.0 this is the problem i got wen i run the code java.lang.NullPointerException..., Problem lies in your code. Try the following code: 1)login.jsp: <html>
help me
the order, Fourth button is Find length of text. and there are panels. Please help me...help me  Dear sir/medam i would like to know how to use the java string class method my programm have four button,(enter the text) that first
Help me
Help me  Hi, LWUIT is working in eclipse j2me for Symbian OS
help me
help me  how to print from a-z, A-Z with exact order using for loop? Thanks for all concern
Help Me
Help Me  What is the source code for Sample example for Mortgage Calculator in J2ME language for developing Symbian
Help me
Help me  plz i want code of program to add real numbers and magic numbers in java example this input :- 5+3i-2+3i output:- 3+6i
help me
help me  pls... xplain dis code:- function go() { window.location.replace("logout.jsp",'window','toolbar=1,location=1,directories=1,status=1,menubar=1,scrollbars=1,resizable=1'); self.close
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
Help me
Help me  hello!!!!. i have a Excel file which includes 4 columns and somewhat 8500 rows.these rows i have printed in SQL thru Excel file and i have 1 MYSql database which includes all those 4 fields i have defined in excel file
help me
help me  I have a quastion a bout array whic is>>> 1-write aprogram to diplay a multiplication table for 1to 10 by entering the start number and the end number. EXAMPLE: ENTER START NUMBER:1 ENTER END NUMBER:3
help me
help me  Create a GUI application that allows a user to select a text file (using the JFileChooser). The program will then allow the user to do the following operations (selection of these operations must be made by clicking
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 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

Ads