javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

First of all this is a 11 month-old thread.
Second, do you understand why what you have written is wrong? Also the OP has already figured out his problem. You hardly made any contribution

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

i know that you cant use Arrays.sort since it will only compare the one City array object

What do you mean by that? Aren't you going to save all the City objects into one array?

City [] cities = new City[10];

Arrays.sort(cities);

Maybe I am missing something. Can you describe better where are you having problem

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster
CE emp1 = new CE("Martin", "Sheen", "420", 0.2, 100000);
public CE(String fName, String lName, String secu, float commRate, float grossSales)

When you write: 0.2 java interprets it as a double. But your constructor accepts a float. So you need to "tell" java to treat 0.2 as a float not a double:

CE emp1 = new CE("Martin", "Sheen", "420", 0.2F, 100000);
BCE emp2 = new BCE("Rachael", "King", "421", 0.2F,100000, 2000);
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I have a few extra suggestions, but I didn't have time to post them because I was hungry.

First:

String musicCd[] = { "Fergie", "Celine Dion","Kelly Clarkson", "Chris Daughtry"};
double count[] = {5, 7, 3, 8};
double price[] = { 19.95, 21.99, 16.50, 21.75};

Arrays.sort(musicCd);

As you can see you sort the musicCD array but the other arrays are left unchanged. If we assume that initially you meant that:
Fergie, 5, 19.95
Celine Dion, 7, 21.99

Then after the sort the elements at the array will change order but the elements at the other arrays will not and will not correspond to the right title.

One way to fix this is write your own sorting method (bubblesort) to sort the musicCD array (use the compareTo method of the String class) and whenever you swap 2 elements do the same with the other arrays.

Second:
Did you understand the above suggestion? . . . Yes? . . Ok, now forget the above suggestion because:
There are 3 ways to do things:
The right way,
The wrong way,
And the Object Oriented Way

And the above doesn't use the OO Way.
You need an Object to represent a music CD. Try this:

public class MusicCD {
    private String title = null;
    private int count = 0;
    private double price = 0.0;

    public MusicCD() {
        
    }

    public MusicCD(String title, int count, double price) {
        setCount(count);
        setTitle(title);
        setPrice(price);
    }

    /**
     * …
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I think that because you do something like this:

String musicCd[] = { "Fergie", "Celine Dion","Kelly Clarkson", "Chris Daughtry"};

public void musicCd() {

}

Maybe because you are using the same name. I am not sure but you might want to test it

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

And to complete rapture's suggestion, try writing and TESTING small pieces of.
Break down he assignment into small pieces of code and test them individually.
You have written lots of stuff and you didn't explain what is the problem.
I have noticed that you read and write from files.
>Create separate classes that read and write to files. Test them using some dummy values. Create some objects with values and try to read and write. When that is done,
> Try in a different class to have methods that do what you described at the List you implemented, When that is done,
>Combine the above classes so that the List is written and read from the file.
> Then after the above work and tested, write the main method

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

First you need to define what kind of structure to use in order to represent your tree. An array for example. Then you write code that inserts and reads the data, at and from the right place

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Well the error is very simple. You should have figured it out form the compile message. Understanding compile messages is very important if you want to learn programming.

import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;

You import those classes. You must also import the StringTokenizer

import java.util.StringTokenizer

When you are having problems with a class, always check the API. There you will find all the methods of the class and what it can do.
http://java.sun.com/j2se/1.4.2/docs/api/java/util/StringTokenizer.html

Also it is recommended by others in this forum to use the spilt method of the String class:
String.split()

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Try this, although I am not sure since I have never used the "include" tag like this: <%@ include file="<%= somepage%>" %>

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Of course, but we need more info (as my first reply, sarcastically, implied). Post all error/compiler messages, post your code, and post what the program produces and what it is suppossed to produce.

As masijade said, you failed to tell us what errors do you get. You are not going to correct you entire project. That is your teacher job.
What errors do you get?
Where?
State specific lines, error messages!
What it does and what it is supposed to do?

We do not spend our lives by fixing other people's problems for free. Why should we bother to read and understand this mess when you are not making an effort to explain anything

Also:

You can obtain these
classes from your lecturer.

If I assume correctly, you were given these classes by your teacher. Your job was to understand them. Then it would be easy to complete the project. All you did was post some code without explaining which part doesn't work

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Save the sums into 2 different 1-D arrays and when you loop the 2-D array to display the elements display next to each row (row i) the value at "i" of the rowSum array.
And that loop finishes, have another loop that prints 1 more line with sums from the other 1-D array (colSum)

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

3 suggestions:

Try printing the query and then run it at your database to see if it actually updates. Maybe the WHERE clause is false

Maybe I am wrong, but try first to close the statement and the connection and redirect

And finally:
THIS IS THE MOST IMPORTANT:
Delete everything and start all over again, but this time follow the instructions from this link:
http://www.daniweb.com/forums/thread141776.html
It is at the top of the JSP forum. You should be reading other posts to see if that have something about your problem and that post tells you exactly how to do things

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Yes! I've got it! I was able to modify the code that you gave to compute for the sum per column. Now my problem is, I don't know how to include those sums in my array wherein i have to put all the sum per row to the right and all the sum per column at the bottom of each column in my array and display it in a tabular format. How will i do that? Please help me. Thanks!=)

You need to better explain what you need to do

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I can't think of a way to do that. I mean, how to calculate the sum per row and per column. I don't know how. Please help me. Thank you.

Apparently you don't read other people's posts, because I have just explained how to do this, and I have posted 2 pieces of code, which I have told you to run them.

Did you follow the steps I described?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

First of all the name of the select is: "selectPrimaryKey", so you will need something like this:

String nval=request.getParameter("selectPrimaryKey");

Also the select needs 1 minor change:

............
 <select name="selectPrimaryKey">
<option>SelectValue</option>
<%
for (int i = 0; i < Nheadlist.size(); i++) {
	%>
<Option value="<%= Nheadlist.get(i)%>" >
      <%= Nheadlist.get(i) %>
</Option>
<%
}
%>
</select>
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Ei can you help me? what's wrong with my program? i think there's something missing. Please help! Thanks!

I was busy that's why I couldn't reply.
As for your code:

for(x = 1; x < 5; x++)
    for(y = 1; y < 6; y++)
    sum = sum + array[x][y];

   System.out.print(sum + "   ");

You successfully calculate the sum of all the salesmen for all the products. Now, you will need per salesman and per product.
Therefor you will need to calculate for each row and each column the sum

for(x = 1; x < 5; x++) {
    sum = 0 ;

    for(y = 1; y < 6; y++) {
       sum = sum + array[x][y];
    }

System.out.println("X: "+x+". Sum= "+sum);
}

Try, after running the above code to understand what it does, by comparing the results to the values the array has. As you can see for each row (X) you calculate the sum (inner loop) and the you print it. Then when you go to the next line (outer loop) you reset the sum (sum=0) in order to add only the elements of the next line (X) you are now.

Try running the code by hand. It will help you understand it better.
Then all you need to do is modify the above code so you will get the sum per column

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Could you create them using 'Pools Tab' code as a blueprint so the programming outline in all the tabs look similar if at all possible?

Yes, rapture he was asking for us to complete his code. But if he has already done part of it, he can try and do the rest and we will help with problems he is having, provided of course we see some code

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I already told you how. Call the method I told you. It is not very hard to figure out what the argument should be. You said yourself what you want to check if it is an int or not

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

If you search the internet (Yahoo) for:

java API BufferedReader

you will find the API of BufferedReader with all possible constructors.

Also what do you mean read from a variable. If you want a variable to be the input of the constructor, that variable will have to be one of types that the constructor accepts

InputStreamReader inputreader = ......

BufferedReader console=new BufferedReader(inputreader );

The constructor:

InputStreamReader(InputStream in)

Takes as argument an InputStream. Again if you check the API you will see that java.io.InputStream is an abstract class. So you might want to check the API for all know subclasses of that class.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You can use the method: Integer.parseInt

String s = "12";
try {
  int i = Integer.parseInt(s);

//do calculations here
} catch (NumberFormatException nfe) {
  
}

If s is not an integer then the method will throw an exception. So call the method I told you and if it is an int then continue doing whatever you want with the value. If it is not then the code will continue inside the catch.

You might want to search the internet for Exception handling tutorials

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

First of all you don't say which tabs you couldn't do. Yes you did the Pool tab on your own, but which tabs you did and work and which don't work?
So I would suggest to post the code of the tab that you are having problem with.
ONE tab at a time. Describe what is your problem, the errors you get, what the tab currently does and what it should do

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I usually use javascript to manipulate the state and value of the input fields. Haven't combined it with tables.
But I would suggest to post the code you have for the table as well as the javascript code and describe what you are trying to accomplish. If I know it I will reply

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

a. The salesperson number
b. The product number
c. The total dollar value of that product sold that day

Apparently the rows (1 to 4) will be the salesperson number.
The columns (1 to 5) will be the product number
And the elements of the array will be the total dollar value of that product sold that day

So this:
array[2][3] = 100
Will mean that last month the salesperson 3 sold the product 4 and earned 100 dollars.
You need to populate the array with some values on your own and then use for loops to calculate the statisitics

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

The "mainMenu" should be the id of the table.
Since you are using this: document.getElementById("mainMenu") It is quite obvious when you say "getElementById" that the argument should be the id of the element you are trying to take.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You must also close the connection and the RsultSets at the end, so better make some public methods that do that.
Also you need to apply these changes to other queries as well:

This: rs=stmt.executeQuery("select username from userinformation where username=name") Should be rs=stmt.executeQuery("select username from userinformation where username='" + name + "'") And any where else is needed

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Of course, now I see it. It is very simple. The executeQuery is supposed to return a ResultSet. You use that method when you are querying the database (select * from ...) and you expect to get back some rows.

But the query you have is an INSERT query. You are asking for the database to return you a ResultSet: rs1=stmt.executeQuery("insert into userinformation(username,password,dateofreg) values ('"+name+"','"+password+"','"+dateofreg+"')"); But the INSERT query doesn't return anything, it is simply inserting.

So use this method:

int executeUpdate(String sql)

Executes the given SQL statement, which may be an INSERT, UPDATE, or DELETE statement or an SQL statement that returns nothing, such as an SQL DDL statement.

The int that returns is the number of rows affected. In your case will return the number of rows inserted (1)

Also next time you should check the API of the classes you are using:
Statement

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Well I run them at my computer and there is no syntax error. Your class cannot find the fm1

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Are both classes in the same folder?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Try changing this line:

rs1=stmt.executeQuery("insert into userinformation(username,password,dateofreg) values(username,password,dateofreg)");

To this:

rs1=stmt.executeQuery("insert into userinformation(username,password,dateofreg) values ('"+username+"','"+password+"','"+dateofreg+"')");

Also the exception tells you at which lines you got the error. It would be better if you point out to us which lines are that, because we cannot just count 51 lines, especially when you post 2 classes at the same time

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

because he wants the value returned, not a true or false

But isn't he using the value as input to search if it is inside the array or not? (Read my recent post)

I am not saying that someone is correct or wrong. You are all right, but with the given information it is hard to understand what the poster really wants. That is why maybe we should wait for the poster's response to my question:

what your method takes as arguments and what do you want it to do and return

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

if the number was found in the array, I want to return that number

Yes but what are you using to search the array? If you are using the number and want to see if it is there then you already have the number. If your method takes as argument the number to search for then you already have the number. You don't need to return it:

int number = 10;


boolean b = searchNumber(number);
if (b) {
  System.out.println("Number: "+number +" found");
} else {
  System.out.println("Number: "+number +" not found");
}

Or you might want to return the index as suggested and if not found return -1 as suggested.

If the above doesn't cover you please post what your method takes as arguments and what do you want it to do and return

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You have 2 while loops one inside the other that do exactly the same thing in the opposite. There are much better codes than that:

boolean done = false;
while (!done) {

// and now k2k's code

enter input

    if (answer.equals("yes"))
    {
        do whatever calculations you want to do
    }
    else if (answer.equals("no"))
    {
        done=true;
    }
    else
    {
        System.out.println("Invalid option");
    }
}
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster
String number1 = "Enter first number:";
        double P1 = in.nextDouble();

        String number2 = "Enter second number:";
        double P2 = in.nextDouble();

You need to print the messages:

System.out.println("Enter first number:");
        double P1 = in.nextDouble();

        String number2 = "Enter second number:";
        double P2 = in.nextDouble();

With your code you give value to the number1 and then the program waits for you to input a value. You need to simply enter a number and print <ENTER>

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Also about the weird output:

System.out.println(list.getFirst())  //weird output

Whenever you put an object as a parameter in System.out.println the toString method of that object is called. In the above example you passed as parameter the: list.getFirst() which is a Data object. Since you didn't implement/override the toString method it used the one from its parent class Object (every class extends the Object class). So you got what the toString method of Object class returns.

So if you want to do something like this:

Data data = new Data();
System.out.println(data);

Add this to your Data class:

class Data {

public String toString() {
  return "whatever you want to be printed"; //probably the values of the variables
}

Also this will have the same result and the toString method will be called automatically:

Data data = new Data();
String s = "Data: " + data;
System.out.println(s);
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster
for (String s : list)
    System.out.println(s);

The idea is to learn about Lists, not to learn the different ways to iterate. I doubt that the above example would have helped in understanding how to add and get elements from lists.

There's no need to write one in C++, either. #include <list>

That I liked.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Check the API for ArrayList. It is the most commonly used

ArrayList list = new ArrayList();

list.add("asd");
list.add("fgh");
list.add("erty");

for (int i=0;i<list.size();i++) {
  String s = (String)list.get(i);
  System.out.println(s);
}

Or if you use generics (after java 1.5)

ArrayList<String> list = new ArrayList<String>(); //here you define what kind of objects you will put inside the list

list.add("asd");
list.add("fgh");
list.add("erty");

for (int i=0;i<list.size();i++) {
  String s = list.get(i); //you do not need to cast it to String like the previous example because of the way you defined the list above
  System.out.println(s);
}

Check the LinkedList in case it has methods that interest you

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Check the API for the String class. It has a replace method.
Also if you search this forum you will find examples on how to read and writes files.

So read the file line by line.
For each line use the replace method and save the result (the modified line) into a collection (check the API for ArrayList).
After you are finished with the file, write all the lines that are inside the ArrayList back to the file

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster
BufferedWriter writer = new BufferedWriter(new FileWriter("fileName"));

writer.write("write here");
writer.newLine();

Check the API for the BufferedWriter in case I have some errors in the syntax

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

From a quick look at your code you have this:

case 2:
                mart.print();
                // Call break to avoid falling through to the default case.
                break;

It is suppose to print the shopping cart. Are you having problems with that?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Post again the code that you are currently using

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

please marked it solved if it has solved your problem

First of all this is not a contest of who will get the most solved threads. I say this because:

The "solution" given is not the best that could be provided and it is very difficult to understand what you have written if you are not experienced enough.
This is not the right way to write java code. First learn proper java yourself and then give "solutions" to others.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

is there any book from which i can learn net beans

Try the tutorials of the net beans site.

And net beans is an IDE that helps you organize your projects. Shouldn't you been learning java?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I want the program to take 2 user inputted numbers and then carry out the calculations I have added at the bottom.
eng.M4AH, When I switch the order like you have stated, the BlueJ doesn't run the program. I think you're on to something though

eng.M4AH is correct, but yes you will get compile errors if you copy paste the code given because of these lines:

double P1 = in.nextDouble();
double P2 = in.nextDouble();

Pair pair1 = new Pair(p1, p2) ;

See what is the problem? The compiler's message should provide you with the answer on what to change at the above lines

EDIT: And please eng.M4AH, don't give him the solution. He will never learn anything if he can't correct simple mistakes like that

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Peter is right. If you don't want the message to printed at the console, don't call that method.

And as I asked in my post:

Where do want it to be displayed?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Where do want it to be displayed because I don't think that it can be done.

I would suggest you look at the API for
PrintStream

Because the System.out is type of PrintStream.

This will behave exactly like the System.out.println

PrintStream print = new PrintStream(System.out);
        print.println("aaaaa");
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I told you to write a main method in which you will call your other methods. You wrote this:

public class Main {
public class McBrideCR1{

The above doesn't mean anything. Surely this is not the first program you wrote. Check your notes. Writing a main method is the first thing you learn.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You need to write a main method in which you will execute the code you wrote. Right now you have only a class with methods. You need to call these methods inside the main

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

What errors do you get and at which lines. Post the errors you get.

Also if it runs what results do you get what you were expecting?

Also the tab character is this:
\t

System.out.println("aaa\tbbbbb")

and for new line:
\n
System.out.println("aaa\nbbbbb")

Try running the above just for testing

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You need to count how many elements are inserted and when you reach 10 exit.

If I understood correctly you will need this:

int count = 0;

do {
System.out.print("Enter 1 for F to C, 2 for C to F, and 3 to quit");
choice = input.nextInt();
if (choice == 1) {
count++;
tempC();
} else if (choice == 2) {
count++;
tempF();
} else if (choice == 3) {
exit();
} else {
System.out.println("Invalid selection");
}
if (count==10) {
  choice = 3;
}
} while (choice != 3);
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

First of all remove the lines:
do{

They don't do anything. You open the bracket and you don't close it plus you don't have a while to go with it. The while that follows is unrelated with the previous 'do' and it has its own brackets.

Also inside the while you write:

while ( hours < 0 )

'hours' is an array. You cannot do these kind of calculations with an array. I believe that this is what you wanted:

while ( hours[index] < 0 )