User Profile
Collapse
-
It is also a good idea to copy and post the entire error message. And indicate which lines of your code it is referring to. -
-
You don't what the possible values of this integer are.
If the integer value is just one digit long you could use the String substring(int,i nt) method to make a String with just the first character. The the static Integer method parseInt() can be used to find the int value corresponding to this string. (There are also String and Character methods that will work with the first character directly - not as a one digit string)Leave a comment:
-
OK. You might also ask whoever set the conditions what *they* would suggest: Java has never been good at commandline i/o and, I would have described it as the wrong tool for this job.
Just my 2c of course. And if I'm being too sweeping someone can jump in and say so.Leave a comment:
-
How do you know this? In particular what would you attach the event listener to?
Java's Consoleclass offers the ability to read lines without echoing but, beyond that,
interaction with a character based console device is limited to what is provided by Reader and Writer: ie no events or classes to which you might attach event listeners. (And Console may very well not be instantiable.)
You might want to consider OS...Leave a comment:
-
It looks like the compiler thinks your constructor is a method (and hence needs a return type). Why would it think that? Hint: cAsE mAtTeRs.Leave a comment:
-
It sounds like an Aircraft instance HAS-An AircraftType rather than IS-An AircraftType. In that case the type would most natuarally be an instance variable of the aircraft (rather than being a parent class of it.)
Code:class Aircraft { private AircraftType type; private String name; public Aircraft(String name, AircraftType type) { // etc }
Leave a comment:
-
If this is anything other than homework then you're going to have problems with the likes of Old MacDonald, Rip van Winkle and Stephen J Gould.Leave a comment:
-
-
Both questions (the capacity of a SB made with the no-arg constructor, and the purpose of "capacity") are covered in the StringBuilder API docs.Leave a comment:
-
There's a good description of regular expressions at http://www.regular-expressions.info/. (The * is being greedy.)
Alteratively, since slash-star comments don't nest you could just use String's indexOf().Leave a comment:
-
No, you cannot. A string is a string and has string methods etc, an array is an array and has array methods etc.
It might have been easier just to ask that question.
Why do you not want to use "built in" methods? They are built in so that you can use them. Not using builtin methods leaves you with just using arithmetic and other operators and assigning the results to things but that's about it: a sort of leaf-falling-from-a-tree-in-a-forest-unobserved...Leave a comment:
-
Your output is showing the id number. That number is zero.
Do you expect it to be non-zero? If so, go back to the code that assigns the id number - at the start of the Product constructor - and check that code to see why the idNum field remains zero.Leave a comment:
-
I would suggest you compile your code. (every time you make a change.) The compiler messages are very useful.
If there is a compiler message you cannot understand post the exact and entire thing and indicate which line of your code it refers to.Leave a comment:
-
pbrockway2 replied to How to write an program that converts a temperature given Fahrenheit to centigrade?in JavaThat doesn't leave much fun for shon!
If he/she hasn't done so, reading the section in the Java Tutorial on scanning (along with nearby sections) may be useful.Leave a comment:
-
pbrockway2 replied to How do I write a method named isPrime, which takes an integer as an argument andin JavaThe remainder operator (%) is used like any other binary arithmetic operator: you put it in between two values to obtain a third.
Code:int result = 6 * 7; System.out.println(result); // prints 42 result = 5 % 2; System.out.println(result); // prints 1
Leave a comment:
-
One way would be to have a class representing a Price. That class could have an accessor method getPrice() returning a double value for use in arithmetic by the caller. But it could also offer getPreviousPric e() returning the value before the most recent change.Leave a comment:
-
The Java Tutorial has a good description.
Basically it gives access within the package to which a class belongs.Leave a comment:
-
Well, there are just two lines in that while loop. So I don't think it will be too difficult to decide which of them is removing the righthand three digits (and how it has to be changed so that only one digit is removed.
Consult your textbook and figure out what each of the lines is doing. Neither are all that complex, but to progress from here you will have to understand the ++ and % operators as well as the two assignment operators:...Leave a comment:
-
Putting in the println() wasn't supposed to make it work! You will only make it work by fixing the bug. The println() was supposed to highlight what the bug is.
Do you see how the while loop chopped off three digits from the end? Since you are building up the output string one digit at a time, it doesn't make sense to remove three digits each time you go around the loop.
Change the line of code that...Leave a comment:
No activity results to display
Show More
Leave a comment: