|
http://pastebin.com/cuTQJ4nU I've got an error on lines 96 & 97, it tells me I should change the type of myCar to InteriorColor / ExteriorColor respectively. But what I don't understand is Interior/ExteriorColor extend CarDecorator, which extend Car. This is for my design patterns class, doing a bonus assignment where we need to mix and match random patterns we've learned this semester, trying to use Decorator + Singleton patterns. But yea, no idea where my logic is wrong. As far as I can tell I've followed my previous homeworks exactly.
|
# ? Dec 14, 2011 05:40 |
|
|
# ? May 24, 2024 17:16 |
|
Sab669 posted:But what I don't understand is Interior/ExteriorColor extend CarDecorator, which extend Car. Sure, it extends Car. But it doesn't extend UniqueCar, which is what the type of your variable is.
|
# ? Dec 14, 2011 05:47 |
|
Sab669 posted:http://pastebin.com/cuTQJ4nU What Jabor said. As an aside, UniqueCar is missing a synchronized keyword.
|
# ? Dec 14, 2011 05:50 |
|
I guess that's where I'm confused, because UniqueCar also extends Car, so isn't it technically a Car? And in the two classes I've taken that use Java as the language, I've never heard of Synchronized.
|
# ? Dec 14, 2011 06:12 |
|
Sab669 posted:I guess that's where I'm confused, because UniqueCar also extends Car, so isn't it technically a Car? Every UniqueCar is a Car, yes. That doesn't mean that every Car is a UniqueCar. You'll notice that every class in Java extends from Object - does that mean that you can do something like the following? code:
Why can you do this instead? code:
|
# ? Dec 14, 2011 06:24 |
|
Sab669 posted:I guess that's where I'm confused, because UniqueCar also extends Car, so isn't it technically a Car? UniqueCar is a Car CarDecorator is a Car InteriorColor is a Car CarDecorator is not a UniqueCar InteriorColor is not a UniqueCar You are trying to set a UniqueCar = InteriorColor and that does not work. For why to use "synchronized", here's a good article on Singletons. Reference the section "Multiple Instances Resulting from Incorrect Synchronization": http://java.sun.com/developer/technicalArticles/Programming/singletons/ What exactly synchronized does and why you should use it appears to be out of the scope of your class however.
|
# ? Dec 14, 2011 06:24 |
|
The code Sab is working on is almost certainly for a low-level class and thus single-threaded.
|
# ? Dec 14, 2011 09:50 |
|
edit: Eh, nevermind, found an easier to use library. Problem solved.
ImplosiveF fucked around with this message at 00:06 on Dec 15, 2011 |
# ? Dec 14, 2011 18:48 |
|
I was wondering if anyone had a clever solution to this problem. I have a method that takes a String of html, and a Set<String> of ids pertaining to elements in the html. The purpose is to take the original html, find all of the tags that have one of the matched ids, and return a new string fragment of html. So for example: Given this html and a set of ids {"1", "4"} code:
code:
The only thing I can think of is a sax parser solution, where I maintain a map of String id > String htmlFragment. This seems pretty tough to implement correctly and efficiently. I wonder if a regular expression might work, although that seems pretty ugly. I'd welcome any ideas. And yes the html is valid xml. FateFree fucked around with this message at 20:09 on Dec 15, 2011 |
# ? Dec 15, 2011 20:07 |
|
FateFree posted:I was wondering if anyone had a clever solution to this problem. I have a method that takes a String of html, and a Set<String> of ids pertaining to elements in the html. The purpose is to take the original html, find all of the tags that have one of the matched ids, and return a new string fragment of html. Try Woodstox instead. This is what CXF uses and is therefore probably very good.
|
# ? Dec 15, 2011 21:48 |
|
I've been reading the Newbie Interview thread and a while back someone suggested:code:
code:
So I wanted to rewrite my print function using the printf command and HOLY LORD I don't know how printf works. I could get around this using another value to keep track of the number of digits in count, and then a loop to print the appropriate number of spaces, but printf seems pretty powerful and useful so I'd like to learn how it works! tl;dr Given an int 'digits', how can I use printf to print the int 'count' inside a 'space' that's 'digits' long? ex: code:
|
# ? Dec 16, 2011 15:52 |
|
Does anybody know if there's a way to take user inputs through a pop-up window in Java (on Windows 7, if that matters)? I've taken my share of college programming classes, and I seem to recall a concept like this showing up in at least one of my textbooks, but none of my classes have actually covered anything related to this (... yet). I'm putting together a Java program that runs a certain series of calculations based on user inputs, and right now the "inputs" are just .txt documents that have to be typed up in Notepad before every individual run (after which the program scans in the .txt files line-by-line). If there's a way to save these input values after they've been typed into an input window (so the user doesn't need to re-enter old numbers a bajilliondy times), that'd be great too. EDIT: Let me know if this question doesn't make sense to anyone. I might be able to explain it a bit better if I can find some of my old books. I. M. Gei fucked around with this message at 16:06 on Dec 16, 2011 |
# ? Dec 16, 2011 15:59 |
|
http://docs.oracle.com/javase/1.4.2/docs/api/javax/swing/JOptionPane.html May be what you're looking for. ex: code:
Newf fucked around with this message at 16:19 on Dec 16, 2011 |
# ? Dec 16, 2011 16:02 |
|
Newf: Have you read the documentation for the Formatter? It contains some examples of doing similar things.
|
# ? Dec 16, 2011 16:04 |
|
Thanks, I think I'll try those out a bit later today and see what happens. Now if only I could find my old textbooks.
|
# ? Dec 16, 2011 16:08 |
|
Internet Janitor posted:Newf: Have you read the documentation for the Formatter? It contains some examples of doing similar things. Yeah, that's where I'm at. So %[argument_index$][flags][width][.precision]conversion is the format for a number in a 'formatted string'. So given that (most) of those arguments are optional, I'm not sure how to make an entry where it recognizes that the argument I'm inputting is for the width option? I had tried something like: printf("%digits", count); which prints (if count=7 for example) "7igits". I believe I see now that this is printing count as a decimal integer, and then going on to print "igits", but I guess I'm restuck now.
|
# ? Dec 16, 2011 16:17 |
|
Newf posted:Yeah, that's where I'm at. So Well it's right there in the specification. printf("%1$5d", count); //5 space padded number Edit: forgot the required conversion value baquerd fucked around with this message at 16:24 on Dec 16, 2011 |
# ? Dec 16, 2011 16:22 |
|
baquerd posted:Well it's right there in the specification. OK, so part of my problem was that I hadn't payed enough attention to the format there to see that inputs aren't ambiguous. For example, flags are specified with a character set that's disjoint from the ints that specify ints, and an int without being followed by a $ will be interpreted as width instead of as an index. The thing is that I can't put that 5 in there for width. The width was meant to correspond to a variable "digits", which is input-dependent. I got it now though: printf("%"+digits+"d", count); Thanks for the pointers. Newf fucked around with this message at 16:38 on Dec 16, 2011 |
# ? Dec 16, 2011 16:32 |
|
What's with Java and null pointer exceptions, even though I check to see if the object is a null? Ie check this code out: code:
Also, is there any way to go back to previous errors in Eclipse? Every time I run a new build it erases the old log.
|
# ? Dec 17, 2011 05:58 |
|
Try setting some of those values to temporary variables instead of using long conditionals. Then you can step through with a debugger and examine each value. It's also easier to read. To answer: selected.getDragArrowPoint() probably returns null, and you are dereferencing it. Also, if mousePosition.distance returns Integer, I think Java will automatically unbox it for the comparison and throw if the value is null. I'm sure someone will correct me though. Here's hoping for non-nullable reference types.
|
# ? Dec 17, 2011 06:18 |
|
Sedro posted:Here's hoping for non-nullable reference types. Speaking of which, has anyone tried the Checker Framework and its Eclipse plugin? Max Facetime fucked around with this message at 13:53 on Dec 17, 2011 |
# ? Dec 17, 2011 13:21 |
|
e: hey new page
|
# ? Dec 18, 2011 00:28 |
|
MrZig posted:What's with Java and null pointer exceptions, even though I check to see if the object is a null? How exactly are you initializing Camera? I don't want to make any assumptions, but you are saying you are trying to access Camera in a static way... I am assuming when you call Camera.getRelativex(int x) you are doing some conversion between the camera position and the position that you pass it. When are you initializing the Camera? I am guessing that may be where your problem lies.
|
# ? Dec 18, 2011 01:58 |
|
I am in posted:Speaking of which, has anyone tried the Checker Framework and its Eclipse plugin? My biggest concern would be IDE integration. Horrible plugins for otherwise great tools tend to be a deal-breaker for me.
|
# ? Dec 18, 2011 02:23 |
|
The Camera is initialized before that code is run, and all the variables needed are already initialized. The weird thing is, I've run the program hundreds of times and this error only happened once, and hasn't occurred again. Being a fluke doesn't stop me from worrying about it. I can't re-create it either. The dragArrowPoint is initialized at the beginning of the Planet object's code, so it should always return something. I've now made selected equal a separate object when it's supposed to be null (called nullPlanet - just an Planet object without meaning) so that I will no longer get any nullPointer exceptions from that.
|
# ? Dec 18, 2011 06:18 |
|
simple question with the JDBC hooking into MySQL. Is there a way I can insert an entry, and at the same time return the automatically generated key that entry is now using? I am aware that I can insert an entry, stating the automatic key should be returnable, and then get the key for the final entry in the database, but if multiple processes are accessing the database, this could return an incorrect result due to a second entry being added in before the key is returned.
|
# ? Dec 20, 2011 03:57 |
|
MonsterUnderYourBed posted:simple question with the JDBC hooking into MySQL.
|
# ? Dec 20, 2011 10:15 |
|
Ahhh, that makes alot more sense now, thanks a bunch!
|
# ? Dec 20, 2011 12:29 |
|
I'm gonna apologize in advance because I expect to be making GBS threads this thread up a lot over the next few days. I'm trying to use my Christmas break to get as much programming in as possible, and my biggest current goals are to build on my understanding of how OO programming and Java in particular work, and also to get a better understanding of some basic data structures and associated algos by writing them myself. I figure I can do these things in combination. My plan is to start from this Node class: code:
By the time I go back to class in January, I'd like to make my own 'package' that I can use in the future for my own academic type things, which includes all of my homemade classes. I guess my only question for the moment is whether what I'm doing is totally misguided, or if I'm going about it in a fundamentally stupid way. Thoughts?
|
# ? Dec 20, 2011 16:00 |
|
MonsterUnderYourBed posted:simple question with the JDBC hooking into MySQL. Shouldn't this be handled in the DDL for the table? Some column is the auto incrementing key?
|
# ? Dec 20, 2011 16:25 |
|
Newf posted:... The important part: after you write your own and fiddle with them, go back and use the ones provided by the JDK or Apache's or Google's open source libraries. It's more pragmatic to use the classes that professional programmers use instead of just your own.
|
# ? Dec 20, 2011 16:35 |
|
Newf posted:And extend it into Node classes suitable for implementations in Singly, Doubly, and circularly linked lists, and then into trees and more general graphs. Finally, my end-goal for this endeavour is to extend my Graph class into a Finite State Automata class for reading RegExpressions, and also maybe write some code to output a graphical representation of a graph (or even FSA if I'm still rolling confidently at that point). It's cool to learn the guts of a basic implementation for these classes and you'll learn a lot on the way. But rather than using them for future academic projects, you'd be better served to learn how to use and, if needed, extend the standard library classes (or third party libraries) which will generally serve you better than rolling your own solutions in terms of basic data structures. In particular, writing a regular expression parser can be fun, but almost certainly will not result in something you want to use over the built in regular expressions.
|
# ? Dec 20, 2011 16:35 |
|
Yeah, to clarify, I understand and expect that pretty well all of this will exist entirely as an exercise, but I mean to say that I'd like to continue on updating and refining my own library of code as I learn new things. I'm in trouble already though, and it's with a dumb thing that's going to betray my total lack of understanding: code:
super.Node(e); --> cannot find symbol method Node(E) and some other stupider things. Is there some special way to use a constructor with generics? Or some particularly good reading on how to work generics? Should I, before getting into any of this, make myself understand Interfaces and use them throughout my adventures?
|
# ? Dec 20, 2011 18:20 |
|
public class SLinkNode<E> extends Node<E>, I think
|
# ? Dec 20, 2011 18:33 |
|
Aleksei Vasiliev posted:public class SLinkNode<E> extends Node<E>, I think Correcto. Thanks.
|
# ? Dec 20, 2011 18:35 |
|
MonsterUnderYourBed posted:simple question with the JDBC hooking into MySQL. Also a note, but I believe getting the last inserted keys is safe from other concurrent access so long as it is in the same transaction.
|
# ? Dec 20, 2011 19:50 |
|
Newf posted:http://docs.oracle.com/javase/1.4.2/docs/api/javax/swing/JOptionPane.html I did a little playing around with this and yeah, I think this is what I need. Thanks. Now I need help figuring out how to SAVE data entered into a JOptionPane. The only way I've come up with for doing this is to take the values entered in each field on the JOptionPane (stuff like Name, Sex, Date of Birth, etc.), copy each of these values into a new .txt document separated by blank spaces (using a name entered into one of said fields as a default filename, which the user can change in a popup window if desired), and then save this .txt file into a certain predesignated folder on the user's system. Then, if the user wants to open one of the saved files, the corresponding .txt file is opened from the aforementioned folder, and all of the values are scanned into their respective fields in the JOptionPane, in the same order they were written into the .txt file when they were saved. My first question is whether there is an easier way to do this than the way I've just described. If so, then I'd like to know what it is and how to do it. If not, then here are my questions regarding the method I described above: 1.) How do I create a new .txt file in Java? 2.) How do I write values into a newly-created .txt file in Java? (Apparently I forgot how to do this awhile back and need some help jogging my memory ) 3.) How do I set up an option enabling a user to save a .txt file into a destination folder, and how do I enable the user to edit the "Save As" name that the file is saved under? 4.) How do I get my program to recognize the contents of one of the JOptionPane fields as a default "Save As" name for Question #3 above? 5.) If the user decides to open a previously saved file, how do I get the program to open the destination folder so the user can Browse it for the file they want? Not sure if these questions make sense, but any help would be greatly appreciated. I've never dealt with JOptionPane stuff before, so this whole subject is new territory for me.
|
# ? Dec 21, 2011 05:04 |
|
Understand that I am a Java/programming child, and my answers to these and any questions are almost certainly not the best answers available. That said, I think they can 'work'.Dr. Gitmo Moneyson posted:1.) How do I create a new .txt file in Java? 1), 2), and 4) can all be accomplished with the FileWriter and PrintWriter objects. To write, for example, to a file whose name is input by a user, you can do something like: code:
code:
I don't really have any immediate ideas about questions 3) and 5). Newf fucked around with this message at 16:17 on Dec 21, 2011 |
# ? Dec 21, 2011 14:37 |
|
Preface - I've never dealt with Swing really. But the logic of what you're trying to do I can try to help with.Dr. Gitmo Moneyson posted:
1&4) Creation of a .txt file is as easy as looking at the File class. Specify the path for the file and the correct extension and bam, your File exists. You can get as creative/restrictive as you want, but the Constructor for File that you want is File(String pathname) ... you could also force an extension with String concatenation. Here's a little example: code:
code:
If you need help with the actual implementation of 3&5 now that you have the tools, just yell.
|
# ? Dec 21, 2011 17:53 |
|
|
# ? May 24, 2024 17:16 |
|
Maven question: My project has a bunch of XML and XSL files. What's the canonical place to put those sorts of things so that the POM does the right thing when packaging them up for distribution?
|
# ? Dec 28, 2011 17:44 |