Help require ><

import java.io.*;

import java.util.*;

import javax.swing.*;

class BookEnquirySystem {

private Book[] bookArr;

int mMenuChoice;

BufferedReader input;

public BookEnquirySystem() throws IOException {

input = new BufferedReader(new InputStreamReader(System.

in));

BufferedReader infile = new BufferedReader(new FileReader(

"bookInfo.txt.")); ;

int size = bookArr.length;

bookArr = new Book[8];

// create the book array.

for (i = 0; i < bookArr.length; i++) {

String s = infile.readLine();

StringTokenizer st = new StringTokenizer(s, "|");

String title = st.nextToken();

String edition = st.nextToken();

String author = st.nextToken();

String Isbn = Integer.parseInt(st.nextToken());

String publisher = st.nextToken();

listPrice = Double.parseDouble(st.nextToken());

sellingPrice = Double.parseDouble(st.nextToken());

bookArr = new Book[8];

// create the Book object and place it in the array.

} //end of for-loop

infile.close();

}

// close the input file after reading.

public void displayMainMenu() {

String menuStr = "";

menuStr += "Main Menu\n";

menuStr += "=======================\n";

menuStr += "1.Display All Books/n";

menuStr += "2.Display All Titles for Selection/n";

menuStr += "3.Search By Author/n";

menuStr += "0. Quit\n";

menuStr += "Please enter your selection or (0) to quit";

boolean inputOK;

do {

inputOK = true; // assume user will input a valid input.

try {

mMenuChoice = Integer.parseInt(input.readLine());

// read in input using input.

} catch (NumberFormatException e) {

inputOK = false; // input is invalid.

JOptionPane.showMessageDialog(null,

"Please enter an integer for Main Menu choice");

}

} while (mMenuChoice < 0 || mMenuChoice > 3); // input is invalid.

}

public void displayAllBooks() {

char bookchoice;

for (int i = 0; i < bookArr.length; i++) {

System.out.print((i + 1) + " of " + size + "\n");

System.out.println("=================================" + "\n");

System.out.println(bookarr[0].formatDetail);

System.out.println("N for Next Book");

System.out.println("P for Previous Book\n");

System.out.println("M for main menu");

} //close for loop

bookchoice = JOptionPane.showInputDialog("Enter N for Next Book" + "\n" +

"Enter P for Previous Book" +

"\n" +

"Enter M for Main Menu" + "\n");

if (bookchoice == N){

System.out.print((i + 1) + " of " + size + "\n");

System.out.println("=================================" + "\n");

System.out.println(bookarr[0+1].formatDetail);

System.out.println("N for Next Book");

System.out.println("P for Previous Book\n");

System.out.println("M for main menu");

}

else

if (bookChoice == P){

System.out.print((i + 1) + " of " + size + "\n");

System.out.println("=================================" + "\n");

System.out.println(bookarr[0-1].formatDetail);

System.out.println("N for Next Book");

System.out.println("P for Previous Book\n");

System.out.println("M for main menu");

}

else if (bookChoice == M){

return displayMainMenu();

}

}

public void displayTitleforSelection() {

titleChoice = Integer.parseInt(input.readLine());;

do {

System.out.println("Book Title Selection Menu\n");

System.out.println( "=======================\n");

for (int i=0; i<bookArr.length; i++) {

System.out.println((i+1) + ". " + bookArr.getTitle() + "\n");

}

System.out.println("0. Quit\n");

System.out.println("Please enter your selection or (0) to quit");

// invoke displayMenu() method

if (titleChoice > 0 || titleChoice >= bookArr.length)

JOptionPane.showMessageDialog(null, "Please enter 0 to " + bookArr.length);

} while (titleChoice < 0 || titleChoice >= bookArr.length);

}

void displaySearchByBookAuthor() {

}

void runSystem() {

do {

displayMainMenu();

if (mMenuChoice == 1) { //display all books

return displayAllBooks();

} else if (mMenuChoice == 2) { //display all titles

return displayTitleforSelection();

;

} else if (mMenuChoice == 3) { //search by author

;

}

} while (mMenuChoice >3 || mMenuChoice < 0);

} //end of BookEnuirySystem

} //end of class

[4666 byte] By [Sengaporea] at [2007-11-27 11:43:00]
# 1

> Help require ><

Code formatting require.

Question require.

~

yawmarka at 2007-7-29 17:47:23 > top of Java-index,Java Essentials,New To Java...
# 2

Turn the doo-dads the other way round, flip the triclops switch and flurtle your dunbats. Job's a good 'un

georgemca at 2007-7-29 17:47:23 > top of Java-index,Java Essentials,New To Java...
# 3

class Book { //start of class

private String title;

private String edition;

private String author;

private String isbn;

private String publisher;

private double listPrice;

private double sellingPrice;

public Book(String title, String edition, String author, String isbn,

String publisher, double listPrice

, double sellingPrice) {

this.title = title;

this.edition = edition;

this.author = author;

this.isbn = isbn;

this.publisher = publisher;

this.listPrice = listPrice;

this.sellingPrice = sellingPrice;

}

public String getTitle(String title) {

return this.title;

}

public String getEdition(String edition) {

return this.edition;

}

public String getAuthor(String author) {

return this.author;

}

public String formatDetail() {

String resultStr = "";

resultStr += "=================================\n";

resultStr += "Title : " + this.title + "\n";

resultStr += "Edition : " + this.edition + "\n";

resultStr += "Author : " + this.author + "\n";

resultStr += "Publisher : " + this.publisher + "\n";

resultStr += "Listprice : " + this.listPrice + "\n";

resultStr += "SellingPrice : " + this.sellingPrice + "\n";

resultStr += "=================================\n";

resultStr += "Enter N for Next page\n";

resultStr += "Enter P for Previous page\n";

resultStr += "Enter M for Main page\n";

return resultStr;

}

}

Sengaporea at 2007-7-29 17:47:23 > top of Java-index,Java Essentials,New To Java...
# 4

> > Help require ><

YODA!

BigDaddyLoveHandlesa at 2007-7-29 17:47:23 > top of Java-index,Java Essentials,New To Java...
# 5

Still no formatting tags. Still no question.

Please try harder.

cotton.ma at 2007-7-29 17:47:23 > top of Java-index,Java Essentials,New To Java...
# 6

> please try harder

for inspiration:

http://en.wikipedia.org/wiki/Thomas_the_Tank_Engine

TuringPesta at 2007-7-29 17:47:23 > top of Java-index,Java Essentials,New To Java...
# 7

>> private Book[] bookArr;

@op, why are you storing the book collection in an array?

you should probably use a Collection like an ArrayList.

TuringPesta at 2007-7-29 17:47:23 > top of Java-index,Java Essentials,New To Java...
# 8

>> int size = bookArr.length;

>> bookArr = new Book[8];

@op, what is that line supposed to do? you are asking for the

array's size before you even initialize it on the next line.

TuringPesta at 2007-7-29 17:47:23 > top of Java-index,Java Essentials,New To Java...
# 9

> > please try harder

>

> for inspiration:

> http://en.wikipedia.org/wiki/Thomas_the_Tank_Engine

Or better

http://en.wikipedia.org/wiki/The_Little_Engine_That_Could

cotton.ma at 2007-7-29 17:47:23 > top of Java-index,Java Essentials,New To Java...
# 10

haha, i thought they were one in the same.

i need to revisit my earliest studies...

TuringPesta at 2007-7-29 17:47:23 > top of Java-index,Java Essentials,New To Java...
# 11

Some comments about your program:

Formatting

1. Use tabs or spaces

2. When you post code in this forum click the code button and also use the preview button

Debugging

The BookEnquirySystem has many compiler-errors. When you write a program you should begin with thinking and then implementing small pieces at a time. For example, when you try to make this program work you could do like this:

1. comment every method except the constructor.

2. Try to compile - it won't work - make the code correct

3. Then add a main method and let it make an BookEnquirySystem -object. (inside a try -catch)

public static void main(String[] args){

try {

BookEnquirySystem b = new BookEnquirySystem();

}

catch(Exception e){

System.out.println("Exception in main: " +e);

}

}

4. compile (make the code correct)

5. Try to run - you will get an exception - try to fix the code...

6. Make the for-loop print the Strings or make the for-loop call the method formatDetail and print what it returns so you can see it works correct.

7. make everything in this method work correct

...

8. start with next method /next bit of code/ next task you want the program to perform

- and so on until you are done

You can ask in the forum if you have any specifik questions

There are so many errors I cannot tell you all, and I dont think any other here will either. But I think if you know what you want to do - and if you let it take some time - and if you do one task in a time - then you will be able to do it! (It's not hard you know)

Well, this looks llike a school exercise but I dunno. Good luck any way!

Ja_Lava_Javaa at 2007-7-29 17:47:23 > top of Java-index,Java Essentials,New To Java...
# 12

> Some comments about your program:

>

> Formatting

> 1. Use tabs or spaces

> 2. When you post code in this forum click the code

> button and also use the preview button

>

> Debugging

> The BookEnquirySystem has many compiler-errors. When

> you write a program you should begin with

> thinking and then implementing small pieces at

> a time. For example, when you try to make this

> program work you could do like this:

> 1. comment every method except the constructor.

Pointless. What for? Comments suck, they rarely add any value, and if your code needs them, generally it's because the design sucks. Code can be written to be self-documenting (some corner cases aside). Which is better?

this

// takes an array of ints and returns the mean of them

public long doAvg(int[] args) { // code }

or this

public long getMeanAverage(int[] args) { // code }

What if the code changes what it does, but the comment is left as-is? Seen that happen loads. Comments are just something else that can go out of date, and people are often too afraid to change them. Don't bother with them unless they're absolutely necessary. I'd rather refactor a method than comment it

georgemca at 2007-7-29 17:47:23 > top of Java-index,Java Essentials,New To Java...
# 13

I disagree, comments are necessary when you write code for someone and the person reading/maintaining it doesn't know english.

In general, I'd prefer your style to the use of comments, I generally don't need them to read my own code, but the same can't always be said for someone else (reading my code).

Commenting on methods like doAvg is pointless anyway, because the calculation is simple enough to be explained in the few words you used.

lance_dragonsa at 2007-7-29 17:47:23 > top of Java-index,Java Essentials,New To Java...
# 14

> I disagree, comments are necessary when you write code for someone

> and the person reading/maintaining it doesn't know english.

Тревога с комментариями сочинительства что она представляет блок текста к потребителю для того чтобы понять, и потраченное время делающ то более лучше потрачено понимая Кодего сразу. Я изображение чонсервной банкы это только более плох если вы не в языке комментария.

BigDaddyLoveHandlesa at 2007-7-29 17:47:23 > top of Java-index,Java Essentials,New To Java...
# 15

What language is that?

I put it into babelfish as Russian and got this translation:

"Anxiety with the commentaries of writing that it presents the block of text to the user in order to understand, and the spent time of delayushch the more better spent understanding Kodego immediately. 4 image of chonservnoy banky this are only more than plokh if you not in the language of commentary."

TuringPesta at 2007-7-29 17:47:27 > top of Java-index,Java Essentials,New To Java...
# 16

Comrade, it is Russian. Now we must drink wodka!

BigDaddyLoveHandlesa at 2007-7-29 17:47:27 > top of Java-index,Java Essentials,New To Java...
# 17

You speak russian, lol? I thought you were indian or something?

And you lived in france?

Are you are a secret agent, lol? Or just a polyglot?

TuringPesta at 2007-7-29 17:47:27 > top of Java-index,Java Essentials,New To Java...
# 18

> Comrade, it is Russian. Now we must drink wodka!

В Совет Россия водочка пить вы!

cotton.ma at 2007-7-29 17:47:27 > top of Java-index,Java Essentials,New To Java...
# 19

> You speak russian, lol? I thought you were indian or

> something?

Bablefish can translate TO Russian as well as FROM Russian :)

> And you lived in france?

>

> Are you are a secret agent, lol? Or just a polyglot?

If he lived in France, almost certainly. Half the population there are French secret agents keeping taps on the other half who are secret agents from all other countries keeping taps on the French.

jwentinga at 2007-7-29 17:47:27 > top of Java-index,Java Essentials,New To Java...
# 20

> You speak russian, lol?

See Babelfish comment. I was just teasing Comment Boy. The idea

that comments are even more needed when you don't speak the language

seemed farcical to me.

> I thought you were indian or something?

Can't an Indian speak Russian ;-)

I just like Indian food, and also filestream and I get into some chapatti-slapping contests.

My wife's family is Mauritian, and their food is a mix of Indian,

Chinese, African and French. Sunday was had Octopus Curry -- funky.

> And you lived in france?

I never wrote that I lived in France.

> Are you are a secret agent, lol? Or just a polyglot?

Well, I don't speak Groovy.

BigDaddyLoveHandlesa at 2007-7-29 17:47:27 > top of Java-index,Java Essentials,New To Java...
# 21

> Well, I don't speak Groovy.

I dunno. You speak fairly groovy, you crazy cat

georgemca at 2007-7-29 17:47:27 > top of Java-index,Java Essentials,New To Java...
# 22

> > Well, I don't speak Groovy.

>

> I dunno. You speak fairly groovy, you crazy cat

<finger-snap/>

Bury you now, dig you later.

<finger-snap/>

BigDaddyLoveHandlesa at 2007-7-29 17:47:27 > top of Java-index,Java Essentials,New To Java...
# 23

> > 1. comment every method except the constructor.

>

> Pointless. What for? Comments suck, they rarely add

> any value, and if your code needs them, generally

> it's because the design sucks.

georgemc, You misunderstood my intention, I only wanted to comment everything to be able to compile (instead of deleting every line) - of corse I do not recommend any one to add a comment after every statement!

You are right about self-documenting code (good arguments too) - In a perfect world there would be no other kind of code.

Message was edited by:

Ja_Lava_Java

Ja_Lava_Javaa at 2007-7-29 17:47:27 > top of Java-index,Java Essentials,New To Java...
# 24

> Bury you now, dig you later.

#! /usr/bin/groovy

graveyard = []

def bury(whom) {

graveyard << whom

}

def dig(whom) {

graveyard.remove(whom)

}

bury('you')

assert graveyard == ['you']

Thread.sleep(1000)

dig('you')

assert graveyard == []

~

yawmarka at 2007-7-29 17:47:27 > top of Java-index,Java Essentials,New To Java...
# 25

The Groovy Fu runs strong in you. I think that if I met you, you would

resemble "The Blind Kung Fu Master":

http://www.metacafe.com/watch/244711/blind_kung_fu_master/

BigDaddyLoveHandlesa at 2007-7-29 17:47:27 > top of Java-index,Java Essentials,New To Java...
# 26

> The Groovy Fu runs strong in you.

I am but a grasshopper.

~

yawmarka at 2007-7-29 17:47:27 > top of Java-index,Java Essentials,New To Java...
# 27

> georgemc, You misunderstood my intention, I

> only wanted to comment everything to be able to

> compile (instead of deleting every line) -

In that case I'd delete every line. Commented out code is a code smell. Either you want the code, or you don't. If you're commenting everything out "to get it working" the code you're commenting is probably worthless anyway

> corse I

> do not recommend any one to add a comment after every

> statement!

>

> You are right about self-documenting code (good

> arguments too) - In a perfect world there would be

> no other kind of code.

Doesn't need to be a perfect world. Do it now

georgemca at 2007-7-29 17:47:27 > top of Java-index,Java Essentials,New To Java...
# 28

Werent there other replies?

Why did they get deleted?

EDIT: freaky. it kept coming up as 19 replies only.

i refreshed and reloaded the page too. oh well.

TuringPesta at 2007-7-29 17:47:27 > top of Java-index,Java Essentials,New To Java...
# 29

> Werent there other replies?

> Why did they get deleted?

>

> EDIT: freaky. it kept coming up as 19 replies only.

> i refreshed and reloaded the page too. oh well.

that's been happening w/ me too lately i have been having problems with the forum pages

mark07a at 2007-7-29 17:47:27 > top of Java-index,Java Essentials,New To Java...