In: Computer Science
Im trying to create a book list. I started off like this but idk how to continue?
public static int [] BookList (String title, String author, int price, int copies, String category) {
}
I don't know what to do next in order to list a set of (lets say 5 ) books and how to call it in the main (public static void main(String[] args))method
public static int [] BookList (String title, String author, int price, int copies, String category) {
}
Return list type cannot int because we have both Strings and int values in method.To combine the values and to return the list,List type should be String.I have given the code to call the method from main method.
Java Code :
import java.lang.*;
class Books{
public static String []BookList(String title,String
author,int price,int copies,String category){
String list[] = new
String[5];
list[0] = title;
list[1] = author;
list[2] =
String.valueOf(price);
list[3] =
String.valueOf(copies);
list[4] = category;
return list;
}
public static void main(String args[]){
String list[] = new
String[5];
list = Books.BookList("Wings of
Fire","A.P.J.Abdul Kalam",400,10,"Autobiography");
System.out.println("Book
Details\n");
System.out.println("Title : " +
list[0]);
System.out.println("Author : " +
list[1]);
System.out.println("price : " +
list[2] + " Rupees");
System.out.println("Copies : " +
list[3]);
System.out.println("Category : " +
list[4]);
}
}
Output :
Please Up vote.Thank You.