javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

im not exactly sure where to start and i dont really understand it. i dont know if im right, but i tried to understand the question by following the sample inputs. For example, the first sample input, (1 5 9 + 8 – + ), you take leave the 1 alone for now. Next, you take the first operand ( +) and add 5 and 9 together which equals 14. Then you take the next operand (-) and subtract 14 and 8 which is 6. Then you take the last operand the ( +) and add 6 and 1 together which is 7.

let me know if i have the basic idea..


should i use the indexOf() method to call the operands ?

i dont know what to do.. im really confused !

One suggestion. When you take the first operand and do the math then use String.replace() in order to put the result where it was:
1 5 9 + 8 – + -->
1 14 8 – +

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

And what if the user enters 24?
Then he should check for 2,3,4,5,8,12. The algorithm for checking prime numbers is a little bit more complicated.
It will require a for loop from 2 till the number divided by 2. Then in the for-loop you will have the if statement like the one posted.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Just create a new project in eclipse, create the package, and then put the file inside that folder.
Then select your project, right click on it, select properties, Java build path, select the Source tab. There Remove the source folder on build path, and then press Add Folder. Then you choose the folder where your packages will be (the classpath).
You might want to set the Default Output Folder. It will determine where your classes will be created

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

We will need more than this. Perhaps your code.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster
String a = "";
System.out.println ("Please enter the sentence to analyse");
a = userInput.nextLine();


if (a.length!=0) {
  if ( (a.charAt(a.length-1) == '.') || (a.charAt(a.length-1) == '!') || 
            (a.charAt(a.length-1) == '?') || (a.charAt(a.length-1) == ' ') )  {
      a = a.substring(0,a.length-1);
  }
}


System.out.println ("");
System.out.println ("Here are some statistics on your sentence:\n");
int textLength = a.length();
int numberOfWords = 0;
int countChar = 0;
int lengthOfLongestWord = -999;
int lengthOfShortestWord = 999;
// . . .

So instead of getting what the user enters, you omit the last character (if it is a punctuation mark)

If you check the API: String there are methods for the String class like:
int indexOf(String str) ;
int indexOf(String str, int fromIndex);
In case they help you.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

He's not using MySQL.
That is correct for MS SQL Server.

He just did that.

No, it's only that he doesn't have the driver on the classpath.

That would work if he were using MySQL, and it were running on the port 1433.

Sorry, don't mean to be mean, but that entire post seems to be entirely offbase. ;)

I didn't mean that he should take exactly this: mysql-connector-java-5.0.7-bin.jar. This is the jar I am using. I meant that he should take whatever he has installed in his computer. As far the port I used what he was using in his mail.
And I told him first to use the jar file and then if it didn't work to change the driver.

As far as my post was being little off was because by the time it took me to write it, you guys have already posted two threads before I submit.

And I don't think you were mean. Your comments said what needed to be said and nothing more.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Have you included this mysql-connector-java-5.0.7-bin.jar jar file?
If not use the above first and if it doesn't work try the below

I think that the problem is with value you use for:
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
At first try to write: e.printStackTrace(); inside the catch(). You will get a better view of the exception. I think that the problem is with the driver you are using inside the Class.forName() method,
try this: com.mysql.jdbc.Driver.
and this: jdbc:mysql://localhost:1433/nameOfTheDB

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You should post the errors the compiler gives you, and at which line you get them.
You call these methods like this:

prime(isPrime);
noPrime(isPrime);

And you declare them like this:

public static void prime(isPrime, int number)
public static void noPrime(isPrime, int number)

Plus, at the main method you don't declare the isPrime variable that you put inside the methods

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

One suggestion is this:
you could have an array with values from 1 to N*N like this: (example)
int [] oneDim= {1,2,3,4,5,6,7,8,9};

Generate a random number from 0 to 8.
Take that number and put it inside the 2-sized array.Use a for loop that puts the first taken number to (0,0).
Then use a swap method that takes the selected number and puts it at the end of the 1-sized array:
example: if the random number was 4, Then the oneDim[4]=5 will be put at the target 2-sized array, and after the swap the oneDim will be like this: {1,2,3,4,9,6,7,8,5}

Then you will repeat the above procedure with one difference: the random generated number will be from 0 to 7. So when you go to the oneDim array you will take only the first 8 numbers: {1,2,3,4,9,6,7,8} and you will not take the last which is already used: 5

int [] oneDim= new int[N]
int [][] randoms=[N][N];

for (int i=0;i<N;i++) {
  oneDim[i]=i+1;
}

int row=0;
int col=0;

for (int i=0;i<N;i++) {
  int r = //random number from 0 to N-1

  //put the value from oneDim to randoms
  randoms[row][col] = oneDim[r];

  //swap oneDim[r]  with oneDim[N-1 - i]  //N-1 - i : so not to keep swapping a number that was previously used and was put at the end 

  //alter row, col so as to put the next number at a new place
}
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Since the user inputs the size you can create the array:

int [][] array=new int[N][N];

Then use a for-loop to put numbers in the array.

As I noticed at your example the random numbers are from 1 to 9. Is that a requirement? Meaning do the numbers have to be from 1 to N*N?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Also I think that you are missing the main method and this piece of code:

Scanner keyboard = new Scanner(System.in);
System.out.println("Please enter a positive integer: ");
num = keyboard.nextInt();

for (int x=2; x < num; x++)
{
if (num%x==0)
noPrime();
else
prime();
}
System.exit(0);
}

is not inside a method, it's in the middle of the class

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Can't you read the errors and follow the instructions to fix them? When you get compile errors you get a description of the error, the line that it happened and how to fix it.

Why doesn't anybody read compile errors these days and just post the code without even bothering to see what the compiler says??

And most important, you didn't even post these errors, you just gave us the code. Are we suppose to compile it for you in order to find out the errors?

Anyway, you declare prime and noPrime like this:
public static void noPrime(int num)
public static void prime(int num)
and you use them like this:
noPrime();
prime();

You figure it out.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You are trying to turn a EmployeeAryApplicEx instance into a EmployeeMultiTypeSeqFileExer, which cannot be done. I presume that you wrote something like this:

EmployeeAryApplicEx empAryApplicEx=new EmployeeAryApplicEx();
EmployeeMultiTypeSeqFile empMultiTypeSeqFileExer=new EmployeeMultiTypeSeqFileExer();
empMultiTypeSeqFileExer = (EmployeeMultiTypeSeqFile)empAryApplicEx;

What you did is like trying to cast a String into an Integer:

String s="3";
Integer integ=(Integer)s;

Which cannot be done in both cases because the objects are not of the same type.
It would have worked if one object extended the other

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Ehmm, are we forgetting to use code tags??

I usually don't use code tags when writing 1 or 2 lines of code. I mean all I wrote were 2 commands what were easy to read and understand. Of course for larger blocks of code I always use tags.

Yes Jbutton belongs to swing and sorry, but I didn't see that your question was about AWT. I use JButtons from the swing package for my GUIs

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

What do you mean when you say button tip? If you want a message appearing when you put the mouse on the button then use this:

JButton button = new JButton("Save");
button.setToolTipText("Click to Save the file");

If you want to have the button activated from the keyboard:
JButton button = new JButton("Save");
button.setMnemonic('S');
The 'S' will be underlying at the button and if you press Alt-S it will activate the button.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

First of all equalDeals does what equals does. So delete equalDeals.

Inside the MutiItemSale class you will define an array of Sale objects:
Sale [] sales = new Sale[100]; //the 100 is for this example, you can use what you want.
You can have a count int variable and when you "add" a new Sale object you will increase it.
Now pay attention: The sales array contains 100 null Sale objects. The sales is an array and it is not null BUT the sales[0] is a Sale object and it is null. If you want to create it do:
sales[0] = new Sale(); So you will use the count to determine how many new Sale() objects you have instantiated in the array and use that count as a limit to your for-loop.
You will have methods that take as argument Sale object and insert them in the array. Use the count as index and after you add a new Sale increase it
You will have a method that takes an int argument and returns the Sale object that is at that specific index in the array.
And the method that returns the bill will loop through the array (be careful to use the count variable as the limit) and take the sum of all the Sale objects from the array

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster
number = SavitchIn.readlineInt();
int sum=0;
int count=0;
int tempMax=number;
int tempMin=number;
while ( number != -1 ) {
  //have an int variable(count) that increases by 1 each time, counting how many numbers   
  //were given

  //add each number to the sum variable in order to have the total sum

  //use the tempMax,tempMin in order to compare them with the new number given and    
  //change their values only if the new number is greater or lower than them

  number = SavitchIn.readlineInt();
}
int average = sum/count;
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I actually need to instantiate two ListeningPoint objects here and use one per interface. What is your idea to get this ?

What do you mean use one per interface? The interface is one and you cannot instantiate it

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Are you talking about variables or methods? If variables just declare them like you would any other variable. You have already declared a lot of stuff, is it difficult to add a few more? or perhaps I don't understand your question

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Your class is an interface: public interface SipStack
So you can not write code only declarations of methods and variables.
So this: myListeningPoint= sipStack.createListeningPoint(port, "udp"); shouldn't be there.
And by the way: myListeningPoint is declared as a method: ListeningPoint myListeningPoint();
This would be wrong anywhere you write it : myListeningPoint= sipStack.createListeningPoint(port, "udp");

On the other hand this would be correct:

SipStack stack = //somehow get an instant that extends this interface
ListeningPoint lPoint =  stack.myListeningPoint();
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

How does it behave? Has JOptionPane.showMessageDialog an "OK" button? Waht did you expect to receive.
Perhaps you should use the syncronized keyword.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

At which line do you get the Exception? What does the console prints. Try adding try-catch with printstacktrace so you can provide us with more information

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Netbeans IDE can do it.
Although for most cases I prefer to hardcode it becuase that gives me more flexibility

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

you must desclare this one first bro!

String q="";
q = answerField.getText();
int n1 = Integer.parseInt(q);

//email me whats the result ok!
jalpex91@gmail.com

This is what puk has already written : String q = answerField.getText();
It is the same as what you suggested. If he is going to use your two-line solution or not will not make any difference

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

And have a class that reads from the database and gets the data you want to display in a String, or an array, or in whatever you want.
You call that class in your gui and display the results like peter_budo said.
As you can a lot of things are involved. Where are you having problems? In reading the database or displaying the gui.
Remember, don't put all in one class. Try to separate functionalities. One class for the DB, one for the GUI. Test both before you start calling one into another

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

javadoc has some other parameters as arguments besides the filename.java. I don't remember them exactly but if you search the internet you might find ways to use them

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster
for(int i=1; i<employees.length+1; i++){
           output += employees[i-1].toString();<<<<<This Line

One of the employees[i-1] is null, meaning that you don't instantiate all the elements of the array. That happens because inside the for-loop you have an option with the command: break; So if the user gives "Quit" you break from the loop and the rest of the elements of the array remain null. Two choices:
Remove the "Quit" option and make sure the user instantiate all the elements. Don't have a break and if a user enters something that is not: "Salaried, Hourly ,Commission, Base Plus Commission" either create a default instance with empty values, or print a message and reduce the counter of the loop in order to male sure that all the elements will have values and that you will not skip one.

for ( int empNo = 1; empNo <=5; empNo++ ) {
 if(workerType.equalsIgnoreCase("Salaried")){ ..
 } else if () ... {
 } else {
    empNo--;
 }

Choice Two:
Have a while-loop: while(true) {...} instead of for-loop. When when user enters"Quit" break from the loop and instead of an array have a Vector or an ArrayList

I think that at the following command:
workerType=JOptionPane.showInputDialog
if you click "Cancel" it returns null. So workerType will be null when you do this:
if (workerType.equalsIgnoreCase("Salaried"))

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I would suggest not to download the API. You don't need the entire API since you are new to java and it will confuse you. The API is not going to help you learn java.
And you have written a few programs with the notepad try to download a java editor

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Your code is correct. This is how it is done.
The problem is that you are trying to convert the String: "Enter Answer here!" into an int which cannot happen.
As you can see at the message that you posted it:
Exception in thread "main" java.lang.NumberFormatException: For input string: "Enter Answer here!"

So I guess that in the code you posted:

String q = answerField.getText();
int n1 = Integer.parseInt(q);

You give q the value: "Enter Answer here!"

If q has a number as value like this, it will work:

String q = "23";
int i = Integer.parseInt(q);

i has now the int value 23

If q has any String value like this, it will NOT work:

String q = "Enter Answer here!";
int i = Integer.parseInt(q);

The second line will throw the NumberFormatException that you saw.

How to avoid it?. enter at the textfield only int numbers.
And better: read and learn about exceptions:

String q;
int n1;
try {
  q = answerField.getText(); 
  n1 = Integer.parseInt(q);
} catch (NumberFormatException nfe) {
  System.out.println( "NumberFormatException occured: " + nfe.getMessage() );
}
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

public static string showOutput(int a, int[]signal,int[]smooth)

There is not such thing as a "string". The correct declaration is String with capital S. And most important, java is case sensitive. Meaning that if you want to call the above method you should call it like this: showOutput NOT like this: showoutput. Try to find where you have such a mistake because I think I've seen in other places, and not only for showOutput but other variables as well. You declare them
like: endValue
and I see that you use them
like: smooth[ endvalue ] = ...

Try to correct the above and continue with the others.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Create a class that will represent the data from the database.
Create a separate class with queries and methods that return the data from the DB.
When you open the GUI call these methods and use the data to populate the combobox.
Since you will have many Jpanels Child I would suggest to have an array of JPanel Child or a Vector. Each element will take value from the data that you will read from the database. And with the help of a for-loop you will be displaying them at the gui.

Try to divide you work. First create the class to read from the database. Then create the gui. Just the gui with no functionality just to see how it is displayed and use dummy values instead of using the database. Then after you have made sure that they work try to combine them. Since you will have a lot of stuff in the child JPanel I would suggest for you to create a new class that extends JPanel and put(add) inside it the gui elements that you need

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

gradesReceived as I can see is an array. Why do you call gradesReceived.close() ? I don't think there is such method and if it is then you don't need it.

Do you know what divided by zero means. In case you don't know English it happens when you are doing something like this 2/0. So you need to add the try-catch block where you trying to divide something, probably where you calculate the average.

Rewrite computeGPA without the try-catches. You probably get an error because you try to catch DividedByZeroException when you should be catching NumberFormatException:

try {
  int i = Integer.parseInt( . . . );
} catch (NumberFormatException nfe) {
}

This:

double sum = 0.0;
for (int i = 0; i <100; i++) {
if (!classesTaken.equals(" ")) {
sum += gradesReceived;
}

Doesn't need a try-catch. When you divide for the average you will need the try-catch

You have a grades and a gradesReceived array. What is the difference between these two?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You have declared an array:
CdRecord[] arrayrecord=new CdRecord[5];

and the method:

public static int CdSearch (CdRecord [] data, String searchKey, int size)
{
for (int counter = 0; counter <size; counter++)
{
if (data[counter].toString().equals(searchKey))
return counter; // return position where found
}

return -1; // if drop off end of array, its not there
}

takes an array as an argument. So you should call it with an array, not like this:
result=CdSearch(CdRecord,searchKey,counter);
CdRecord is not an array and you don't declare it anywhere. That is why you get the error.
Call trhe method like this:
result=CdSearch(arrayrecord,searchKey,counter);

And you shouldn't use the toString() for comparisons. It is only for returning the values of the object. In order for the above to work the searchKey should have exactly the structure that the toString returns. Based on what you want to compare them, meaning what attribute of the class you want to use in order to distinguish one instance from the other? If name is what you want then ask for the name from the dialog box and do this in the method:

data[counter].name.equals(searchKey) or if you have a getName:
data[counter].getName().equals(searchKey)

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Inside a for-loop you will have a System.out.print("*") How many times will this for loop will execute will determine how many * you will have at each line.
Then you will put it in another for-loop which you will use to determine how many lines you will have:

for () {
  for () {
     System.out.print("*") 
  }
  System.out.println(""); //for changing lines
}

What will you put in the for as arguments(counters) will be up to you.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

When you use code tags inside the [] write next to the code=JAVA so I can see the lines or write in the code where the error was, because I can't count your entire code to find the line that the error happened

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I started in 1998.
6 months: Fortran 77 in unix
6 months: Pascal
6 months: Ansi C
And at 2003 I started java and I've being doing it ever since

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

The stack.push is inside the for-loop. Meaning that insert the same token more than once.
For example if token="123"
then you will check if "1" is a digit and then you will push the token.
then you will check if "2" is a digit and then you will push the token.
then you will check if "3" is a digit and then you will push the token.

But if you enter token="12a". Then the first two characters will be digits and you will push to the stack the token: "12a" twice which is wrong, and then the 'a' will not be digit and you will do nothing:
1) Have a boolean inside the for-loop and if it is not a digit do something like this:
boolean isNumber=true;
for (...) {
if (char not a digit) {
isNumber = false
break;
}
}
if (isNumber) push(token)

Or better:
2)
try {
double d = Double.parseDouble(token);
stack.push(token);
} catch (NumberFormatException nfe) {
System.out.println("Token: "+token+" is not a number");
}
And you will not need the for-loop

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

the catch block should should print out an error message (nonGUI) and return zero as the GPA , and the finally block should print out a message (nonGUI) indicating the method finished

You will put the code that calculates the GPA inside the try. Inside the catch you will print an error message and give the GPA value 0 and inside finally you will again print whatever is required from you.
I would suggest to put the entire code inside the try just to be sure. Then have a variable declared outside the try. Inside the try calculate the value and put it inside it. Inside the catch you will have it take value 0. And at the end you will return it:

double ret=0;
try {
  //calcucate GPA

  ret= //the value calculated
} catch (Exception e) {
  ret=0;
} finally {

}
return ret;
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Ok. Then you are on the right track. Just ignore what I said about iash and follow your own idea

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Are you iash? Because I was referring to his code:

And I have seen your other post. I would suggest not to open a new post for the same thing. And most important do not have different versions of code in different posts.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

These are not objects, they are variables of the object CDRecord:

class CDRecord {
String artistName;
String album;
int numberOfTracks;
}

The above is an object.
And I have seen your other post. I would suggest not to open a new post for the same thing. And most important do not have different versions of code in different posts.
Use the code you have at this post. Forget about the other. Add in this code the part where you create the menu with the if-statements but don't put anything inside them. Then start all over.
Put code in one of these options test it and then try to code the others. I saw that you tried to fix all the menu options and there are many different bugs. Try to build one by one.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

First of all how do you know that you will have exactly 3 objects. If this is the case then use arrays:
CDRecord [] records=new CDRecord[3]; And follow the example I sent you.
With arrays you cannot add more objects than the size of the array.

If you have a while-loop and the user can give as many CDRecord as he wants then use ArrayList: /java/util/ArrayList

ArrayList<CDRecord> records = new ArrayList<CDRecord>();

CDRecord cdr = new CDRecord();
//set the values of the cdr
records.add( cdr );

int length = records.size(); //returns how many objects the ArrayList has

CDRecord ret = records.get(i); //gets the CDRecord from the ArrayList that is at the 'i'th place. (i must be int)

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You write:

public String toString()
{
String o = "Artist Name: " + artist_name + "\nAlbum Name: " +album_name+"\nNo. Of Tracks: " + no_of_tracks;;

System.out.println(o);
return o;
}
.......
System.out.println(one.toString());

Meaning that you print inside the method, and then you print again. Remove the System.out.println() from the method:

public String toString()
{
String o = "Artist Name: " + artist_name + "\nAlbum Name: " +album_name+"\nNo. Of Tracks: " + no_of_tracks;;

return o;
}

You also write:

CdRecord one = new CdRecord();
System.out.println(one.toString());

one.artist_name = JOptionPane.showInputDialog("Enter artist name.");
one.album_name = JOptionPane.showInputDialog("Enter album name.");
one.no_of_tracks =Integer.parseInt(JOptionPane.showInputDialog("Enter the number of tracks on the album"));

When you create the object:
CdRecord one = new CdRecord();
it has values: "A", "B", 0.
Then you call: System.out.println(one.toString()); So it prints the values that it currently has.
You give values to the object afterwards and you don't print them. So place the System.out.println() after you have given values to the object:

CdRecord one = new CdRecord();

one.artist_name = JOptionPane.showInputDialog("Enter artist name.");
one.album_name = JOptionPane.showInputDialog("Enter album name.");
one.no_of_tracks =Integer.parseInt(JOptionPane.showInputDialog("Enter the number of tracks on the album"));

System.out.println(one.toString());
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Sorry for posting too many times but I think it is better to have different suggestions separated:

I need to create a menu of options as well, which include:
* new entry from keyboard
*print entries so far
*quit

A)Put your code inside a while(true) loop
B)Read from the keyboard the input:
String input=JOptionPane.showInputDialog("");
--If you give "read new entry" do whatever you are already doing but instead of printing it, put it inside a Vector"
--If you give "print" use a for-loop to print the entries
--If you give "quit" then use the command break; to exit the while(true) loop

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Since you don't know how many CDs the user will enter then don't use an array. With arrays you NEED to know from the beginning their size. Use Vectors or ArrayLists.

I would suggest to alter the printCdRecord(). Every class inherits the toString() method from Object. It returns as a String all the information of the current instant of your class. So it would be better for you to do the same. Actually even if no one is forcing to do this (programmatically speaking) it is most preferable to have a toString() than a print method:
Your Code:

public void printCdRecord ()
{
String o = "Artist Name: " + artist_name + "\nAlbum Name: " +album_name+"\nNo. Of Tracks: " + no_of_tracks;;

System.out.println(o);
}

My suggestion:

public String toString()
{
String o = "Artist Name: " + artist_name + "\nAlbum Name: " +album_name+"\nNo. Of Tracks: " + no_of_tracks;;

//System.out.println(o);
return o;
}

And call the above method in your main:
System.out.println(one.toString()); or better: System.out.println(one);

When you put an instant of a class in a System.out.println it will automatically call the toString() method. If you haven't implemented one it will the super class toString() and so on until it reaches the Object.toString().

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Useful example for objects in arrays:

CdRecord [] records = null; : This is an array that takes CdRecord objects. THE ARRAY IS NULL

CdRecord [] records = new CdRecord[2]; : This array IS NOT NULL. The records IS an array and it behaves EXACTLY like any other array. But records[0] and records[1] ARE CdRecord objects and they are NULL.

CdRecord [] records = new CdRecord[2];
records[0]=new CdRecord();
records[1]=new CdRecord();

records[0],records[1] are CdRecord and they are not null. They behave exactly like any other CdRecord object:

records[0].artist_name="Artist";
System.out.println(records[1].artist_name);

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I don't know if you are going to receive this tanha, but I am going to say it anyway.
What you have tried to do is wrong from the design point of view. Even if it compiles and does exactly what you want it is not how it should be done: You cannot have you entire code with different functionalities in one method. The gui you wrote should be used to do things only a gui would do. Meaning that shouldn't implement code that connects to a database, runs the query, gets the result and then perform some actions with the result inside the actionPerformed. A better way to do this (I am not saying it is the best way but it is easier and SIMPLER) is the following: (Some details are omitted in order to reduce the code)

Have a class that only returns the connection:

class ConnectDB {
  public static Connection getConnection() {
     //code the returns the connection to the database:
    // here you write what is needed only for the connection.
   //  ... 
     conn = DriverManager.getConnection (dbUrl, dbUser, dbPass);
   //  .. ..  ...
 return conn;
  }
}

Then you have another class in which you run only the queries. One method as an example

class UserDB {
  public boolean validateUser(String user, String pass) {
    Connection conn = ConnectDB.getConnection();
    //write the query, executed, and return if the user can login or not
    return false;
  }
}

And finally you call the above inside your …

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

For the random generated numbers try : Math.random(); . It will return a random double between 0 and 1. You can then multiply with 100 and cast it to an int

I need to Populate the class taken whth an empty string

Add getters and setters for the variables: name, address, phone, major and call them after you have created an instant of the object. Example:

public void setName(String name) {
  this.name=name;
}

public String getName() {
  return name;
}
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Why don't you try the API for String, and the methods indexOf. If it returns something not -1 then increase a count++ and search for the occurrence of the letter after that index.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

bottomPanel.add(goButton);

Where do you do: goButton = new Button("some name"); ? If you don't do this then goButton is null.

Obviously you must initialize everything before you use it. And the compiler will tell you the lines where you try to use null objects