What do you need help with? Please try to be specific as we are not allowed to just do your work for you.
PS This thread is 18 months dead, please check the dates before performing a resurrection.
What do you need help with? Please try to be specific as we are not allowed to just do your work for you.
PS This thread is 18 months dead, please check the dates before performing a resurrection.
http://gcc.gnu.org/ is the official site for the gcc compiler. Latest version was released in March this year and is version 4.3.0. Note that it is actually a standard compiler that is usually included in a standard install of Linux or the Mac OS as well. So you probably only need to download it if you are running windows.
to determine the length of the boundary of an irregular polygon.
The polygon may have between 3 and 9 sides.
The user should be prompted to enter the number of sides and the coordinates of each vertex point.
The program should then calculate and display the total length of the boundary.
You should write a main function to implement this using your Point and Line classes and test the program thoroughly.
It seems as though you've done everything up until this point. For this section you need to:
All of this needs to be done inside a main method in order for it to be run.
Give that a go and repost if you still have problems. :)
I am assuming that your main question is about accepting user input since that is underlined. You will need to use an InuputStream of some form or another for the standard input of System.in to accept input from a console. Something like:
BufferedReader input = new BufferedReader( new InputStreamReader( System.in ));
will set up a buffered reader for you that reads from standard input. Then you can use the BufferedReader's readLine() method to read a single line of input.
As for the rest of your program, as jasimp said we aren't allowed to do it for you but we will answer specific questions. Have a try and repost if you get into trouble. :)
Hi antony_24 and welcome to Daniweb,
What's the application doing when the bug occurs? Especially, what are the various threads doing when the bug occurs?
I'm sorry sbv but I don't understand your question. Are you asking how to determine the score as a percentage if you have an average mark for someone?
I think you will need to use the getInputStream() and getOutputStream() methods in the Process class to be able to do what you want to do. Basically you can use the I/O streams to communicate with the Process and then you can use the output from the Process to work out whether your command is successful. This might require a bit of trial and error, so I'll leave you to have a go at it.
I'm not sure if this is what you are after, but I think the java.text.NumberFormat abstract class might help. It provides a static method called getIntegerInstance() that can be used to create a formatter for your floating point numbers to round them to integer digits. I can't quite tell from the description of your problem if this is what you want or not, but take a look at the API and see if it helps.
Yes your pseudocode will work, but may I make a suggestion? My pseudocode would be:
if ( isEmpty() ) {
return;
}
E item = remove();
add( item );
Now, both your code and mine will do the same thing, but mine will be easier for someone else to read. You may argue that all that the remove method does is call poll(), but just by looking at the moveToRear method, which one is easier to work out what is happening? Same goes for add and offer. But why did I say isEmpty rather than front == null? Again, I think it is clearer to say "is the list empty?" rather than "is the front Node null?" but that's just my personal opinion.
You just write a new method in each of those classes called
void overiden( int access )
Then when an object of type Widget calls the overiden method, it will use the implementation in the Widget class. Similarly, a Spork object uses Spork's implementation and a Grommet will use Grommet's.
Where it gets really interesting is when Part's overiden method is not declared as abstract and the subclasses each override the method. They can call super.overiden(access) in order to call Part's version of the method, and then go on to do some more things as needed. This allows for code reuse, efficient maintenance of code and is a common theme in object oriented programming called polymorphism.
I think Vernon's suggestion will fix your problems. This is a common mistake when first learning Java and other C-style programming languages. Saying '=' is an assignment to a value statement, saying '==' is a test for equality. In other words the statement
housing = 2
means "set 'housing' equal to 2" while the statement
housing == 2
means "is housing currently equal to the number 2?" which can only be a true or false (boolean) answer.
Also, is there an error in the code you have to add to? There appears to be two methods called remove() which is invalid since the take the same parameters (none).
EDIT: Ignore this, one of the methods is in an inner class (my mistake, sorry :$)
I'm not sure what the "gwordsomething" should be, but my pseudocode for your would go something like this:
if list isEmpty - return
E item = list.remove
list.add( item )
Now, take a look at those methods I have referenced and you will see that this should work. First, we check if the list is empty. If not, we remove the first element in the list and add it back in at the end.
The only thing I can think of looking at this code is: do you have an image file called LogoGIF.GIF in a subdirectory called JavaProgram2? Also, you have added the logoLabel to the panel, but you haven't provided the code where you add the logo to the panel or the panel to the rest of your GUI. Are you doing that?
You will need to take a look at the java.awt.Graphics and java.awt.Graphics2D classes. They provide methods to draw shapes to what is called a graphics context (eg screen, image, printer etc). So if you want to draw a shape to the screen in say a javax.swing gui, you override the paint method in an extension of JPanel (or a similar JComponent) and call Graphics.draw(Shape).
I have never used JScrollPane, but I believe that the "listener" functionality you want is provided in the default functionality of a scroll pane. Do you need to know where the user has clicked for some other reason than to scroll around the pane? If so, I think you should just add a MouseListener?
Here is a link to the sun tutorial on JScrollPanes.
I would suggest using Java since your main concern seems to be portability. Java is a cross-platform object oriented language and provides several API's for GUI development. The swing package in particular will be most helpful to you if you decide to go with Java.
Hi naiad08 and welcome to Daniweb,
We have some pretty strict rules here in that we can't just do the work for you, we need to see some effort and then we can guide you. What have you done so far? Where are you having problems? Do you know the difference between those sorting algorithms?
Thanks Ezzaral :) Will try this out and repost if I still have probs.
You can GET the date and time by using
System.currentTimeMillis();
This returns a long type that represents the number of milliseconds since Jan 1, 1970. You can format that long by using the java.util.Calendar and java.text.DateFormat classes.
What is clrscr()?
Hi all,
I am wanting to display an image that is aligned so that the centre of a string of text is in line with the centre of the image. I know the image's dimensions and the length of the string, as well as the font I am using to draw the text, but I can't work out how to calculate the coordinates of the centre of the string. I am using the java.awt.Graphics.drawString and drawImage methods to draw each part of my object. If I have set my graphics component's font to have a size of 12 say, does this mean that each character takes up 12 x 12 pixels?
Thanks in advance for any suggestions,
darkagn
True, to an extent, but it still works with a url, as it will be given a "file://" url, rather than an "http://" url. It is still valid.
I didn't know that - thanks masijade :)
Instead of
URL url = new URL( path );
BufferedImage image = ImageIO.read( url );
try
File imageFile = new File( path );
BufferedImage image = ImageIO.read( imageFile );
Generally URLs are only used for the internet, use Files for local stuff...
What's the error message you get?
I haven't used JFree_Graph before, but that stack trace has given you a pretty detailed description of the encountered problem. I'm guessing that your problem line of code is:
series.add(new Millisecond(), lastValue);
Try changing it to:
series.addOrUpdate(new Millisecond(), lastValue);
and see what happens.
That's not right!
char *tensWord[]
is an array of pointers to char. As I initiallised it above, it just so happens that the char being pointed to is at the start of a string/array of characters.
Sorry dougy83, you are correct, and thanks for helping my understanding. :)
Ok, so in your actionPerformed method, you put whatever code you need to do what you want when the button is pressed. Then you add the action listener to the button by writing the following:
myButton= new JButton ("Submit Grades");//inserting button
myButton.setBounds( 16, 45, 208, 218 );
myButton.addActionListener( new ButtonHandler() );
container.add(myButton);
That's all there is to it really...
You want to say "while the guess is not correct and counter is <= 3, do something" right? You need to change your line that reads:
while( ! function1.equals( selection ))
to:
while( ! function1.equals( selection ) && counter <= 3 )
The && means "and". This means that both statements must be true in order for the code inside the while loop to execute.
Another handy one is || which means "or", meaning that either statement can be true (or both) for the code inside the loop to execute.
EDIT: Too slow, and I didn't see the System.exit() statement...
We've just equalled our record number of days in a row above the old 100 degrees F and the forecast says it will continue for at least the next seven days. It's supposed to be autumn here...
You write it like this:
int main()
{
int x, y;
cin >> x;
cin >> y;
if (x==0 && y==0)
// the && means and, use || for or
{
cout << "x/y = 0";
}
else
{
cout << "neither is 0";
}
return 0;
}
const char *tensWord[] = {"", "ten", "twenty", "thirty", "fourty", "fifty", "sixty", "seventy", "eighty", "ninety"};
can i ask what is *tensWord[]? i think ur wrong in that part i think it's
const char *tensWord[][10] = {"", "ten", "twenty", "thirty", "fourty", "fifty", "sixty", "seventy", "eighty", "ninety"};
and it is right to use char only? why do you use const>?
You use const in this situation because the strings aren't going to change, you want them to remain constant.
The char * is an object type in C++ that literally means "pointer to char". The char *tensWord[] is a pointer to a char[].
and how about the 148 or any that has no exact pattern in one tens hundreds.??
The provided code will be close if not spot on for solving your problem here. It should print out "one hundred forty eight" because dougy83 has split the number into hundreds, tens and ones and then printed the result for each.
Ahhhh
Ok, your line at the bottom of your code that reads
String empName = input.nextLine(); // read employee name
remove the word "String" from this line.
The problem here is that you have already defined empName but you want to assign a new value to it. When you say
String empName = input.nextLine();
you are defining the variable but also assigning an initial value to it. After that to reassign a new value, you just write
empName = input.nextLine(); // get another line of input
Then when the loop comes back to the top it will check the same variable with the new value.
Hi jcato77 and welcome to DaniWeb,
jamesbien is completely wrong with his advice. But I am not sure about your question. Do you mean that the code inside the loop that jamesbien referenced never executes, or that it executes even when the user inputs the word "STOP"?
I am just saying that the loop wont execute N times. since each time it is incremented by j*5
okey fine, you should have mentioned at the very start that you dont want to answer.
Bye :(
Actually I am trying to help you discover the answer without just giving it to you.
How do you think the "j *= 5" part of the for loop affects the number of operations performed as the input size (n) gets very large?
This question was a bit misleading sorry.
What I meant was, how does the "j *= 5" part of the loop affect the way that the number of iterations grows as n gets large? Start with n=1, how many times does this loop iterate? Now try n=20, n=100, n=10000? Do you see some sort of pattern? Is it growing linearly or quadratically? Or something else?
Ah yes you are correct. The loop is not linear.
Your functions absolute(), fibonacci() etc are in a class called Main, but you have called these methods for a variable of type myFunctions. I'm not sure if that is what is causing your exact error from the compiler, but this can't be good...
Actually I think that loop is linear, so it should be O(n).
How do you think the "j *= 5" part of the for loop affects the number of operations performed as the input size (n) gets very large?
Hi there aishaahmad and welcome to Daniweb,
Sorry but we aren't allowed to just do your homework for you. Do you know what is meant by O(N) and why that loop is O(N)? Do you understand what the term time complexity means?
Also, you have two loops that don't increment by one...
Ah ok, now I see your confusion...
If I have a variable called kev that is a type BankAccount and I write kev.debit(), the program looks in the class BankAccount for the debit() function to run. However, if I am already in the BankAccount class, I can just write debit() and the program knows to look in the current class for the function.
As for your arguments, as in debit(25, kev), either can be modified, that's up to how you write the debit method. In the example code you posted previously, the kev that you pass in as a parameter gets modified by the amount 25. This is because the kev variable relates directly to the BankAccount parameter called amount in the function as it is the second parameter passed in.
I'm not sure I'm explaining this too well, so let me give an example. Imagine I have a class called Foo and it has one function, void bar( int i ). In another class I can write the following:
class Hello
{
int main()
{
Foo f = new Foo();
f.bar( 5 );
}
}
Now how does this code get executed? First the program creates an object of type Foo and calls it f. Then it performs the function bar() on the object f with the value 5 passed in as an argument. Where does it find the implementation of bar()? In the class Foo since f is of type Foo.
I hope …
The lines that read:
return result;
should be removed from your main method. The main method should just use that result variable rather than attempting to return it.
You can return your delimiters from the StringTokenizer by adding a third parameter when you create the tokenizer object.
StringTokenizer st = new StringTokenizer( input, delims, true );
Now your nextToken calls will return the delimiters as tokens as well. This will require changing how many calls you make in the next section of your code.
When you get each delimiter you can parse it to a char very easily:
// since we know the delimiter token has a length of 1
char del = ( st.nextToken() ).charAt( 0 );
P.S. Unless your assignment specifies that you must use a StringTokenizer, you really should listen to Ezzaral's advice...
You are probably better off using a local smtp server if you have access to one...
Hi there shinnxennosagga,
Please check the date of threads before posting a reply to them - you have just resurrected a thread that hasn't been used for three years...
Hi ekirkco,
Can I just ask why you use a signed shift in your write methods? I'm just wondering because I saw this in another example on another forum but it wasn't explained and I had trouble when sending data to another computer. I ended up using an unsigned shift and it worked, but I don't know why...
Hi gauravdott and welcome to DaniWeb,
For number 1, I would use the mathematical proof by iteration - ie prove the statement true for n=2 then assume true for n=k and prove true for n=k+1.
Number 2 is a little trickier but this link might help:
http://en.wikipedia.org/wiki/Kruskal's_algorithm
Kruskal's algorithm determines the minimum spanning tree of a graph. If you imagine each town to be a node in a graph and the telephone lines to be the edges, can you think of how you might find the minimum cost? I'm sure once you work out this part of the question, the next will be much simpler.
Good luck :)
Hi chapelhoffer and welcome to DaniWeb,
This question should probably go in the C++ forum, but now that we are here I will try to help you out.
Let's take for example your member function called debit. Inside your main function, if you want to debit a certain bank account you can go:
// debit the bank account called amount $123.45
debit( 123.45, amount );
Now what the program does when it runs is it gets to this line and it "jumps" to your debit function, executes the code in that function, then returns and continues from where it was before in main.
So why do we do that do you ask? Well in this example it's a little difficult to see. But the beauty of doing it this way is that imagine we had 100 bank accounts to debit different amounts in our program. Or 1000? It is much easier to just make the call to the debit function rather than just writing that code over and over. Imagine what would happen if one day you wanted to change the way in which you debit an account? You would have to change your program in many places, but doing it like this means that you only have to change it in one place. Much neater to say the least. ;)
Anyway, I hope this has helped, but feel free to ask any other questions if I haven't explained enough.