713 Posted Topics

Member Avatar for jon.kiparsky

Most of the posts here are from people with problems, looking for help. I thought I would try to talk a bit about ways to find your way out of "stuck". It's been on my mind lately, since I've been wrestling with Swing and it's been winning. Finally worked out …

Member Avatar for apines
1
127
Member Avatar for yap_1991

You certainly don't want the algorithm code in the GUI. Presumably the "algorithm file" has some method that takes input and returns the result? Instantiate the class containing your algorithm, and call whatever method is required, and put the return from that function wherever it is that you want it …

Member Avatar for JamesCherrill
0
209
Member Avatar for techieinvents

If you don't have the experience, it's tough to fake it. Two years coding experience teaches you a lot, if you're not very strong on your java you'd probably be wasting everyone's time. Best to try to pile up the experience in other ways - contribute to open-source projects, find …

Member Avatar for jon.kiparsky
0
88
Member Avatar for cassyjack

Brian - I'm going to jump in before someone gets cranky at you, and suggest that if you start a new topic, you'll get a lot better response. It's considered bad form to revive old threads to ask new questions. I'll give you some suggestions in the new topic...

Member Avatar for jon.kiparsky
0
2K
Member Avatar for Tankadin

You're reading a file by making a Scanner on that file. The Scanner's constructor takes a String. What if you made a method readFile(String filePathName){} which accepted the name of the file as a parameter and used that to construct a new Scanner. That should eliminate your extra file-reading methods. …

Member Avatar for Tankadin
0
264
Member Avatar for TahoeSands

At an overview level, the object-oriented solution is the one that divides the problem into its natural components. Typically you'll have a natural division between getting the work done and talking to the customer. In the real world, we don't let the customer call the developer directly, we have the …

Member Avatar for jon.kiparsky
0
124
Member Avatar for o0oKodako0o

Easiest thing would be to do the conversion after the addition, but that's probably not what you're after. If you have two strings representing binary numbers and you need to add them, you have to a) grab digits from the right-hand end b) and add them in standard binary fashion …

Member Avatar for apines
0
118
Member Avatar for banana1073

It seems to me that the nextToLast and the pointerToLast methods are useful for an iterative solution, not so much for the recursive. Come to think of it, the nextToLast isn't much use in an iterative situation, either, and of course as a practical matter it's impossible to keep it …

Member Avatar for jon.kiparsky
0
204
Member Avatar for shelexelex

It allows the program to take arguments from the command line. Not used very often, but it allows you to do something like [CODE]public class DoStuffToStrings{ public static void main(String[] args) { for (String s:args) { //do stuff to the strings } } }[/CODE] You can call this as follows: …

Member Avatar for jon.kiparsky
0
92
Member Avatar for Pushpasheela

In short, yes. There's Swing, it's big, and you have to learn how to use it if you want to do this sort of thing. You can also use the older awt, but that's a little ugly. Or if you're hard-core you can use the awt stuff to roll your …

Member Avatar for jon.kiparsky
0
189
Member Avatar for wobuaini

I'm not sure if this is what you meant, Leiger, but the way I'd go about it would be: - put "A" and "B" in the queue - pull Strings from the queue: for each String s in the queue, put s+"A", s+"B" - repeat. Stop when you get to …

Member Avatar for leiger
0
99
Member Avatar for MeandJava

[CODE] for(;;) { tries++; (...) if(tries == 9){ ... } [/CODE] Um, if you want to go around nine times, what was wrong with [CODE] for (int tries = 0; tries<9; tries++) { .... } [/CODE] Of course, the kinder thing to do would be to ask each time, as …

Member Avatar for leiger
0
7K
Member Avatar for spades0001

Here's a sneaky way to do it: print each number n as (n/2)*2. That'll print all of the even numbers in the range, without an if. Okay, it'll print them twice, but nothing in the assignment said you can't print them twice, did it? :)

Member Avatar for apines
0
146
Member Avatar for Guna16
Member Avatar for RBK_RBK

What are you trying to do? What do you expect to happen when you run this particular piece of code? What happens instead? If you want people to help you, make it easy for them - tell them what the problem is. This is also helpful for you, since it …

Member Avatar for jon.kiparsky
0
98
Member Avatar for Barnifericus

Take the input from the file and use it to create a Course object. There's some parsing involved there, but you should be able to do that, it's just looking at Strings as they come in and making decisions. When you finish making a Course, add it to the list …

Member Avatar for jon.kiparsky
0
114
Member Avatar for Bordeaux0113
Member Avatar for Bordeaux0113
0
75
Member Avatar for akondray
Member Avatar for shelexelex

Object-oriented programming is a pretty deep area of study. You'd probably do well to start out by getting the hang of Java syntax, writing small programs that do small things. Once you have at least some idea of the internal structures of a Java class, you'll have a means to …

Member Avatar for shelexelex
0
104
Member Avatar for sannidhikumar99

So what's stopping you? It's a simple recursive descent, isn't it? Start with a File. If it's not a directory, you're done: return this file. If it is a directory, add its contents to your list. How do you do that? For each file in the directory, if it's not …

Member Avatar for jon.kiparsky
0
283
Member Avatar for jliao20

It's okay as far as it goes, which isn't very far. Yes, you can use a scanner to tokenise a line, and yes this will take a statement like LET a 10 and produce a LetStatement (a, 10) But it'll have trouble with LET a = 10 (if that's legal …

Member Avatar for jon.kiparsky
0
159
Member Avatar for Glass_Joe

The military is an organization; it has to "forbid" certain things in order to not be seen "condoning" them. So they say "you can't buy it at the PX" and it's done. People serving in the military don't seem to have any trouble getting hold of these things, and the …

Member Avatar for kes166
0
903
Member Avatar for charat

a few things - isPalindrome returns a boolean, so you can't assign it to an int. You would use it like [CODE]if (isPalindrome(i)) System.out.println("i? si!"); else System.out.println("o, no."); [/CODE] Also your loop index is not exactly what I'd use. I suspect it works, at least some of the time, but …

Member Avatar for weathernerd1990
0
3K
Member Avatar for shinnie

Not sure I understand the problem. Your user is entering input, and it's getting stored in an array - that much I've got. You're running out of space in the array, I think, and the program crashes with an ArrayIndexOutOfBounds - I'm guessing on that part. Why is the array …

Member Avatar for jon.kiparsky
0
293
Member Avatar for BboyRodimus

In the future, you'll want to use the CODE tags - easily obtained by clicking on the word CODE, in brackets, above your editing window. That makes it a lot easier to read your code. You should also include and error report that your compiler generates. This will point us …

Member Avatar for NormR1
0
1K
Member Avatar for nix_xin

What have you tried so far? The program assignment gives you a helpful starting hint, with the part about the three arrays. This narrows down your possible solutions somewhat. Try thinking about it with a piece of paper. I'm going to read off a list of numbers to you, you're …

Member Avatar for Xufyan
0
176
Member Avatar for simransuri

It would help if you would give some idea of a) what this is meant to do b) what it's doing that it shouldn't be doing, or what it isn't doing that it should be doing It may seem obvious to you what it's meant to do, and perhaps I …

Member Avatar for JamesCherrill
0
175
Member Avatar for santoshkosgi

[QUOTE=coil;1325216]If you could provide a bit more info on your experience and type of game, you might get better suggestions. Console or GUI? Multiplayer? etc.[/QUOTE] Second that. Different games will give you practice with different skills. Two-player strategy games (tic-tac-toe, othello, pente, mastermind) in the console are probably the easiest. …

Member Avatar for coil
-1
214
Member Avatar for Sunshineserene

A try block, like any other block, has to occur within some sort of method. You can't put it out in the field declarations. Sorry. It looks like you're trying to protect the assignment to that 2D array - have you been getting an exception there?

Member Avatar for Sunshineserene
0
181
Member Avatar for badae

Well, for a start, it's posted without any code tags, so it's hard to read. That's one thing that's wrong with it. For another thing, it doesn't tell me what it's supposed to do, so I can't evaluate whether the code is correct, that's a big problem. What is the …

Member Avatar for badae
0
194
Member Avatar for tedmyers

[CODE] while (number !=-1);[/CODE] You never change the value of number in the loop, so this remains true forever.

Member Avatar for tedmyers
0
174
Member Avatar for nobodycool

- A 5 dimensional array? I see the five dimensional array, and it's scary to me. Can you talk about what it is you're doing there, and why you need 5 dimensions to model it? - I'm having a little trouble figuring out what your code's meant to be doing, …

Member Avatar for nobodycool
0
130
Member Avatar for nitol

Well, there are sorting methods, for example, see the API for Arrays. You could, for example, load the numbers into an array and let the sort() method do the work. If you're supposed to write the sort yourself, you're probably looking for a bubbleSort: go through the list of numbers, …

Member Avatar for jon.kiparsky
0
88
Member Avatar for PDB1982

[CODE]if (m<n) { for (double count = m; m < 499; count++) { for(i=n; i< 499; i++ ); { [ SNIP ] m++; n++; } }[/CODE] This is a very confusing way to do a for loop. It'll compile, but it's not at all clear what you mean to do. …

Member Avatar for jon.kiparsky
0
152
Member Avatar for flyingcurry

And remember, you can't recurse without cursing first. If you're not familiar with recursion, it'll seem weird at first, but really it's just another method call, only your method calls itself. The only trick is knowing where to stop. As coil says, you have two possibiliities: either you know the …

Member Avatar for coil
0
1K
Member Avatar for NewOrder

NowOrder: Linked lists are a well-described area of computer science, usually the first thing covered in your second-year Data Structures and Algorithms class. They underlie a number of standard data structures and understanding them is fundamental to understanding serious programming. What follows will be a very brief overview, but you …

Member Avatar for adams161
0
134
Member Avatar for sanelepatrick

So a permutation cipher works by scrambling the order of the plaintext while retaining the values. The problem is to work out a way to transform the order of objects in an array in a regular fashion, and then to undo that transformation. If you're familiar with array manipulation, start …

Member Avatar for jon.kiparsky
0
136
Member Avatar for mrnutty

It's clear that your environment supplies you with the raw materials for the choices you make, but it's a cop-out to go from that to the assumption that your choices are determined by your environment. Ultimately, you're going to live the life made up of your choices and other people's …

Member Avatar for alan145
0
316
Member Avatar for raym.mart

1. That's not an "it", it's a them. 2. Yes, I'm pretty sure he can. 3. No, I'm pretty sure he won't. 4. You're welcome.... to post questions about your work. That is, questions, not requests for people to do your work for you. Your teacher gives you that assignment …

Member Avatar for raym.mart
0
208
Member Avatar for hajjo

[QUOTE]Aha, thank you very much. So they are always unique.If i create new object, it will be allocated a new memory address and not old one.[/QUOTE] I don't think you can rely on that being true. It'll be true as long as you don't let any of your Objects go …

Member Avatar for jon.kiparsky
0
86
Member Avatar for kennski23

Well, I see by this line: [QUOTE]As the turtle moves around the room with its pen down, the floor is marked an *.[/QUOTE] that you're to do this in the console rather than graphically. This will save you a lot of math, since you won't have to calculate angles and …

Member Avatar for peter_budo
0
328
Member Avatar for bangor_boy

For completeness, you should know that there is also[CODE] System.getProperty("line.separator")[/CODE] which returns the correct separator for your system, since Windows still uses the bizarre two-character EOL. I don't know if just using \n fails on Windows machines, though, so I don't know if this is actually necessary.

Member Avatar for jon.kiparsky
0
85
Member Avatar for tonyfingures

The calculation isn't hard. All you'd need would be some very fundamental arithmetic, a loop, and a branch. If you haven't done so, you should start by reviewing the basics thread stuck to the top of this forum. You'll want to have done the following: - get a basic hello …

Member Avatar for NormR1
0
1K
Member Avatar for morancr

Okay, put that all aside for a bit. Make a class, call it "IfStatements". In that class, translate the following statements into java, and print the responses to the console, using System.out.println() if 1 is greater than 2, print "In union there is strength" if 2 is greater than 1, …

Member Avatar for jon.kiparsky
0
96
Member Avatar for packetpirate

The math isn't difficult. You have the dimensions of the applet, so you know the center point. That center point is also the center point of the rectangle. A rectangle in Swing is defined by the top left point and its two sides. The sides will not change - all …

Member Avatar for packetpirate
0
5K
Member Avatar for SoulRaven

You'll probably find some useful stuff in the recent thread on summing numbers from 1 to 1000. Read that over.

Member Avatar for jon.kiparsky
0
33
Member Avatar for gudads

[CODE]import javax.swing.*; import java.util.*;[/CODE] Potential import conflicts, as discussed in another thread. Use explicit imports. [CODE]System.out.print("enter num1\n");[/CODE] Terrible UI - don't give the users your variable names, give them something they can use! [CODE]int num1 = input.nextInt();[/CODE] If you're using nextInt(), try{} it and catch the exception [CODE]System.out.print("enter num2\n"); int …

Member Avatar for peter_budo
0
1K
Member Avatar for StacyAnn1296

Pseudo-code is a design tool. Design starts with asking questions - any questions that help you understand the design are good questions. Who is this for, what does it do? How do they use it? How often do they use it? What sorts of things do they use it with? …

Member Avatar for Nick Evan
0
158
Member Avatar for flyingcurry

You have the line number where the error occurred. It looks like you're doing an array read at that line. What is the value of the index you're trying to read at that point? As Norm would say: put in a println statement before the error to see what the …

Member Avatar for flyingcurry
0
177
Member Avatar for NewOrder

Wouldn't lines 14 and 16 be clearer if you used Math.abs() instead of the home-made version? in line 33, [CODE] valid1 = !(a<size);[/CODE] why do you put it this way instead of [CODE] valid1 = a>=size;[/CODE] which is easier to read?

Member Avatar for NewOrder
0
107

The End.