I've tried and tried to get my java coding to work, but it's just not working....
I'm trying to add, remove, and search in an array.
For the adding, I am reading 3 strings from a user, verifying them, then making them into one object and then putting them into the array. The removnig/selling and I just don't know how to do it.
Help is so much appreciated. I pray for someone to help me with this. I would love them forever. <3
import java.io.*;
import java.util.*;
publicclass BookStore {
static InputStreamReader isr = new InputStreamReader(System.in);
static BufferedReader br = new BufferedReader(isr);
publicstaticvoid main (String [] arg) throws Exception {
finalint iSize = 200;
Book book = new book (iISBN, sTitle, iQuantity);
String [] arrayBook = new String[iSize];
arrayBook[i] = book;
//I have a switch statement for the menu, but took it out to save the space
}//close main
publicstaticvoid addBook() throws Exception {
for (int i = 0; i<arrayBook.length; i++) {
//getting the ISBN number
boolean bISBN = false;
while(!bISBN) {
System.out.print("Enter the ISBN number: ");
String sISBN = br.readLine();
sISBN = sISBN.trim();
try {
int iOtherISBN = Integer.parseInt(sISBN);
if(iOtherISBN >= 0 && iOtherISBN <= 199) {
bISBN = true;
}//end if
}//end try
catch (NumberFormatException nfe) {
System.out.println("Number not within 0-199, back to the menu.");
bISBN = false;
}//end catch
}//end while
//getting the Title
boolean bTitle = false;
while(!bTitle) {
System.out.print("Enter your Title: ");
String sOtherTitle = br.readLine();
sOtherTitle = sOtherTitle.trim();
if(sOtherTitle.length !=0) {
bTitle = true;
}//end if
else {
System.out.println("Your title is blank, go back to the menu");
bTitle = false;
}//end else
}//end while
//getting the quantity
boolean bQty = false;
while(!bQty) {
System.out.print("Quantity of books: ");
String sQty = br.readLine();
sQty = sQty.trim();
try {
int iOtherQuantity = Integer.parseInt(sQty);
if (iOtherQuantity >=0) {
bQty = true;
}//end if
else {
System.out.println("Your number is negavtive, go back to menu.");
bQty = false;
}//end else
}//end try
catch (NumberExceptionFormat nfe) {
System.out.println("You did not enter a number, back to the menu you go.");
bQty = false;
}//end catch
if(arrayBook[iISBN] ==null) { //checking if there's a book already
arrayBook[iISBN] = new book();
}//close if
else {
System.out.println("Book exists in there, cannot add, try again.");
} //end else
arrayBook[i] = new Book; //No idea how to add the object into the array
}//end for
}//close addBook
//adding more copies to an exsiting book
publicstaticvoid addMore(int iISBN, int iQuantity) throws Exception {
for(int i = 0; i<arrayBook.length; i++) {
if(iISBN !=null) {
iQuantity = iQuantity + iOtherQuatity;
}//end if
else {
System.out.println("There's no book here.");
}//end else
}//end for
}//close addMore
//selling books
publicstaticvoid sellBook(int iISBN, int iQuantity) {
for (int i = 0; i<arrayBook.length; i++) {
if(iISBN != null) {
if(iQuantity <= iOtherquantity) {
iQuantity = iQuantity - iOtherQuantity;
}//end if
else {
System.out.println("There's only " + iQuantity + " amount of books left.");
}//end else
else {
System.out.println("There's no book.");
}//end else
}//end for
}//end sellBook
//searching for a book by the Title
publicstaticvoid findBook(String sOtherTitle) {
for (int i = 0; i<arrayBook.length; i++) {
//I have absolutely no clue how to search the array by the title
}//close find
}//close class