Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, it's quite easy if you put those entries into a collection of objects as you mentioned in your last thread. You just scan the collection for the ones that fall between the upper bound and the lower bound.

Did you have a more specific question?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Ah, never mind, it is not the Console method. On that line you are calling

cc.setAcctTypeCode(Console.in.readInt());

but you haven't initialized "cc" yet. You can't call methods on objects that are not yet created.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I think the problem is most likely with your Console.in.readInt() method. Are you sure this Console class is working correctly? Why not simply use Scanner for reading the values?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I've not yet heard any reason why "java is different" from anything else, or why that would matter.

Hardly surprising, as most arguments come from people who have no clue yet have strong opinions based on personal preference or irrate hatred of Microsoft (caused in itself by jealousy above all else).

In other words, another pointless discussion about this topic (which is in itself pointless) like there have been so many in the past.

Agreed.
Just let dead horses lie.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Also, please use the search feature in this forum for "inventory program" and see what help you can gleam from those threads. We have helped a few people with this exact assignment series recently and there are many posts.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Post the errors that you are receiving and what problem you are having with it. You can't expect others to read the entire code line by line and debug it for you.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

How would I call the function in main without defining it as a method? I think I'm missing a pretty large chuck of the puzzle....

He was trying to say that your method needs to be separate from main - not written inside it.

public class MyClass{

  public static void main(String[] args){
    someMethod();
  }

  public static void someMethod(){
    // do some stuff
  }
}
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

And because that is how they designed the language specification.

"Why" doesn't really matter at this point does it?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Does anyone have time to look over a 3 class program? I get a NULL POINTER ERROR. What is the best way to debug a variable that produces this error? Thanks

Yes, as mentioned, the stack trace should tell you which method the error occurred in and the line number.

You can also use "if" checks and System.out.println() to verify variables if you are having trouble locating the problem:

String s = null;
if (s==null)
  System.out.println("a is null here!");

or you can use assertions

String s=null;
assert s!=null : "s is null!";

To use assertions, you must run the program with the "-ea" flag to enable them (ie "java -ea MyClass"). If the condition of the assertion is false, it will stop the program with an assertion error and show the message that you have supplied.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You really don't need to cancel execution of the method, just don't perform any other actions after the display of the message. It looks like your current method will do that just fine as it is. Just remove the System.exit() call.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, if you have parsed the fields into an array for each line, such as with split(","), then you can just create the new Student object and set each property from your field array. Then add the Student object to a HashMap with the id field as it's key, ie studentMap.put(aStudent.studentNum, aStudent); Student objects can them be retrieved from the map by id.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You just need to declare them at class level. You can initialize in the constructor as shown or in whichever method reads the first question. Subsequent calls to get the next question just use the same scanner.

class MCQquestion extends JFrame implements ActionListener
{

    private static final int WIDTH=550;
    private static final int HEIGHT=200;
    private static final int HLOC=340;
    private static final int VLOC=290;
    private JPanel pnlQ, pnlA,pnlButton;
    private JLabel lblQuestion;
    private JFormattedTextField txtAnswer;
    private JButton btnNext;

    //Not Sure what u meant... Im totally new to Java..
    //but declaring it here, at class level generate 'unreported Exception' during compilation
    //where do i insert throw IOException
    //Try n catch dint work at class level..."invalid declaration.."

    File questionFile = [B]null[/B];

    Scanner questionInput = [B]null[/B];
    

    public MCQquestion()
    {
        [B]try {[/B]
[B]           questionFile =  new File ("question.txt");
           questionInput = new Scanner (questionFile).useDelimiter("//");
        } catch (Exception e){
            // deal with exceptions here
        }
[/B] 
        lblQuestion =  new JLabel();


        try{
                        MaskFormatter ans = new MaskFormatter("U");
                          txtAnswer = new JFormattedTextField(ans);
                          txtAnswer.setPreferredSize(new Dimension(40,30));
                    }

         catch(ParseException pe)
         {
              System.out.println("Error: " + pe.getMessage());
         }

    .... the code continues...
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

and this?

int myInt = 5;
String myStr;
myStr = myInt.tostring();

Is invalid. Primitives like int are not objects and do not have methods.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You need to declare the method like

public static [B]int [/B]getCalculation(){
   // do your calcs

[B]  return calc;[/B]
}

and you can show it like so

int percentComplete = getCalculation();
JOptionPane.showMessageDialog(null,"percentage of chapters read: "+percentComplete,"",JOptionPane.INFORMATION_MESSAGE);
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

There is a ton of info in that tutorial now that I look into it and it might be a lot to digest at once. Here's a quick example of invoking main() on a class by name

try {
            Class c = Class.forName("HelloWorld");
            Method mainMethod = c.getMethod("main",new Class[]{String[].class});
            mainMethod.invoke(null, (Object)new String[0]);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Instantiating a class at runtime like that can be done through Reflection. See the following info:
http://java.sun.com/docs/books/tutorial/reflect/index.html


Class.forName() will allow you to get a Class instance for a given full (including package) class name.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Just parse the lines from the text file into its fields, create the Student, and I would suggest you could use a HashMap if you want to access the Students by their ID.

You have already posted several threads about reading a field from text file, so I find it hard to believe you cannot see a starting point for this. Post your code if you have problems with the implementation.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Check the API on JOptionPane. showMessageDialog() is a void return - you can't assign it to a variable.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

show = String.valueOf(calc);

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Declare the scanner at the class level and do not re-open it in the listener. Let it use the one you have already opened.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Why does your listener need to extend JPanel? Your class can just implement KeyListener or extend KeyAdapter and be added to a component with the .addKeyListener( new MyListener() ) call. When a key is pressed in that component, the listener will fire and you process it accordingly.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Not sure exactly what you are referring to with "precasting". There is casting

List pointList = new ArrayList();
pointList.add( new Point(0,0) );
Point p = (Point)pointList.get(0); // you must cast Object to Point here

or you can use generics to "pre-cast" and declare the type of collection

List<Point> pointList = new ArrayList<Point>();
pointList.add( new Point(0,0) );
Point p0 = pointList.get(0);  // no need for the cast here

Is that what you are wondering about?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

So any child class of Super is going to begin with a height of 1 and width of 2.
You could then add things such as area, volume and other attributes from that base.

Could you also change one of the original attributes? Say if I wanted to call Super, but make the newest object have a height of 2.

Yes, you can change the base class variables as long as their scope allows. With no scope modifier, the variable is package-protected, which means other classes in the same package can access it. Protected access will allow classes in the same package and also any subclasses to access it. Public allows anything to access it. If you declare it private though, not even the subclasses can access the variable.

no1zson commented: always helpful +1
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You cannot define methods within other methods, which is where you are trying to put ReadInteger. You have it declared in main(). Also, readInteger() should read an int input, which you must write the code for - just writing a declaration line won't do anything.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Super can also be used to call a parent class method that you overriding to extend the original functionality. i.e.

public void someMethod(){
  // go ahead and do what parent class has defined
  super.someMethod();

  // now do a few other things that this subclass needs...
}
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Sun's tutorial is a good palce to start.
Tutorial: Writing a Key Listener
If you still have unanswered questions after that, just post them here :)

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster
int myInt = 5;
String myStr;
myStr = "" + myInt;

Yes, this does work, but it is not an efficient way to go about it. As I posted above

int myInt=5;
String strValue = String.valueOf(myInt);

is more appropriate.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Post the code that you do have, or pseudocode for the algorithm and specific questions that you have about implementing it in Java. The forum is for Java help - not implementations by request.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Have you tried adding

setLocationRelativeTo(parinte);

after the super() call or before show() in your dialog constructor already? You mentioned the method in your original post but not whether you had used it.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, you don't define a class at all - just a main() method. Methods can't exist on their own, they must be in a class. You also don't define the readInterger (sic, misspelled Integer) method either, so you can't call it until you define it.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, after finding this bug report http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4102292 I tried running your app on the oldest JDK I have here, 1.4.2, and it still functions fine for me. The dialog is always centered in the frame. Are you running this in Windows or some other OS? I'm at a loss as to the cause if you are using Windows and a recent JDK.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

The dialog is centered in the frame when I click the button. Where is it appearing for you?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

my Dialog class is used inside the main window class, so i`m using "this" in Dialog`s object constructor, but the Dialog window is not centered;
please let me know if you want to post the code

Yes, the code would probably help. If your main window class extends JFrame and is valid and visible when the JDialog is shown, then using "this" for the owner should be all that is needed.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

actually i still have problems with regards to this project of mine, GUI is really not the priority, il post a new thread with regards to it, tnx

And use code tags! Both here and in the other post, you have posted a huge wall of code without any formatting, which no one wants to wade through. Please read the announcement at the top of the forum and use code tags as requested.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

If you pass the JFrame reference as the "owner" parameter to the JDialog constructor it will center on it. Example:

JFrame frame = new JFrame();
        frame.setBounds(200,200,300, 400);
        frame.setVisible(true);
        
        JDialog dialog = new JDialog(frame,"test");
        dialog.setVisible(true);
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Ellipse2D.Double ellipse = new Ellipse2D.Double(0,0,getWidth(),getHeight());

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

If the discount rate is fixed, why do you even need a setDiscountRate method? It seems like all you need is a getDiscount() method that returns .20 * invoiceAmountBeforeTaxes . Then total invoice is (invoiceAmountBeforeTaxes - getDiscount() ) * 1.0775 assuming that .0775 is your tax rate.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

so, that's JAVA!
but when I was using it, I think I did something before!!!!!!!

Well, yes, this is the Java forum, so posting something that is not valid Java code is less than useful.

Honestly, I cannot even fathom what you are trying to say in the second line of that comment...

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

you don't have any problem to cast int to string
int myInteger = 25
String myString = myInteger;

what's your problem?!

This is not valid at all.

To the OP, use String.valueOf(int value).

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, the math that it is performing is very straightforward. Do you mean to increase the "discountRate" by 20% of "discountRateBeforeTaxes" on every call to setDiscountRate()?

You would probably be better served by breaking those calculations into multiple steps if you aren't getting the results you expect. Then you can place System.out.println() calls to verify the calculations after each step.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Do you mean JAVASWING for 2D Graphics?

Well, your graph would be on a JPanel, but you would override paintComponent() with your own code to generate the shapes, lines, etc. Here again is the link to the tutorial on 2D graphics: http://java.sun.com/docs/books/tutorial/2d/index.html

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

If you are using the DefaultTableModel for your model, you can call removeRow(int row) . If you are using your own custom table model then you must implement it yourself.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster
String.valueOf(x);
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Why don't you ask on the vBulletin forums??
http://www.vbulletin.com/forum/

For specific apps like that you're better off starting at the source.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You may want to look into using osCommerce for the site:http://www.oscommerce.com/

There are many people that do custom templating for osCommerce if you need that service.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, without a database you will have to hardcode every condition as an if statement, but if that is really what you want to do then...

$makems = $_GET['makems'];
if ($makems==83){
  // place the audi banner
}
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

What? Your post does not make any sense at all. Please provide a bit more info on what you are wanting to do.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You did not post what error you are receiving.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You need to look into optimization.