98 Posted Topics

Member Avatar for ksaihat

One method you can use is to start off with 2 integers that store the beginning of the Fibonacci sequence and loop through to modify them and iterate through the sequence. If one of the values exceeds the number you are checking, you passed it, so you know it's not …

Member Avatar for kvass
0
129
Member Avatar for Bobon

You have the right idea, but the main problem is in your equals() method that you created. Your method just checks to see if the inputted object is a date object. So for instance, calling if(check1.equals(check2)) will basically check if check2 is an object that is also a date. Since …

Member Avatar for kvass
0
101
Member Avatar for need

You need to clarify what you want better and specify the place in the code where you are having an issue. However, this might help you: [CODE=Java] Student s; /* ...More lines of code here... -- s may have been initialized or it may still be an empty pointer */ …

Member Avatar for Ezzaral
0
174
Member Avatar for Aisha25

I think what BestJewSinceJC meant was that you should be more specific with what is going wrong with your code. Are you compiling it and an error message shows up on a line? If so, what is the message? Or is it that your code compiles fine, but it crashes …

Member Avatar for BestJewSinceJC
0
991
Member Avatar for handrews3583

Wow... lots of errors... The first thing that strikes me is that you have several displayResults() methods, all with the same signature (double, double). It doesn't matter that you named the double variables differently in each displayResults() method -- Java identifies a method based on its name and parameters. You …

Member Avatar for handrews3583
0
216
Member Avatar for Egypt Pharaoh

double values tend to do that. I recommend having a method round the double value before printing it, so you only print a certain number of digits after the decimal point. A way I usually like to set the number of decimals is to multiply the double by 10^(number of …

Member Avatar for kvass
0
113
Member Avatar for Olliepop

Agreed, class Class is messy business -- you need to be sure you know what you are doing. Personally I like to use the equalsIgnoreCase() method instead of the equals() method for strings simply because the user might enter "Yes" or "yes" and you will want to evaluate such answers …

Member Avatar for Olliepop
0
106
Member Avatar for coolguy0201

Um, this isn't our assignment. And it's not your place to give commands like "reply to me immediately" if you are the one who needs help. Sorry kiddo, you'll have to figure this one out on your own. If you have a specific question we may be able to help …

Member Avatar for jwenting
0
101
Member Avatar for jtodd

On my computer it seems to be working fine. You should generally use the print command instead of printf -- it is much easier to read. Basically you just include whatever pieces you want and put them together with + signs: System.out.print("The Remainder is: " + answer + "\n"); You …

Member Avatar for jtodd
0
746
Member Avatar for DifficultUsrnme

Also if possible try to indent your code. It makes it much easier to read if each block of code is indented by 4 spaces (unless BBcode has a tab tag).

Member Avatar for BestJewSinceJC
0
130
Member Avatar for oneofakind007

A multidimensional array IS an array of arrays. A grid is basically an array running up-down with each element containing a left-right array. [ICODE]int[][] multiArr = new int[5][5]; //creates array of 5 elements, each element containing an array of 5 elements. (5x5 grid)[/ICODE]

Member Avatar for kvass
0
48
Member Avatar for jmguerriero

Welcome to Daniweb! If you want to post code in the future, please use the code tags (read the 2 announcement posts at the top of the forum). The code tags just make the code easier to read. As far as sorting is concerned, you have 2 options: you can …

Member Avatar for jmguerriero
0
554
Member Avatar for merrycit

Lets say you are using an integer as a counting variable: [CODE=Java] int x; for (x=0;x<10;x++){} //remainder of your code here [/CODE] If you want to access the value of x later the for-loop may not have been evaluated if the condition was [I]Never [/I]met, so x would be lacking …

Member Avatar for kvass
0
151
Member Avatar for saveyourselves

The first step is to write the Sandwich and Customer classes. These are in my opinion the best procedure when writing a class: 1. Define the various components of the state of the object (its properties). Set them all as private variables. 2. Create accessor and mutator (get + set) …

Member Avatar for kvass
1
218
Member Avatar for anders10
Member Avatar for eikal

What he said. Between every { and } tab all lines 1 tab inward. Also you should note that on line 34 you will get an error because you can't call a variable "class" since the word "class" is a reserved Java word.

Member Avatar for stultuske
0
144
Member Avatar for Bemani_lover

I think you are making this way too complicated for yourself... [CODE=Java] int count = 0; int[] arr = new int[10]; int num = 0; while (count<10 && num!=-1) { num = Integer.parseInt(JOptionPane.showInputDialog("Enter Integer Number "+(count+1))); if (num!=-1) arr[count] = num; count++; } [/CODE] Shouldn't that do the trick?

Member Avatar for kvass
0
173
Member Avatar for omeli
Member Avatar for kvass

The commonly used syntax: [CODE=Java] public class Foo { private int x; public Foo(int x) { this.x=x; } } [/CODE] Is actually "flawed." If you have an anonymous inner class inside the Foo constructor (i.e. if this were a GUI code and you were adding an ActionListener) then the private …

Member Avatar for javaAddict
0
177
Member Avatar for saggykulji

If you read it in as a string, and then use substring() and charAt() methods to isolate certain strings and characters, then you can just confirm that the 3 substrings are integers and the 2 characters at the designated points are '-'. If this is the case then you can …

Member Avatar for kvass
0
77
Member Avatar for qariella

You would need to post the rest of your code for anyone to help you out with that piece.

Member Avatar for qariella
0
987
Member Avatar for rocky89

We can point you in the right direction, but first we need to see your attempts to figure it out. You can't just say "I don't know" with your paper clean. Play around with it and see where you get. If you don't get anywhere we'll help, but we need …

Member Avatar for stultuske
-1
192
Member Avatar for kvass

This program creates 2 methods for convenience: menu() and binaryQ(). The menu method accepts several strings as its parameters. The first of the strings is the question to be displayed at the top of the menu. The following strings are the menu choices. For instance, if you call [icode]Confirmer.menu("What is …

Member Avatar for kvass
-1
199
Member Avatar for JessJames

Ok so in that problem they want you to use something called method overriding. What this means is as follows: If a superclass (Transaction) has a method purchase(), then by default its subclasses (Rental, Return) will also have that same method. If I say: [CODE=Java] Rental rent = new Rental(); …

Member Avatar for kvass
0
83
Member Avatar for J-Rock

There are a couple of things you can do: 1. Make another class that has an array of these objects, each representing a single student. Then have methods of that new class have the class average, min, and max methods, which basically takes the scores from all the GradingScaleRP1 objects …

Member Avatar for kvass
0
124
Member Avatar for BuhRock

The command System.exit(0); will kill your program. So if you have the lines: [CODE=Java] if (val == testNum) System.exit(0); [/CODE] Then your code will exit if the testNum is entered. Note that this is not like breaking from the loop -- your program will basically jump to the end of …

Member Avatar for kvass
0
146
Member Avatar for beGinneR24

Value comparison is done with the == operator. For instance, the expression (5==5) will return true. This operator works with all numerical values as well as with characters. To compare strings, use the syntax (str1.equals(str2)). For instance, ("apple".equals("orange")) will return false.

Member Avatar for BestJewSinceJC
0
129
Member Avatar for CollinRyans

Look at these 2 sites: [URL="http://java.sun.com/j2se/1.3/docs/api/java/awt/event/KeyListener.html"]KeyListener API[/URL] [URL="http://java.sun.com/docs/books/tutorial/uiswing/events/keylistener.html"]Tutorial for KeyListener[/URL] In general, KeyListener works exactly the same as ActionListener, except instead of overriding actionPerformed() you need to override keyPressed(), keyReleased(), and keyTyped(). Play around with this interface and see what results you get.

Member Avatar for kvass
0
86
Member Avatar for santiaguinho15

It's funny -- I had the same confusion a little while ago. I am fairly sure this is how it works --> algorithms have different runtimes based on their designs, and each of those runtimes can be roughly estimated depending on the algorithm type. Each of these estimations can be …

Member Avatar for BestJewSinceJC
0
106
Member Avatar for supersoup

[QUOTE=PatrickSharp;1139849]Since code isn't your thing.. here is some psuedocode: [CODE] set valid input false while (not valid input) do prompt user for input value. get input value from user. if input value is what you are looking for set valid input true else display error message end [/CODE] That is …

Member Avatar for BestJewSinceJC
0
117
Member Avatar for kvass

Hey everyone! If I have a matrix as follows: int[][] mat = new int[5][3]; Does that mean that the row size is 5 and the column size is 3 or vice-versa? I am really confused about whether the order is [row][col] or whether it is [x][y] in relation to the …

Member Avatar for masijade
0
116
Member Avatar for habibalbi

So basically a method works like a machine that accepts some input and does something based on that input. Usually it is useful for organizing your code so you don't get a crazy-long main function like the one you ended up with. I shortened your main function using some methods, …

Member Avatar for kvass
0
204
Member Avatar for JanieRae

I imagine your assignment was to use for-loops for the array. Ok, so basically an array is a list of items (in this case integers) and each is assigned a certain index. You seem to understand the basic usages of an array, as your syntax in that respect is correct. …

Member Avatar for BestJewSinceJC
0
119
Member Avatar for kvass

Hey everyone~! I am having a major issue understanding class casting. I thought I understood it, but I found 2 problems in my Barron's book that seem to contradict in their explanations. Can someone please explain the distinction between these two problems??? [B][U]Problem 1:[/U][/B] [INDENT] Bird = Super class Owl …

Member Avatar for kvass
0
234
Member Avatar for sedai77

I would start by creating a person object with those pieces as private variables. Have one of those private variables be the array of grades. Make appropriate getters, setters, and constructors. Make a method to get the grades and store them in the array. Make a method to retrieve the …

Member Avatar for BestJewSinceJC
0
136
Member Avatar for rena0514

Well since you have a /* at the beginning you need to end it with a */ or else your whole code will be one giant comment ;)

Member Avatar for jwenting
0
148
Member Avatar for kvass

Hey everyone~! I am pretty new to threading but I'm trying to figure it out by playing around with its possibilities. I wrote a program where 2 threads are supposed to "race" to count to 10 and then the first one there says "I win!" and the second says "I …

Member Avatar for kvprajapati
0
117
Member Avatar for ZER09

Basically I think what is happening is this: you have a switch statement with the user's choice -- say they select choice 1. Then it goes to case 1. Case 1 has 2 commands: Add(); and break; First Add() is executed. When add() is finished, the second command is executed …

Member Avatar for ZER09
0
127
Member Avatar for kvass

Hey everyone~! I have been studying for the AP Computer Science exam, and I have a question where I think Barron's is wrong, so if someone could confirm whether I am correct or not please let me know! The following code snippets are given: [CODE=Java] public interface Player { /* …

Member Avatar for kvass
1
89
Member Avatar for RSP86

Um... I have no idea how you intend to hook up the webcam with java... that sounds really advanced. However, I would recommend serializing your database each time the program closes and deserializing it each time it opens. Check out the serializable interface on the Java API.

Member Avatar for peter_budo
0
174
Member Avatar for bheegi

The first step is to make sure you fully understand the concept of an [URL="http://java.sun.com/j2se/1.4.2/docs/api/java/util/ArrayList.html"]arraylist[/URL]. Once you do, check out this code -- I think the simplest approach is to use an arraylist of arraylists to represent the theaters: [CODE=Java] import java.util.ArrayList; public class Cinema { public static void main(String[] …

Member Avatar for kvass
0
113
Member Avatar for suct

I'm not really sure what you are trying to do, but one thing that might help you is a for-each loop. The syntax is as follows: [CODE=Java] for (One instance of a type : A collection of that type) { //Iterate through the list. } [/CODE] For example, [CODE=Java] ArrayList<String> …

Member Avatar for kvass
0
105
Member Avatar for ronyyy
Re: java

Here's something to think about to jumpstart your forming of an algorithm -- consider using nested loops. Have the outer loop keep track of the row and each time it completes have it jump to the next row, and have the inner loop print the contents of the row. Think …

Member Avatar for ronyyy
0
105
Member Avatar for Dasau

I can't see the rest of your code, but it's possible that the string has a null value and thus doesn't have a length of zero. There is a difference between an empty string and a null string. An empty string is like a thread with no beads on it. …

Member Avatar for kvass
0
86
Member Avatar for C+Marshall

I think I might know the issue. If you are saying in your code System.out.println(num1+num2+num3) to print the 3 numbers, your error is here. The print method is adding the integers together and then is printing them. If you add the integers to an empty string and print it as …

Member Avatar for kvass
0
97
Member Avatar for laelzio.mosca

Every method call needs to match the way it was set up. Since you have a method called "void reverse(int units)", the method call is going to need to be set up so it enters a number of units and returns nothing. If you say System.out.println(myCar.reverse()), you are going to …

Member Avatar for kvass
0
119
Member Avatar for kvass

Can someone please write a piece of code for the following and comment each line (except for really simple ones like int x = 5;) explaining what it does? Objective: write a program that "spins a number wheel" in the background while waiting for you to type "stop" -- when …

Member Avatar for kvprajapati
0
94
Member Avatar for kvass

Hi everyone! This code runs without throwing exceptions and stuff, but it doesn't exactly run when I click the "Submit" button -- what is supposed to happen is that I click it and it generates a random number. What happens is either nothing or if I get lucky and click …

Member Avatar for kvass
1
136

The End.