this is the error
C:\bbs>javac libmainsys.java
libmainsys.java:43: array required, but int found
ypub[nElems] = new libary(title, author, ypub);
^
1 error
C:\bbs>
// to run this program: C>java libmainsys
////////////////////////////////////////////////////////////////
class libary
{
private String booktitle;
private String bookauthor;
private int yearpub;
//-----------------------------------------------------------
public libary(String title, String author, int ypub)
{ // constructor
booktitle = title;
bookauthor = author;
yearpub = ypub;
}
//-----------------------------------------------------------
public void displaylibary()
{
System.out.print(" Book Title: " + booktitle);
System.out.print(", Book Author: " + bookauthor);
System.out.println(",Year Publisher : " + yearpub);
}
public String getLast() // get title
{ return booktitle; }
} // end class libary
2007-01-22
02:21:04
·
2 answers
·
asked by
Anonymous
in
Computers & Internet
➔ Programming & Design
class ArrayInOb
{
private libary[] ypub; // ref to array ypub
private int nElems; // number of data items
//--------------------------------------------------------------
public ArrayInOb(int max) // constructor
{
ypub = new libary[max]; // create the array
nElems = 0; // no items yet
}
//--------------------------------------------------------------
// put libary into array
public void insert(String title, String author, int ypub)
{
ypub[nElems] = new libary(title, author, ypub);
nElems++; // increment size
}
//--------------------------------------------------------------
public void display() // displays array contents
{
for(int j=0; j
ypub[j].displaylibary(); // display it
System.out.println("");
}
2007-01-22
02:21:54 ·
update #1
public void insertionSort()
{
int in, out;
for(out=1; out
{
libary temp = ypub[out]; // remove marked person
in = out; // start shifting at out
while(in>0 && // until smaller one found,
ypub[in-1].getLast().compareTo(temp.getLast())>0)
{
ypub[in] = ypub[in-1]; // shift item to the right
--in; // go left one position
}
ypub[in] = temp; // insert marked item
} // end for
} // end insertionSort()
} // end class ArrayInOb
////////////////////////////////////////////////////////////////
class libmainsys
{
public static void main(String[] args)
{
int maxSize = 1000; // array size
ArrayInOb arr; // reference to array
arr = new ArrayInOb(maxSize); // create the array
2007-01-22
02:22:40 ·
update #2
arr.insert("Java_how__to_program", "Patty", 2001);
arr.insert("System_Design", "Doc", 2002);
arr.insert("Program_Design", "Lorraine", 1999);
arr.insert("Computer_Architecture", "Paul", 2006);
arr.insert("Visual_Basic_How_To_ Program", "Tom", 2007);
arr.insert("Information_ Management", "Sato", 1995);
arr.insert("Sofware_ Application", "Henry", 1996);
arr.insert("English", "Jose", 1994);
arr.insert("Web_Publishing", "Minh", 1993);
arr.insert("Human_Computer_Interaction", "Lucinda", 2002);
System.out.println("Before sorting:");
arr.display(); // display items
arr.insertionSort(); // insertion-sort them
System.out.println("After sorting:");
arr.display(); // display them again
} // end main()
} // end class libmainsys
2007-01-22
02:23:02 ·
update #3