Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

In all likelihood it's still due to misplaced brackets or you still have functions defined within functions. This is why proper indentation is important. It makes such things much more apparent.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You have leftSide() and rightSide() methods declared within the body of insertMoney(). Check your brackets.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Because you have return statements in both branches of execution (the if and the else blocks), any code after that block is unreachable. If you need code after that block then you would have to restructure it to get the returns out of those blocks.

public int function(){
  int result=0;
  if ( ){
    result= someFunction();
  } else {
    result= someOtherFunction();
  }
  // do more stuff if you have to
  return result;
}
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Your increment statement is after the return statements. There is no way that code can be reached, which is I'm sure what the compiler is telling you.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Knives handle up, everything else handle down.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Foot to rear can be very effective communication.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Yes, those components are not part of the Java SE API so you will need to provide classpath entries to the locations of the jars containing the Java EE api implementations. There should be some info in your Tomcat docs on how to compile those source files.

This article may be helpful as well. http://www.sitepoint.com/article/java-servlets-1/3

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, the design still seems a little bit questionable, but then I don't know the context of the larger project. Anyway, the issue you have above with the resetTimer() call not responding is probably due to bootstrapping the thread from within the Runnable and lock monitor contention on the synchronized methods.

Here is a slightly restructured version that does behave as you want.

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Counter extends Thread {
    
    boolean timerRunning = false;
    
    volatile int s=0;
    
    public Counter() {
    }
    
    public void run(){
        timerRunning=true;
        startTimer();
    }
    
    public void resetTimer() {
        s=0;
    }
    
    public boolean timerRunning(){
        return timerRunning;
    }
    
    private void startTimer() {
        while(timerRunning) {
            try {
                Thread.sleep(1000);
                s++;
                System.out.println("TIME : " + (s/60) + ":" + (s%60));
            } catch (InterruptedException ex) {
                //ex.printStackTrace();
                timerRunning=false;
                Thread.currentThread().interrupt();
            }
        }
    }
    
    public static void main(String args[]) {
        Counter c = new Counter();
        

        String CurLine = ""; // Line read from standard in
        
        System.out.println("Enter a line of text (type 'quit' to exit): ");
        InputStreamReader converter = new InputStreamReader(System.in);
        BufferedReader in = new BufferedReader(converter);
        
        while (!(CurLine.equals("quit"))){
            try {
                CurLine = in.readLine();
                if (c.timerRunning()){
                    c.resetTimer();
                } else {
                    c.start();
                }
            } catch (IOException ex) {
                ex.printStackTrace();
            }
            
            if (!(CurLine.equals("quit"))){
                System.out.println("You typed: " + CurLine);
            }
        }
        c.interrupt();
    }
}
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Your intent is a little bit vague here. You need to wait for a string before actually doing anything and you also want to keep track of the time between two entries? In the first case, why not just wait for the input before starting the thread and for the second, variables that use calls to System.currentTimeMillis() should suffice.

It's hard to address those much more specifically without understanding more of the context.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

In short, you can't clear the console without system specific calls. You can write a bunch of blank lines to scroll everything to a point it looks clear, but that's about all without "workaround hacks".

If you want full control of the screen that you are running in, you should make the application a GUI application.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I think the null pointer exception is occurring from the printStream.println() call, rather than the exec() call. You haven't initialized "printStream", so when the error from that exec() command is thrown (which is that "cls" is not a program, by the way), the catch statement is throwing the exception out to main().

To execute a command, you have to use "cmd /c <command>". However, if you are expecting that command to clear the command window in which you are running your program, it will not. Runtime.getRuntime().exec() creates a new separate process.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I don't see any reason why you would need "threadMain". The monitoring threads can run just as well in a single main application/controller context. You certainly don't want those threads to be statics. They should be private members of whatever class is acting as the controller context of the application.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Usually the characters are necromancers or warlocks, so kind of an "archaic evil" kind of thing.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Try using a BufferedReader with the readLine() method.

String line=null;
while ( (line=reader.readLine()) != null){
  // do stuff
}
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Mine is just an RPG character screen name I've used many times over the course of several years.
And no, I'm not Jewish nor do I play one on TV. (Evidently some think it's a Jewish name)

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

No, it is not possible. Main() is the only method that can be run with the "java myClass" call from the OS.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You actually do not need classes for the input at all, as they are just making a single call to show your input dialog. A class isn't needed to wrap a single function call. You can put a small helper method in your Calculate class which handles the input part

public static int getInput(){
  int inputValue=0;
  try {
    String input = JOptionPane.showInputDialog("Please enter an integer");
    inputValue = Integer.parseInt(input);
  } catch (NumberFormatException nfe) {
    JOptionPane.showMessageDialog(null, "Entry is not a valid integer.");
  }
  return inputValue;
}

and simply call that method to get your inputs in the main() method. (The method has to be declared static to be used from main() )

int input1 = getInput();
int input2 = getInput();

The class to evaluate the numbers, let's call it Evaluator, should have a separate method for each function that you want it to perform. Each should take the number to evaluate as a parameter and return true or false for the evaluation.

public boolean isGreaterThan100(int value){
  // your code here
  // return true or false if value is greater than 100
}

public boolean isNegative(int value){
  // return true or false if value is negative
}

This separates the functionality of the evaluator to it's individual parts and clearly indicates what it is supposed to do for you. Furthermore, if you wanted the isGreaterThan100() method to be more widely useful, you could let it take two integer inputs : the input value and the value you want to compare …

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Depends on how you define respect. Ann Coulter's two main abilities in the arena of respect are: 1) The ability to articulate what a fair number of conservatives tend to think,

She may articulate what many conservatives think, but the majority of them would certainly have more tact in the phrasing and in some of her more extreme cases they would never voice those opinions aloud. (http://en.wikiquote.org/wiki/Ann_Coulter)

and 2) The ability to seriously unhinge ticked off liberals. For some reason, that brings the image of a vampire being shown a mirror to my thoughts...

Yes, she certainly can do that. Though doing it in such a "political shock-jock", "high-toned bitch" manner, she also offends more than just the "ticked off liberals".

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

It's still unclear why you are hung up on the linked list thing. You mentioned that you wanted to make it easier to insert in the middle, but is that the only thing you require?

Though we got a bit off track with the linked list discussion, javaAddict's suggestion of ArrayList is perfectly valid if you just need a container that's easier for you to manage. It is backed by an array, but the ArrayList API manages all the manipulations internally and you just have to call the methods to add/remove/get any component you wish. Is this homework that will not allow you to use standard API collections? If it isn't, then consider just using an ArrayList for the collection.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Couple of ways to do that

try {
    Calendar calThen = new GregorianCalendar();
    calThen.setTime(new SimpleDateFormat("MM/dd/yyyy").parse("12/15/2003"));
    Calendar calNow = Calendar.getInstance();
    System.out.println("After = "+calNow.after(calThen));

    Date dateThen = new SimpleDateFormat("MM/dd/yyyy").parse("12/15/2003");
    Date dateNow = new Date();
    System.out.println("After = "+dateNow.after(dateThen));
} catch(ParseException ex) {
    ex.printStackTrace();
}

Calendar is the intended way these days, since Date is deprecated. But the whole Date / Calendar API is still somewhat of an awkward mess.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I would hope that your class would have. You do have some notes I assume?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Ann Coulter is a highly respected spokesperson for the ultra conservatives in the US, an author of many good books, and a frequently invited visitor to the White House.

I don't dispute any of that except for the "highly respected" part.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

See the following example on comparing dates: http://exampledepot.com/egs/java.util/CompDates.html?l=rel and you can find a lot of information on using the date-related API classes here: http://mindprod.com/jgloss/calendar.html

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Ann Coulter is quoted as saying:
"I rather vote for Hillary Clinton than John McCain!"

But then, Ann Coulter is a waste of oxygen, so it doesn't really matter I guess...

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

sounds good .... or how bout 'a junior poster in training' actually gets access to some training material from the site.. or he's assigned an expert as a buddy who he can go to once in a while for help :)

The site is the training material. And since the experts here are just volunteering time to help answer questions, I don't see as to how they could be "assigned" to anyone. Help is already given if they wish to help - to new posters or veterans alike.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, that is about the longest way around the problem if you simply want to know the java version from within a program. All you need is

System.getProperty("java.version");

There is a lot of other info available as well

for (java.util.Map.Entry s : System.getProperties().entrySet())
            System.out.println(s.getKey()+": "+s.getValue());

But all that is completely irrelevant if you are trying to check to see if java is installed on a machine. If Java isn't installed, Java code won't run. You will need a batch script or something else if you want to check for Java before running or installing an application.

The original poster does not explain the context, nor what the he/she needs to do with that information. Without a little more detail, you can't really provide a sufficient answer.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

plss give me some basic example of sorting with user input!!!! thx

Sorry, we are here to help with code that people are having trouble with - not provide example code on demand. Post your efforts and specific questions about the trouble you are having. If you haven't made any effort yourself, you're out of luck.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Thanks so much for replying.But i think there is more to my question.
1. i want to create panels with it [

So have the class extend JPanel then and create a JFrame for it in the main() method. Not difficult to do at all. You should also put your painting code in paintComponent() for the JPanel, instead of paint().

2.i also need a code that will make me fill any shape i draw with any colour
Iwill be very grateful if am attended to.thank you so much again

Darkagn already told you that you can use the fillXXX() methods to draw a shape that is filled with the current color. You can have a color picker for choosing that color if you wish. If that isn't what you need to do then you need to explain your question further.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You can accomplish it quite easily with either regex (see Pattern and Matcher) or with a simple String.split(",") to separate the pair.
For the date part you can use SimpleDateFormat if you need to parse to a date value from the string.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I'm not seeing any problem with how you have built the jar, nor with the manifest. If you had a package statement in ExportTest.java, it would cause that kind of class path error, but beyond that it would come down to spelling errors, etc.

Nothing really stands out as a problem.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Are you running it from the command line with

java -jar extract.jar
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Looks mostly fine to me. Do you have any package statements in that class file?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Those calls were not in a method, they were in the class body, which the compiler will read as attempt to declare the method with an invalid signature.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

It's ironic that this has come up in the "Ways to reduce stress" thread :)

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

It was just a suggestion and followed with

and if you can't, don't give out a cry when someone fights fire with fire.

.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Not in his case, if the change is 0.38, he would want dimes to equal 3, not 4.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Why do you need to run the OS command instead of using File.delete()?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I consider being called "a despised cocky kid" and insult! Watch your poor manners!

Perhaps you should consider your own. They aren't exactly shining here.

Sulley's Boo commented: :D +4
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Sorry, I didn't know we live in the Ezzeral country and use the Ezzeral forum.

The point is that the First Amendment has no bearing at all on private forum posts. It only applies to government action against free speech.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

> ArrayList still has nothing to do with a linked list, both are array-backed, so it doesn't really
> matter.

A linked list is not array-backed but composed of a chain of nodes, each pointing to the next in the chain or null, in case of the tail element.

Yes, that was my point. He mentioned using Vector and then ArrayList - neither of which have any relation to a linked list. Perhaps my use of "both" wasn't really qualified there very well. I was referring to the previous suggestion of Vector.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Can someone please suggest...

Yes, and I did.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster
public class Card
{
[B]getSuit();  // These are invalid calls - you cannot do this here
getRank();[/B]

[B]// you have not declared rank and suit member variables

// you can have a static array for the rank values here and initialize it with 
// a static block.[/B]

publlic Card(int rankNum, String suit)
{
      [B] // this won't really do anything for you at all and will
       // not compile because rank is not defined[/B]
       for (int i=1; i<14; i++)
       {
      rank = Integer.toString(i);

      }

     [B] // with the static rank value array you can assign the value of the rank string
      // with a simple array lookup
      // rank = rankValues[ rankNum ];[/B]
     
}

public String getSuit()
{
[B]// just needs to return the suit string - no array here[/B]
String  suit [4]={"spades","hearts","diamonds","clubs"};
return suit;
}

public String getRank()
{
[B]// Same here - return rank - no array needed here[/B]
String  suit [13]={"ACE","2","3","4","5","6","7","8","9","10","Jack","Queen","King"};
return rank;
}
piers commented: you have helped me a lot with java thnx +1
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Regular expressions, Scanner, or String.split() will all work for that.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, you are showing two different file names there, so that might be a problem. If you are having difficulties with specifying a relative file path, make sure that path resolves correctly against the current user directory, which can by checked with System.getProperty("user.dir").

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

ArrayList still has nothing to do with a linked list, both are array-backed, so it doesn't really matter.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Hmm, looks like there is no such thing as the First Amendment in India.

Which has absolutely nothing to do with posts on a forum.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I don't know, but I would imagine the homework assignment entails whether you can prove it.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

What you are wanting to do isn't making any sense to me, so I can't answer the question very well. A linked list does not reference an array. It functions by maintaining links to the next (and sometimes previous) entry object in the list. So I'm not really sure what it is that you are wanting to acheive.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You aren't very clear in what it is that you are wanting to do. What is the point of using a linked list in one class to access an array of objects in another?

You'll need to post a bit more information.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

In all likelihood, yes, you'll have Java at some point in your CS courses. Visual Basic is a lot less likely.