I've been assigned the task of developing a simple Java program based on following:
Write an algorithm to search for reserved book copies, from a list (array) of books using Linear Search, and then store them at the beginning of a newly created array, using an insert algorithm.
I have written the algorithm, but I'm struggling to demonstrate it due to a problem with the last line of the following code:
package javaapplicationadt2;
public class Books
{
public String ISBN; // class properties
public String title;
public int copies;
boolean reserved = true;
public static void main(String[] args)
{
Books[] Book1 = new Books[1];
Books[] Book2 = new Books[1];
Book1[0].ISBN = "ISBN-00001";
Book1[0].title = "Algorithms that torture minds";
Book1[0].copies = 2;
Book1[0].reserved = true;
Book2[0].ISBN = "ISBN-00002";
Book2[0].title = "Lecture Slides that defied practical Java Programming !";
Book2[0].copies = 1;
Book2[0].reserved = false;
for (int i = 0; i < Book1.length; i++)
if (Book1[i].reserved = true)
for (int j = Book2.length - 1; j > 0; j++)
Book2[j] = Book2[j - 1];
*Book2[0] = Book1[i].title;* **(Incompatible types:
Books cannot be converted to a String)**
}
}