- Strength to Increase Rep
- +6
- Strength to Decrease Rep
- -1
- Upvotes Received
- 33
- Posts with Upvotes
- 33
- Upvoting Members
- 17
- Downvotes Received
- 5
- Posts with Downvotes
- 5
- Downvoting Members
- 4
211 Posted Topics
Re: [CODE]public class MyPoint { private int x,y; public MyPoint(){ x=0; y=0; } public MyPoint(int x, int y){ this.x=x; this.y=y; } /* now Two get methods for data fields x and y, respectively. */ ..... }[/CODE] | |
Re: You may declare a method (in java we call function as method) as abstract which means no definition is given, e.g. [CODE]void show();[/CODE] You may declare a method with empty body, which isn't an abstract method anymore. [CODE]void show(){};[/CODE] but do nothing when calling it. Or you may define a … | |
Re: The JOptionPane's showMessageDialog is indeed shown, but it is covered by the DOS window. After you move the DOS window away you will be able to see the JOpationPane's showMessageDialog. This is my observation. | |
Re: Your code shown above is correct. I have tested with a known file. The result is correct. AS long as the browsing files is concerned, as jon.kiparsky indicated, it is already available in Swing. For example, the class FileDialog is a candidate for this purpose. Since its constructor requests a … | |
Re: Your forgot to add the component userMessageLabel into container: [CODE]add(userMessageLabel); // this line of code is missing[/CODE] Please use CODE tag to post your code so that one may refer your certain code to a specific line number | |
Re: StringBuffer has an instance method: reverse() to do the reversing job. [CODE]import java.io.*; import javax.swing.JOptionPane; public class Palindrome{ static boolean palindromeCouplet (String s) { StringBuffer s1 = new StringBuffer(s); return ((s.compareTo(new String(s1.reverse()))==0) ? true :false) ; } public static void main(String[] args) { while(true){ String str=JOptionPane.showInputDialog( null, "Type in a … | |
Re: Following javaAddict's code, I have replaced the BufferedWriter and FileWriter with BufferedReader and FileReader. In order to get each integer value back, the method of class String split is given the delimiter of a space " ". Please read the method of String split(...) in API. Therefore, for reading the … | |
Re: Please have a look at the thread: [URL="http://www.daniweb.com/forums/thread299093.html"]array sort of 10 integers in ascending and descending order Bubble sort http://www.daniweb.com/forums/thread299093.html[/URL] | |
Re: To call System.out.print() and use nested loops as well. | |
Re: Animation in Java JDBC application Statistics on English words obtained from a text file Some demonstration on data structure | |
Re: In constructor you redefine the label2,label4,label6, and label8 as local variable of the type JTextField, which is wrong. You have already declared them as attributes. You should thus replace the 8 lines of code in the constructor by the following code: [CODE]JLabel label1 = new JLabel("Enter the price of one … | |
Re: [CODE]import java.io.*; import javax.swing.JOptionPane; public class PalindromeCouplet{ static boolean palindromeCouplet (String s) { StringBuffer s1 = new StringBuffer(s); return ((s.compareTo(new String(s1.reverse()))==0) ? true :false) ; } public static void main(String[] args) { while(true){ String str=JOptionPane.showInputDialog( null, "Type in a string!\nPress Cancel to terminate the program", "Palindrome or Not?", JOptionPane.QUESTION_MESSAGE); if … | |
Re: Thank you, VinC, for sharing the "Covariant". line 22 shows that g is a variable of type Grain. line 25 shows that a variable of type Grain is capable to receive a value of type Wheat. Why? Because Grain is super class of class Wheat. Wheat is a kind of … | |
Re: [CODE]double num = 1001.27124; System.out.printf("%8.2f\n", num);[/CODE] | |
Re: It happends with Chinese characters as well. I think this is probably due to the computer system (windows' config) where your output is printed. | |
Re: A further development of extemer's program leads to the following table showing the furture values of one thousand dolloars investment calculated based on compound interest: a(t) = (1 + i)^t where i is rate while t the number of years [CODE]import java.text.DecimalFormat; import javax.swing.*; import javax.swing.JTextArea.*; class TextAreaDemoB { public … | |
| |
Re: The main method should be written as follows: [CODE]public static void main(String args[])throws IOException { sp obj=new sp(); obj.takenum();obj.showresult(); }[/CODE] | |
Re: If you have already had JDK 1.6 in your machine then download [URL="http://www.oracle.com/technetwork/java/javame/downloads/sdk30-jsp-139759.html"]Java ME SDK 3.0 http://www.oracle.com/technetwork/java/javame/downloads/sdk30-jsp-139759.html[/URL] do some programing in J2ME Then under your working folder : [B]projectName/dist/[/B] you may find the corresponding file ***.jar ready for mobile phone . | |
Re: (1) The code in the line 12 is not correct. The code in line 12 could be: intTotal = intTotal + intCounter; or intTotal += intCounter; (2) The code in line 13 should be moved/inserted into the place between the line 14 and 15. (3) The initial value for the … | |
Re: (1) flyingcurry ,if you have to sort the whole array the second argument “length” is redundant. In fact, the length is the array.length。 (2) The line 13 could be replaced with [CODE]for (j=0; j<length-1-i; j++) //to avoid the unnecessary comparisons made of the stable region.[/CODE] See [URL="http://www.daniweb.com/forums/thread299093.html"]the post on bubble … | |
Re: One should write the following line of code to update the control variable ctr (the ODD numbers less than 10): [CODE]for (;ctr<=10; ctr+=2, ctr2++) {[/CODE] | |
Re: Just for your [URL="http://docs.python.org/tutorial/datastructures.html"]reference.[/URL] In Pyphon the list data type has a method: pop(). list.pop([i]) removes the item at the given position in the list, and return it. If no index is specified, a.pop() removes and returns the last item in the list. (The square brackets around the i in … | |
Re: The difference between two adjacent numbers in the series of numbers increases one each time. Therefore, one has to update the difference by one increment each time: [CODE]difference++[/CODE] Hence one may calculate the next number by the following code: [CODE]num +=difference++;[/CODE] Therefore the for each loop could be written as … | |
Re: (1) You may define the method as the main(). Hence replace the line 8 with [CODE]public static void main(String args[] ){[/CODE] (2) You forgot to create the instance of Scanner: input. Hence insert line 8 the following code: [CODE]Scanner input=new Scanner(System.in);[/CODE] | |
Re: The UML for the class MyPoint could be written as follows: -x : double -y : double +MyPoint() +MyPoint(x:double,y:double) +getX() : double +getY() : double +setX(x:double):void +setY(y:double):void +distance(AnotherPoint:MyPoint):double +distance(p1:MyPoint,p2:MyPoint):double | |
Re: Note that the instructor asks to verify the value provided for "year" is at least 1908 and at most 2012, hence the code should be: [CODE]if (y >= 1980 && y<= 2012) year=y; else year=2010;[/CODE] The following code by using ternary operator is also valid: [CODE]year = ( y>=1980 && … | |
Re: The class Math in the package java.lang has a static method random() which returns a double value with a positive sign, greater than or equal to 0.0 and less than 1.0. I use this method to generate random number. For example, to generate a integer varying from 0 to 255 … | |
Re: In the definition of class EnemyShip, you may add a static int attribute numEnemieShip from which you may know the number of enemy ships created from time to time. Hence, the constructor is defined as follows: [CODE]public EnemyShip(int x, int direction){ this.x = x; this.direction = direction; numEnemieShip++; }[/CODE] | |
Re: In this case you should cast the result of the evaluation of "xCenter + 200 * Math.cos(2 * Math.PI * 3 / 7)" or "yCenter + 200 * Math.sin(2 * Math.PI * 3 / 7)": [CODE]g.drawLine ((int)(xCenter + 200 * Math.cos(2 * Math.PI * 3 / 7)),(int)(yCenter + 200 * … | |
Re: The following code demonstrates how to analyze a keyboard input in terms of tokens. The client may input no more than 100 words with the final string “end” (excluded). These words are simultaneously stored in the String array s, through which one may do search for a specific word. [CODE]import … | |
Re: Your set methods (settotalPrice() and settotalPriceWithTax()) should be of the type void | |
Re: As far as I know, if the instance of JFrame is a, the code for registering its closing button could be one line of code as follows: [CODE]a.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);[/CODE] | |
Re: To drawing a line one has to use the instance of Graphics : Graphics g so that the method in drawing a line can be applied: g.drawLine(int x1, int y1, int x2, int y2) ; which draws a line, using the current color, between the points (x1, y1) and (x2, … | |
Re: Alternatively, one may use the CANCEL button on the input dialog box: JOptionPane.showInputDialog(inputMessage); to check if the program should terminate or not. [CODE]inputString = JOptionPane.showInputDialog(inputMessage); if (inputString== null){ JOptionPane.showMessageDialog(null, "See you next time", "Telephone Digit",JOptionPane.PLAIN_MESSAGE); break; }[/CODE] | |
Re: Any primitive data type has its own wrapper class. The wrapper class of int is Integer which is defined in the package java.lang. Its static attribute MAX_VALUE represents the positive largest value (2147483647)while MIN_VALUE the negative smallest value. In the same way one may obtain the maximum/minimum values for other … | |
Re: As indicated by API : acos public static double acos(double a)Returns the arc cosine of a value; the returned angle is in the range 0.0 through pi. The return value of Math.acos is in radian instead of degree. It has to be multiplied by 57.296 (180/PI) to become the value … | |
Re: Xufyan, you may have two control indexes, such as int tosInt=-1,tosFloat=-1 to manage these two indipendent arrays of different data type which store different data. It is a common sense. | |
Re: Linked list Queue binary search tree Overridden method Thread and animation | |
Re: Following Dean_Grobler's suggestion you may read each number as a string s, and then convert s into a decimal number in the type of double by the following line of code: [CODE]double d = Double.parseDouble(s);[/CODE] or convert s into a decimal number in the type of float: [CODE]float f = … | |
Re: If multiple choices( selecting one more items at one time) are allowed you may use "if" but no "else". For the 3 choices you may simply use Class JCheckBox. In your layout the selections seem to be more complex than a ckeckbox. | |
Re: It's impossible to add an integer value into a boolean type array which stores boolean value only. | |
Re: You may try the following changes. Because we want the smileFlow() runs for a certain time (befor x reaches 600), you have to (1) delete the line code s.smileFlow(); (2) insert the above code s.smileFlow(); after the f.setDefaultCloseOperation(3); so that it runs after setting up the frame properly. P.S. the … | |
Re: The index variable "cnt" in line 29 and 35 is 5 after the method EnterNumbers() has been called. The value 5 of the "cnt" is "OutOfBounds". You have to rewrite the method NumberCheck() because it is not functional. | |
Re: (1) The default layout manager for JFrame is BorderLayout where 5 blocks are defined as NORTH,WEST,SOUTH,NORTH,CENTER. So the code: f.setLayout(new BorderLayout()); is redundant. (2) Since the f container is controlled by a BorderLayout when you add any sub-containers into f you have to indicate which block each container goes to. … | |
Re: The width of each button is given too small. Try to replace lines 19 and 20 with the following width of 150: b1.setBounds(50, 50, [COLOR="Red"]150[/COLOR], 50); b2.setBounds(50, 125, [COLOR="red"]150[/COLOR], 50); | |
Re: Please fill the following table on a page to trace the nested for each loop: [CODE]for(int count = 0; count <= 3; count++) for(int count2 = 0; count2 < count; count2++) System,out,println(count2)[/CODE] Only when both contitions: (count2<count) and (count<=3) are true, the output is available. If so fill the output … | |
Re: Please to use the code tag so that the number of line could be mentioned. I guess that your problem is the control index "currentImage", the global variable, that is out of the bound after completing the first run of the paint(), i.e. after the 15 (totalImages) pictures are displayed. … | |
Re: Please use code tags around posted code to make it more readable. Since your class projectThree extends Applet an method public void init(){...} would be defined instead of a constructor. Hence the code line: public projectThree() should be replaced by public void init() I have a question for your reference: … | |
Re: In addition to the way ,as kvass points out, to solve this problem one may write a method to do the checking job: [CODE]/* The method duplicate checks the partial part (the index from 0 up to the n-1) of the array a to see if there is an b … |
The End.