1,963 Posted Topics
Re: Doesn't this answer your question? [URL="http://www.daniweb.com/forums/thread156720.html"]http://www.daniweb.com/forums/thread156720.html[/URL] | |
Re: Also this is wrong: [CODE] WrongMenu(int n){ System.out.println("you've entered : "+ n); System.out.println("please reenter: "); } [/CODE] The Exceptions don't get created to print messages. With the above the message will be printed when you do: [ICODE]throw new WringMenu(1);[/ICODE] Exceptions need to be caught and handled. Like this: [CODE] catch(WrongMenu … | |
Re: [QUOTE=Chaster;733579][CODE] String s = new String(""); String s1 = new String(""); System.out.println("enter String : "); Scanner keyboard = new Scanner(System.in); while(!s.equals("end")){ s = keyboard.next(); s1 += s+" "; // or s1 += s+"/n"; } System.out.println("you've typed: \n"); System.out.println(s1);[/CODE][/QUOTE] That is not what [I]enuff4life[/I] has asked. Try this: [CODE] String s … | |
Re: percentage is an array and you do: percentage = frequency * 60000; Also I think you have a problem with your brackets (}) [CODE] public class Assignment5 extends JApplet { .... .... // Multiply the frequency to 60000 to get the percentage line 38 percentage = frequency * 60000; public … | |
Re: Here are some compiler errors: [ICODE]Sanner input = new Scanner(System.in)[/ICODE] [COLOR="Red"]should be[/COLOR] [ICODE]Scanner input = new Scanner(System.in)[/ICODE] Also the <h> variable is never initialized so you will get an error. Try doing h = 0, but then the result would be zero, since you never read it. Also it is … | |
Re: [QUOTE=destin;729906]You mean public variable.[/QUOTE] No, [I]stultuske[/I] means: public [B]method[/B]. If it was public variable it should be declared: [ICODE]public double radius = 0;[/ICODE] Instead it is: getRadius. So when AceAtch writes: [ICODE]myCircle.getRadius[/ICODE], probably has something like this: [CODE] private double radius = 0; public double getRadius() { return radius; } … | |
Re: I don't understand exactly what your method tries to accomplish but I believe that initializing sum with counter will get you some results, or/and returning the sum instead of zero at the else {...} : [CODE] public static int myMethod(int counter) { //int sum = 0; int sum = counter; … | |
Re: I still don't get the poll. What does it mean if I vote the first and what does it mean if I vote the second? | |
Re: [QUOTE=adetya;726714]hi! can anyone please help me complete this code[/QUOTE] You have got to be kiding | |
Re: First of all the way you create your own exceptions is wrong. You don't need to create a String variables: exception. The Exception class has a method: getMessage() which returns the description of the exception that occurred with everything you need to know. So you don't need the getException() method. … | |
Re: [CODE] public static void main(String [] args) { } [/CODE] The (String [] args) is the argument of the main. When you call the java program with arguments at the command line those arguments are stored in the args array: >java Translate arg1 arg2 "arg 3" Now in your program … | |
Re: When you click the button you need to hide the current JFrame and call the other. [CODE] class JFrame_A extends JFrame { .... .... public void methodBuitonClicked( ...... ) { JFrame_B frameB = new JFrame_B(); this.setVisisble(false); frameB.setVisisble(true); } ..... ..... } [/CODE] If you want from the frameB to go … | |
Re: You need to put commands such as this in methods: [icode]System.out.println("Input temperature in ºF ---> ");[/icode] Also in java if you want the power of a number use: [icode]Math.pow(double a, double b)[/icode] | |
Re: You cannot because q is defined in C not in B You cannot because it is declared private. [CODE] class A{ private int o,p; protected B bClass; protected C cClass; public void method() { System.out.println(cClass.o+";"+cClass.p); //this is wrong: bClass.q } } [/CODE] Also none of the above will work because … | |
Re: Write a separate method that takes a String as argument and removes all spaces: Input: +0 69 34 55 --> Result: +0693455 [QUOTE] And sometimes the first 0 is missing, and they appear as 868242602. and sometimes they might be in the form +353868242602. [/QUOTE] Then another method that takes … | |
Re: These calculation need to go inside the methods: [CODE] //The getArea method returns the value that is stored in the area field double area = (PI * radius * radius); //Formula to get the area of the circle public double getArea() { return area; } //The getDiameter method returns the … | |
Re: There is Math.round() that rounds a double: 10.9 --> 11.0 10.4 --> 10.0 If you want a certain number of decimal digits you can: Multiply (for example) the number with 100, then round it with the above method and then divided again with 100: 10.123456 --> 1012.3456 --> 1012.00 --> … | |
Re: With the hashCode() you compare objects. It's no different than using equals() So if you use: File.hashCode() or File.equals() you will compare 2 file objects. Now I don't know the rules that these methods were written but I presume that they compare the path of the file they refer to. … | |
Re: The r.toString() returns a String, it does not print. You need to call System.out.println() with argument r or r.toString() | |
Re: The error has nothing to do with the ArrayList. You forgot to implement the method: suggestions(String) | |
Re: When you have a degree as a parameter you don't know if it is in Celsius or in Fahrenheit. So you will use the scale to determine that and calculate the results accordingly. [U]So don't put any calculations in your get Methods.[/U] When you set the degree (by Constructor or … | |
Re: [QUOTE=daBaki.;716632]Can someone help me how to read and write text file using Java Code... ??? Thanks in advance..[/QUOTE] Start you own thread. This thread started by someone who had a problem. Now, do you expect people to start helping you and stop answering the other guy's question? Start your own … | |
Re: You cannot use what you declare in B inside A. Only the other way around since it is B that extends A, so B can access what you declare in A | |
Re: [QUOTE=shubhang;717633]I observed that many programmers do not create separate functions. They write the whole program in the main function. [/QUOTE] What do you mean by saying: "many programmers". Because this is not the right way to do it. In any language. You must write small functions that are called in … | |
Re: The Employee class has these declared private: private String employeeName; private String employeeNumber; private String hireDate; Since the ProductionWorker extends the Employee you don't need to declare them again in the ProductionWorker class. Declare only these variables: private int shift; private double payRate; Since the first 3 in the Employee … | |
Re: You can view a .class file like any other file: By opening it. Use whatever program you want to open it. But don't expect to see anything. Here is a sample of what a .class file looks like when I used PSPad: [QUOTE] CAFE BABE 0000 0031 0112 0A00 4E00 … | |
Re: Also when you try to print the sentence in the end: System.out.println (+text) (remove the '+' of course), the text variable has been modified in the while loop. So you will not print the original sentence. Save the input to one more variable and print that one in the end | |
Re: Or we can do your Homework since this is the purpose of this forum: [URL="http://www.daniweb.com/forums/announcement9-2.html"]Read this[/URL] | |
Re: Haha that was a good one. [QUOTE]To allo me ton Toto to kseris?[/QUOTE] The above is a greek expression used as a reply to someone who says or asks something stupid or impossible and he thinks that is normal to ask such thing Do we have [I]praful_engg[/I]'s slaves written on … | |
Re: [CODE] BufferedWriter writer = new BufferedWriter(new FileWriter("filename.txt")); writer.write("This is a line"); writer.newLine(); writer.close(); [/CODE] Also: [URL="http://java.sun.com/javase/6/docs/api/java/io/BufferedWriter.html"]BufferedWriter[/URL] [URL="http://java.sun.com/javase/6/docs/api/java/io/FileWriter.html"]FileWriter[/URL] | |
Re: Type cast Object to Integer: Integer integ = (Integer)objectValue; integ.intValue(); | |
Re: Where one class ends and the other starts? Use code tags and have each class separately | |
Re: [CODE] if(Character.isDigit(s.charAt(j))) { //x=(int)s.charAt(j); // Try this and repeat to the other number y char ch = s.charAt(j); x = Integer.parseInt( String.valueOf(ch) ); j++; y=(int)s.charAt(j); z= x + y; System.out.print(z); } [/CODE] After you take the char, if you cast to primitive int it will give you the ASCII. But … | |
Re: They sure changed java last time I checked. They made it look like more C. But wait, this is C. Listen this is a java forum, and your code is in C, but the error you get is confusing: [QUOTE]gabor.java class or interface expected[/QUOTE] How are you trying to compile … | |
Re: Have you ever written a .java file and compile it by doing: javac file.java ? | |
Re: [QUOTE=johanna26;712873]I am new to Java applet.. pls help me out.... I have a very short period to complete this task...[/QUOTE] Since you [TEX]have a very short period to complete this task[/TEX] you should have started studying and writing code sooner, and not wait till the last moment and decide to … | |
Re: What exactly do you want to accomplish? When you say 3D volume object, you mean Graphics, or just a java class that represents a 3D Rectangular? | |
Re: You could use: [URL="http://java.sun.com/j2se/1.5.0/docs/api/java/text/DecimalFormat.html"]DecimalFormta[/URL] or try Math.round after you have multiplied the result with 100..00 and then divide t=with the same number depending on the precision you want: [CODE] double result = 0.0999999999; double d = result *1000; d = Math.round(d); d = d/1000; [/CODE] | |
Re: Search this forum and you will find many examples on how to connect to the database, even code on how to do the login check | |
Re: You can first check if the input is 'Q' or 'q' and then try to convert it into a double | |
Re: [URL="http://java.sun.com/j2se/1.5.0/docs/api/java/util/HashMap.html"]HashMap[/URL] [CODE] HashMap map = new HashMap(); map.put("ONE",new Integer(1)); Integer integ = (Integer)map.get("ONE"); int value = integ.intValue(); [/CODE] or [CODE] HashMap map = new HashMap<String,Integer>(); map.put("ONE",1); int integ = (Integer)map.get("ONE"); [/CODE] | |
Re: Try this: [CODE] Object[] possibleValues = { "First", "Second", "Third" }; Object selectedValue = JOptionPane.showInputDialog(null, "Choose one", "Input", JOptionPane.INFORMATION_MESSAGE, null, possibleValues, possibleValues[0]); System.out.println(selectedValue); [/CODE] I got it from this: [URL="http://java.sun.com/javase/6/docs/api/javax/swing/JOptionPane.html"]JOptionPane[/URL] | |
Re: Also if you had searched the forum, you would have come up with this post about Stack. Others had the same question as you, so you could have searched to see your question answered [URL="http://www.daniweb.com/forums/thread146631.html"]http://www.daniweb.com/forums/thread146631.html[/URL] | |
Re: How about: public void setListData(Object[] listData) [URL="http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/JList.html#setListData(java.lang.Object[])"]http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/JList.html#setListData(java.lang.Object[])[/URL] Also why not use these constructors public JList(Object[] listData) or public void setListData(Vector<?> listData) [URL="http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/JList.html"]http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/JList.html[/URL] | |
Re: [CODE] question = questionGenertor (randomValue1, randomValue2); // asking the user a math question boolean wrongAnswer=true; while (wrongAnswer) { results = JOptionPane.showInputDialog (question,""); if (results.equals("" + randomValue1 * randomValue2)) { JOptionPane.showMessageDialog( null, "Very Good"); rightAnswers += 1; wrongAnswer = false; } else { JOptionPane.showMessageDialog(null, "No, Please try again."); } // end … | |
Re: If you want to call methods you can only do it inside other methods (a Constructor maybe). Where you wrote the code that gives you the error you can only put variable declarations. So you must declare a method (preferably a Constructor) and put the code that gives you the … |
The End.