713 Posted Topics
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 … | |
Re: 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 … | |
Re: 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 … | |
Re: 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... | |
Re: 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. … | |
Re: 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 … | |
Re: 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 … | |
Re: 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 … | |
Re: 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: … | |
Re: 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 … | |
Re: 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 … | |
Re: [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 … | |
Re: 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? :) | |
| |
Re: 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 … | |
Re: 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 … | |
| |
Re: 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 … | |
Re: 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 … | |
Re: 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 … | |
Re: 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 … | |
Re: 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 … | |
Re: 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 … | |
Re: 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 … | |
Re: 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 … | |
Re: 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 … | |
Re: [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. … ![]() | |
Re: 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? | |
Re: 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 … | |
Re: [CODE] while (number !=-1);[/CODE] You never change the value of number in the loop, so this remains true forever. | |
Re: - 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, … | |
Re: 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, … | |
Re: [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. … | |
Re: 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 … ![]() | |
Re: 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 … | |
Re: 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 … | |
Re: 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 … | |
Re: 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 … | |
Re: [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 … | |
Re: 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 … | |
Re: 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. | |
Re: 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 … | |
Re: 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, … | |
Re: 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 … | |
Re: You'll probably find some useful stuff in the recent thread on summing numbers from 1 to 1000. Read that over. | |
Re: [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 … | |
Re: 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? … | |
Re: 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 … | |
Re: 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? |
The End.