File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes calling method not working Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "calling method not working " Watch "calling method not working " New topic
Author

calling method not working

Sandeep Sagar
Greenhorn

Joined: Jan 21, 2013
Posts: 2
Why it is not working , where i have been done mistake ?
public class Books {
private String book;
private int price;
private int ratings;
private String author;

public void bMethod(String book){
if(book == "Java" || book == "JAVA" || book == "java"){
price = 599;
this.book = book;
ratings = 5;
author = "Hills";
}
else if(book == "DBMS" || book == "Dbms" || book == "dbms"){
price = 799;
this.book = book;
ratings = 5;
author = "Rama Krishna";
}
}

public void setMethod(){
System.out.println("Book name is "+book+"\n Price is "+price+ "\n Rathing is "+ratings+ "\n Author is "+author);
}

}

import java.io.IOException;
import java.util.*;

public class Book extends Books {

public static void main(String[] args) throws IOException {
Book b = new Book();
Scanner scan = new Scanner(System.in);
System.out.println("Enter Book name Either Java or DBMS");
String str = scan.nextLine();
b.bMethod(str);
b.setMethod();
}

}

Output:
Enter Book name Either Java or DBMS
java
Book name is null
Price is 0
Rathing is 0
Author is null
Veerle Boer
Greenhorn

Joined: Oct 20, 2011
Posts: 13
I think you have to learn how to compare strings in Java.
Sandeep Sagar
Greenhorn

Joined: Jan 21, 2013
Posts: 2
Veerle Boer wrote:I think you have to learn how to compare strings in Java.

Thanks i got it
Veerle Boer
Greenhorn

Joined: Oct 20, 2011
Posts: 13
You're welcome!

You could also look at the Java String API to see better ways to manage the case of a string, if you want to further improve your code.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: calling method not working
 
Similar Threads
Reading and Writing serialized java Objects
address book
third attempt at solving this
Unable to figure out what is stopping my compile
how to create a linked list data structure from given code