javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster
public void add(CompositeShape aShape)
	{
		Rectangle temp = aShape.getBounds();
		int width = (int)temp.getWidth();
		int height = (int)temp.getHeight();

		JButton aButton = new JButton(new ShapeIcon(aShape, width, height));
	}

The button only exists in the add method. You declare it then that's it, you are not doing anything with it. No one outside the method can see it. It is not even part of the Box class. You should declare as a private attribute in the Box class and use get method. Then you should add it in the frame that you are displaying.

Suggestion: have Box extend JButton

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

char should have length 1. Always 1.
This is correct char c=' '; or char c='2'; Not this: char c=''; or this char c='12';
So I believe that the compiler could convert the '\21' to its equivalent character but not '\29' because there isn't any. Is like writing: char c='\n'. n is a special character for newline. But char c='/n' is not correct.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Call determineGrade followed by the JOptionPane.showmessage() more times (after every time you input the grades). If this doesn't satisfy then you have the methods that work, so use them in order to do whatever you like

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Your determineGrade already does that:

public static char determineGrade(double score)
      {
      if (score >= 90.0) { return 'A'; }
      else if (score >= 80.0) { return 'B'; }
      else if (score >= 70.0) { return 'C'; }
      else if (score >= 60.0) { return 'D'; }
      else {
         return 'F';
      //JOptionPane.showMessageDialog(null, "Your grade is " + grade);
      }
}

Takes the score as argument and returns the grade. Just remove the line I have commented out: //JOptionPane.showMessageDialog(null, "Your grade is " + grade);

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

break statement inside the loop doesn't make it an infinite loop. (that's my opinion of course) Others might have better suggestions

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You don't ask for help, you just posted your assignment that includes a lot of different fields from java. (gui designing, button handling, reading/writing files).
What is your background, what are your weaknesses, what you don't understand?
No one is going to do it all for you.
Start writing code and you will get help. And to help you started:
Create a class that represents the data. //use get,set methods, add attributes:name, address,...
Create a class with methods that write and read to a file. //there are examples in books
Design the gui. (add only the elements that it will have with no button handling at the begining)
See that displays OK and then try to handle the button actions

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

First of all what kind of errors do you get and where?
And from what I see:
In calcAverage() you simply display the average, so in the main I think that you should first call the avgScore = total / 5.0; and then the calcAverage();
And second, the determineGrade() returns a char. If you see the code, the JOptionPane.showMessageDialog(null, "Your grade is " + grade); is inside the last else {},so when the grade is for example 90 it will return 'A', but if it is 50 then it will return 'F' and the JOptionPane.showMessageDialog(null, "Your grade is " + grade); will never be executed:

public static char determineGrade(double score)
			{
			if (score >= 90.0) { return 'A'; } 
			else if (score >= 80.0) { return 'B'; } 
			else if (score >= 70.0) { return 'C'; } 
			else if (score >= 60.0) { return 'D'; } 
			else { 
			return 'F'; 
			JOptionPane.showMessageDialog(null, "Your grade is " + grade);
			}

As you can see when the red return 'F' will executed the method will end. And by placing JOptionPane.showMessageDialog(null, "Your grade is " + grade); inside the last else{} is like saying that you want to display the grade only if the student has failed.

You have the following options:
Put the JOptionPane.showMessageDialog(null, "Your grade is " + grade); before the return statement inside all the ifs (not so good repeating code) or remove it from the method and do this:

public static char determineGrade(double …
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Then use:
sdf.format(date);

The SimpleDateFormat.format(Date) will take any Date object, no matter how it was created and retutn a String based on the pattern you have set at the SimpleDateFormat object.
Meaning that this:

SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-mm-dd hh:mm:ss" );
Date date = new Date();
System.out.println("Date: " + sdf.format(date) );

will return:
2008-03-14 15:53:45

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Yes, your command shall be done my emperor. We have no problem doing you homework, since you asked so nicely.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Haven't you been reading the previous posts?
Max must not be initialized with 0:

You will have to initialize max to something - either the first value of the array or Integer.MIN_VALUE.

as Ezzaral said. (Personally I prefer the first value of the array)

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

When you pop, place the value in a string and compare it with the String "add":
for example (not exaclty java code because i don;t remember by heart the right syntax)

String s=stack.pop();

if (s.equals("add")) {
  int i=Integer.parseInt( stack.pop() );
  int j=Integer.parseInt( stack.pop() );
  int res=i+j;
  stack.push( String.valueOf(res) );
} else if (s.equals("sub")) {
  //do something
} else if (s.equals("mult")) {
  //do something
} else if (s.equals("div")) {
  //do something
} else {
  stack.push(s);//it puts it back because it is (probably) a number
}

This is just a general idea. I don't know what exactly you want to do and how you want to push or pop things in the stack

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Well I thought that you were insisting about the max=0 thing, that's why I replied the way I did.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

No as Trogan said the values were all positive then this bit of code works. And it will pick out the max number.

int max = 0;

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

   if(max < array[i])
   {
      max = array[i];
   }

}

Where if the array was full of negative numbers then you would initialize it like :

int max;

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

   if(max < array[i])
   {
      max = array[i];
   }

}

But you are right that it would be of a better industry standard not to initialize max to any value. That is if you are unsure with what values you would be dealing with.

At the first part of your code where you set max=0, you DON'T know that the array has positive numbers.
At the second part of the code when you say int max; is like saying int max=0; which is the same thing.

And I never said that:

But you are right that it would be of a better industry standard not to initialize max to any value.

I said exactly the opposite, to initialize max or min with one of values from the array.
You cannot have two different codes that do exactly the same thing and assume that you know the values in the array to call one or the other:
initialize max with one of the values of the array, and then use the for-loop which will work no …

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

A good book that helped me learn java was Cadenhead Java 2. Try to search this forum for a thread about java books. Also from what I have seen in your code, there certain basic elements you don't understand about Object Oriented Prog.
You create classes, and these classes can be used to programs to create different instances. If it helps it is like when you declare int variables:
int i=0;
int j=0;
Both are int but have different values.
CarInfo car1=new CarInfo();
CarInfo car2=new CarInfo();
Both car1,car2 are CarInfo, but they are different. Note that you must use new to create a new object.
Then you can use car1, car2 to access the variables they have inside them.
But you don't instantiate the object itself inside it. You only declare the variables-attributes that the object should have. Then you can use instances of the object anywhere in your programs.
Try to put your classes in different files. For example if you wanted to use CarInfo in another program, you couldn't the way you wrote your program.
In the way I showed you, you have the CarInfo object in a separate file and you can use it in any class you want

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

#1: You don't need for loops. You have 4 different for-loops and inside each one you have the same code, without using the index i. If you look at one of them you will see that: the first time it takes for example the model and sets it to the honda. Then the second time again ti asks for the model and sets it again in the honda. 5 times you are setting the model to the honda, then 5 times you set it to the lexus, and so on. You should have an array of carinfo and each time you should be setting the model to a different carinfo instance.

#2: The for-loops are wrong. Inside them you use carinfo objects that declared outside the class. You don't set the values of an instance inside the class. You create a class and in the main you create instances and setting their values.

I will use only your code and show how it should be. By the way this is not the best way to do it but I will do it the way you imagined it.
First create a class in a different file: CarInfo.java

public class CarInfo{

public String model;
public int year =0;
public int numberofdoors = 0;
public int horsepower = 0;
public int cost =0;
}

Then in the main you will create the instances and set their values:
file: Cars.java

import javax.swing.JOptionPane;
public class Cars{
public static void …
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

And if you are to post this in an sql forum try to make it a little bit more readable, because I didn't understand much about what you are trying to do

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

The following algorithm is wrong. If the array has all negative numbers then when you give as initial value zero: (max=0), zero will always be greater than any number in the array. So the result max number will be zero even if the array has not this number.
Max, or min should be initialized with one of the values of the array (preferably the first):

max=array[0];
min=array[0];

and then you should use the for-loop described in the code.
But the bottom line is that initializing the max or the min with zero is WRONG, because you don't know the values of the array you want to search.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I copy-pasted your code and run it and it worked fine. The result I got was:
238.14 + 515 - 126.3616
result = 626.7784146484375
What was your problem?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Why use your e-mail to discuss this with other people? This is why this forum exists. You will get more responses using this forum, instead of having to answer every mail you get. It will be easier to get more replies to your questions.
And what did your teacher asked you to do and what don't you understand?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

That's because there isn't such a method. If you check the API Math.min takes only 2 arguments.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You already have a for-loop, you don't need another while-loop.
Max should be initialized with one element from the array, preferably the first so you can start your loop from i=1:

max=arr[0];
for (i=1;i<arr.lenth;i++) {

}

When you write: int max=0,i; you declare i to be an int, so you don't need to declare it again in the for loop:

for (int i=0;)

Could be:

for (i=0;)
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

No one here is going to do your homework. And when your teacher tells you to write a software, he will probably give you some notes in class. If you attend the classes, pay attention to what you teacher says and study the notes you keep, you will not have any problem doing this assignment. Just post your code with your questions and many people here will help. But don't expect

good programmer/developer

(as you said) to help you they way you want to.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

What are the problem specifications. How are you supposed to produce the image and post your code using tags.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

It should be like this:

"insert into emp(total) values("+total+")" if the total column is type NUMBER in the DB

or like this:
"insert into emp(total) values('"+total+"')"

Use System.out, before you are executing queries in order to see what is executed, so you can use it in an sql editor and debug:

Srtring s="insert into emp(total) values('"+total+"')";
System.out.println(s);
con.updateQuery(s);
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

FirstAglet.java:3: package com.ibm.aglet does not exist
import com.ibm.aglet.*;
^

Do you have the package where the aglet is implemented: com.ibm.aglet ?
You need to get the jar file of the package or the class files in order to be able to import them. The program of your friend runs because he gave you the class file which was already compiled at his computer with the package.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

There is an error because argument1 is an Object and can't call the xyz method. Remember
the class abc may be an object(meaning you can use it as an argument at the method)
but an object is NOT an abc class(meaning that the argument Object does not have a method named xyz).
That's because you could have called that method with any other argument (an other object but not an abc class) and then your method would throw an Exception.
If you want it to work try:

methodname (Object argument1)   //argument1 is instance of class 'abc'
{
       (abc)argument1.xyz();  //xyz is method in class abc,
}

It will again throw an Exception if you use as input an object that is not abc

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Two ways:

First: Use javascript: Instead of type="submit", use:
<input type="button" value="Button" onclick="someMethod()"/>
Inside the someMethod you can check the length of the inputs in order to see how many were given ans act accordingly: submit the form or print an error message with the alert() function.

Second (Not as good as the first): Submit the from and when you get the values of the inputs use java to check their length. Then if you don't have enough inputs you redirect to the previous page in order for the user to give the right inputs.

Finally, I would suggest that you make your question to a javascript forum

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Have a table in the database where you store which options each user is allowed to perform. Then when that user logs in you can query that table to see which actions the user can perform.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

First create a class Ferry with the necessary attributes and method for adding passengers. Use the assignment's specifications in order to find out what methods you should have and they should do.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I think, masijade, that he wants to call this method:whateverMethod(Object obj) with any kind of object and for the method to do what is necessary every time dynamically. Meaning that I don't think that he intends to check what type of class he is passing in order to do casting.
Perhaps if he wants to save the object he is passing, he should consider serializing/desirializing

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

hello,
I am beginner in java . I have very difficult assignment so I need some one guide and help me.
can you help me .
with best regards

Then create a new post and state what you cannot understand and what is your problem

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

In the form tag you must put the url in the 'action' attribute and in the 'method' attribute you put post or get:

<form action="someurl" method="post">
...
</form>

When you submit the form you send the information that are inside it to the given url
And I would suggest to use .jsp to build your pages not servlets

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

From what I understood you have declared the array to contain objects, but you insert Strings. Why don't you create a class with two attributes: name and description and insert that in the array. So when you get the object from the array you will have access to each of these values separately with get methods(getName(), getDescription()).
Now, about your problem:
If you have declared the array to be an array of objects then when you get values of the array you get an object. ex:

Object [] array=new Object[5];
array[0]="Name:Description"

the array contains objects, you insert String which is an Object.String is an Object
BUT when you do this:

String s=array[0];

it is wrong because the array returns an object, not a String:Object is NOT a String
and the method substring applys only for Strings not objects, meaning that you should use casting:

String s=(String)array[0];

If the object that is inside the array ia a String then the casting will work, otherwise it will throw an Exception

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Any beginner's java book has examples on how to create gui using javax.swing.If you don't have already such a book search the internet for tutorials. And check the java API for the following classes:
JFrame, JPanel, JTextField, JPasswordField, JButton, JLabel
And the interface ActionListener

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You have a value in milliseconds. You can either use SimpleDateFormat, or do it yourself using the following rules:
1 sec = 1000 millisec
1 min = 60 sec
1 hour = 60 min

And sorry about my last post, I made a very big mistake: You must divide by 1000 to get the seconds

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

What you see is in milliseconds. When you get the difference, multiply by 1000 and you will have how many seconds have passed

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

At what line do you get that Exception?
And it means that you are trying to access an array with a counter that is bigger than the length.
Check all your arrays and try to debug by putting system.out.println(); before you access an array by printing the counter you are using:
ex:

System.out.println(looq+" "+interest1.length);
interest1[looq];

just to see what values are you passing before the exception

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

First of all you don't say what is your problem and what is your question. You just post code you have written.
Second of all, the main method is void, nad like any other method that is declared void cannot return anything so this is wrong:

if (tax > 180000) tax += income * 15 / 100;
[B]return tax;[/B]
}

It should be System.out.println(tax);

And you have one extra bracket '}':

return tax; //[I]this is the one that closes the main[/I]
}



} // end of main method
} // end of Taxesforresidents class
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You will not be obligated to write something like:

try {

} catch(IOException io) {

}

in your code. Meaning that if a method throws an IOException you will not have to catch it but if it is thrown there will be no place for the exception to "go" since nothing calls main(), so the program will end with exception.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster
public void foo() throws Exception {
  //something happens and an exception is being thrown
}

With the throws you don't avoid the exception. By adding throws you don't have to catch it, but it is thrown to the method that calls foo. Meaning that you have to write something like this:

public void hoo() {
  try {
    foo();
  } catch (Exception e) {
  }
}

You can omit try-catch by adding throws Exception at the declaration of hoo() but you don't avoid it because it is thrown to the one that calls hoo(). You can do that until you reach main() where you will eventually have to catch it in the end

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I don't think you can instantiate an abstract class.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You can write whatever you want if this is the way you want to convert "asu" to a String. As it was said in the first reply what do you want to convert "asu" to?

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

You must add the Panel to this JFrame

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Create first the gui for login, using javax.swing. Then when you click the button you will have to read the file where the users are stored (if you know how to write into the file since you said that you are done with the registration part, you would be able to read it as well) And then check the given values with the ones from the file.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Piers said:

Use Split. Go to the java API and it will tell you how to use it.

split is a method of String class

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I am not going to do your homework for you. I gave the code for reading lines from a file. Each line is stored in the String: String s=bReader.readLine();. What you do with the string is your job. Is not that difficult; use StringTokenizer, or split(), and then make the necessary checks.
I don't know what the assignments says, but you could create a class with 3 attributes. Every time you read a line, create a new object with values, the values you get from the line, and store that object in an ArrayList, or Vector.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster
FileReader reader=new FileReader(new File("filename"));
BufferedReader bReader =new BufferedReader(reader);

String s=bReader.readLine();

The API says that readLine() returns null if the file has ended, so you can do something like this:

boolean b=true;
while(b) {
  String s=bReader.readLine();
  if (s==null) {
    break;  //file has ended
  }
}
javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

I found Java 2 Cadenhead & Lemay very useful. I have given it to others and said the best things about this book.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

That is because the variables you are using to store the values in tri() cannot be used outside that method; they are local variables and can be used only inside that method.
One suggestion is to make your methods non static, and declare the variables that you will store the values outside the methods so they will be global. Then since you are using two different classes you should pass those variables as arguments at the method where you are setting the text.

javaAddict 900 Nearly a Senior Poster Team Colleague Featured Poster

Where do you get your error at the following?
And why do you have size as an argument since you are calculating it in the method. It won't matter what value it will have when you call the method since it will take a new value; the size of the array.

well i have this print method but when ever i try 2 use it it give me an error illegal start of expression
so any idea

private static void displayResults(String[] rooms, int size)
{
int size=rooms.length;
JTextArea textArea = new JTextArea();
textArea.setEditable(false);

// Print Array output text area:
for ( int i = 0; i < size; i++ )
textArea.append(rooms[i]+"\n");

// Display the Array via a message dialog box:
JOptionPane.showMessageDialog(null, textArea);

}