1,963 Posted Topics
Re: You don't add friends here: [CODE] System.out.println("Enter a friend by their first name"); firstName = input.nextLine(); [B][COLOR="Red"]friendList.add(firstName); [/COLOR][/B] System.out.println("Enter a friend by their last name: "); lastName = input.nextLine(); [B][COLOR="Red"]friendList.add(lastName); [/COLOR][/B] System.out.println("Enter their telephone number: "); telephone = input.nextLine(); [B][COLOR="Red"]telephoneList.add(telephone);[/COLOR][/B] [/CODE] You simply add the info of one friend. How … | |
Re: Are you sure you have the right formula? Also shouldn't you have this: [CODE] powerSeries [B][COLOR="Green"]+=[/COLOR][/B] 1 +(negationFactor * (Math.pow(radians, expFact))/factorialResult); [/CODE] | |
Re: I started this post after you added your second post. The extended class seems fine. What is the problem with driver. Just instantiate it and call its methods. | |
Re: Edit: Sorry for the mistake post. I didn't see the names of the posters. Also, [I]sheehab[/I] posting just the code will not do you any good. You need to explain what it does in general, what it is supposed to do, how it behaves now, what errors do you get … | |
Re: If you want to use a .txt file, and you find databases difficult find examples on how to read files in this forum using the Scanner class or the BufferedReader class. After you read the file into a Vector or ArrayList check the username and password entered to see if … | |
Re: First of all, don't do this: [CODE] for (int i = 0; i < 20; i++) ... for(int i=0; i <12; i++) [/CODE] Use the length of the array: [CODE] for (int i = 0; i < tran.length; i++) ... for(int i=0; i <inter.length; i++) [/CODE] How do you know … | |
Re: Use code tags and post [U]only[/U] relevant code. | |
Re: Try a for loop, start would be one of the numbers and the end the other. Check to see which one is greater in case you need to display them in descending order, by reducing the index instead of increasing. | |
Re: Use the String.[B][COLOR="Green"]charAt()[/COLOR][/B] method to loop and get each character. Then have a HashMap. Whenever you get a character check the map. If it is in there then take the value stored, increase it by one and then put it in the map to replace the old value. If it … | |
Re: I don't believe that getClickCount does what you think it does. Nor if you get the Point, you will be able to find which button was clicked. If all you want is to disable the button then: [CODE] buttons[i].addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { JRadioButton source = (JRadioButton)e.getSource(); … | |
Re: If you search this forum you will find examples on how to: > Read a file > Write to a file > Use the split method > Create objects > Add them to Vector or ArrayList And to make things simpler, don't try to put everything in the main method. … | |
Re: Actually you should have something like this: [CODE] int index = 0; for (int i=0;i<array.length;i++) { int num; // read int number System.out.[B][COLOR="Green"]print[/COLOR][/B](num+" "); // loop again through the array to see if that number already exists if (doesn't exists) { // put it into the array [B][COLOR="Red"]array[index] = num; … | |
Re: The split returns an array. And you try to cast it to ArrayList. From the String get the String [] array using the split method. Then loop through the array and [U]add[/U] its elements to an ArrayList | |
Re: Well since you found the number you know one of the occurrences of the number. Assume this: You are looking for '3' [QUOTE] 1 2 3 [B][COLOR="Red"]3[/COLOR][/B] 3 4 5 [/QUOTE] And you find the position of the "Red" 3. So all the others 3s will be either left or … | |
Re: [QUOTE=cute.sridhar;1051959]There is any java Language Translation API. If so means, please indicate that API.[/QUOTE] Please explain. | |
Re: If I understood correctly whenever you click a button you need to get a value from a "set of values" depending on the value of the radio button? If yes then you don't need any listeners to the radio buttons. Whenever a button is clicked, you can get the value … | |
Re: The problem is probably because it cannot find this class: com.microsoft.jdbc.sqlserver.SQLServerDriver when you call the Class.forName Have you download and set to your classpath this driver: [ICODE]com.microsoft.jdbc.sqlserver.SQLServerDriver[/ICODE]? | |
Re: [QUOTE=GTJava;1053446] ERROR: non-static method isPrime(int) cannot be referenced from a static context [/QUOTE] As the error says, You cannot call a non-static method inside a static method. | |
Re: For starters, use the .equals method to compare the equality of Strings and any other objects. See what happens and I will look closely the rest of code later. [CODE] String s1 = "a"; String s2 = "b"; // examples boolean b = s1.equals(s2); b = s1.equals("ccc"); b = "abc".equals(s2); … | |
Re: One suggestion is to read the entire file and then write again what you want at the first line and the write the rest of the data read | |
Re: [QUOTE=MxDev;1052174]Sorry I couldn't get it, would you make it a little bit clearer!!!!!!!! Thanks [EL-Prince][/QUOTE] What? Wasn't this clear enough? [QUOTE=Ezzaral;1051862]Learn manners first.[/QUOTE] Who are you to demand? | |
Re: Search the forum for examples on how to read files | |
Re: for-loop that adds spaces equal to the number of row currently printing. Also use for loop to display the number of "*" Displays N spaces [CODE] for (int i=0;i<N;i++) { System.out.print(" "); } [/CODE] | |
Re: I would suggest to look for tutorials on all of them. In sort: > Statement for executing "raw" queries: [CODE] String name = "Name A"; String query = "select * from table_A where name = [B][COLOR="Green"]'[/COLOR][/B]" + name + "[B][COLOR="Green"]'[/COLOR][/B]"; // Use statement to execute the above query. [/CODE] > … | |
Re: The dashed borders appear whenever you select something. If you add a lot of buttons in a frame and you click one it is natural the it will appear selected. I believe that these dashed line are to show you which element you selected. My advice, although you will have … | |
Re: In order for this method to execute: [CODE] public void actionPerformed(ActionEvent e) { Izzy.hittable(); Izzy.movement(); if(rar == 'T') { System.out.print("Sky High(Grand Nuave)"); } } [/CODE] You need to add its listener to a component. The methods in the 'KeyListen' are executed because you do this: [CODE] p.addKeyListener(new KeyListen()); [/CODE] When … | |
Re: Aren't you suppose to do this: [CODE] dRetirement = keyboard.nextDouble(); [B][COLOR="Green"]dGrossPay = [/COLOR][/B]grossPay(dHours, dRate); //netPay(dGrossPay, dRetirement); [/CODE] Instead of this? [CODE] dRetirement = keyboard.nextDouble(); grossPay(dHours, dRate); //netPay(dGrossPay, dRetirement); [/CODE] | |
Re: You already have a for-loop, you don't need another while-loop. Max should be initialized with one element from the array, preferably the first so you can start your loop from i=1: [CODE] max=arr[0]; for (i=1;i<arr.lenth;i++) { } [/CODE] When you write: int max=0,i; you declare i to be an int, … | |
Re: Your problem is reading the file. What is the format of the file. Can you post some of its data. Also I would suggest to create an object with properties the data you are reading: [CODE] class YourClass { private String employeeName=null; private int employeeNum=0; .... // declare constructor and … | |
Re: You can check the API to see if there is a way to get the data from the table. | |
Re: Try to better explain your problem. What you posted is difficult to quite understand. Also, don't tell me that your teacher hasn't showed how to write a single class with attributes and get/set methods. Or don't you have a book or notes with examples? | |
Re: I suppose by the time you have been given this assignment your teacher has showed you how to write programs and how to run them or how to declare methods ans use them. I assume that you have some notes on how to declare and instantiate classes, or how to … | |
Re: I would have used the sleep method: [CODE] // line read: line = readLine(); // take the time at the end of the line: lone time = ... ; try { Thread.sleep(time); } catch (Exception e) { } // repeat the loop [/CODE] I would suggest to put the above … | |
Re: Try run it without the .class extension: > java Hi Then post the error that you will get :) | |
Re: Isn't this suppose to throw an ArrayIndexOutOfBounds Exception?: [CODE] names[names.length] = ... [/CODE] names's length is [B][COLOR="Red"]1[/COLOR][/B] [ICODE]java.lang.ArrayIndexOutOfBoundsException: [B][COLOR="Red"]1[/COLOR][/B][/ICODE] | |
Re: Yes, but you didn't say what the error is. The code seems fine. What is your problem? Also you should post a few lines of the file you are reading. Also check the API for the class: Scanner: [URL="http://java.sun.com/j2se/1.5.0/docs/api/overview-summary.html"]http://java.sun.com/j2se/1.5.0/docs/api/overview-summary.html[/URL] You will find it at the link: java.util at the left … | |
Re: When you get that error it means that something is null. At that line it means that 'fc' is null. Did you initialize it? Because I didn't see it in your code. | |
Re: It's not a big challenge. We can easily do it. Can you post something more difficult because I am bored? | |
Re: You should have made this a code snippet. Nevertheless it is very simple example, very useful only for beginners. | |
Re: I don't know. Have you checked the API for Treemap? | |
Re: [CODE] Partysupply[] pippo = new Partysupply [20]; pippo[0] = new Partysupply(); [/CODE] You need to initialize all the elements of the array. With your code, you initialize the pippo[0] [U]but[/U] the pippo[1], pippo[2], pippo[3] are null. Don't forget that when you do this: [ICODE]pippo = new Partysupply [20];[/ICODE] You initialize … | |
Re: And are we suppose to do? From what I read you didn't ask any questions in your post. | |
Re: Check out the css tutorial at: [URL="http://www.w3schools.com/css/default.asp"]http://www.w3schools.com/css/default.asp[/URL] | |
Re: You don't run the programs, you call the methods. If the other programs are inside a main, then take that code and declare it as a method and call the method. For arguments, You might want to add some JTextFields. Check the API for JTextFields. An example on how to … | |
Re: These lines are incorrect: [CODE] GetBookDetails(); newBook = new Book (IDNum, Title,Author,Publishr,CatNumPublicationYr,returnDate,BookStat,ISBN); [/CODE] with the GetBookDetails you get all the date from the gui, but when you call the "new Book" you "erase" the previous object and replace it with the new one. At the next lines the [I]newBook[/I] doesn't … | |
Re: [QUOTE=JavaStudent23;1047111] Let’s say they get on the bus on ‘stop 3’ and go to ‘stop 9’, how would I code this? [/QUOTE] From stop 3 to stop 9 there are: 3,4,5,6,7,8,9 stops. The first doesn't count because the passenger has just entered the bus so you can not charge him … | |
Re: Because you are saving the object as binary data not as text. You are serializing. You cannot open the file and view it. If you want to read it then use the opposite way. FileInputStream ObjectInputStream If you want to save it as text then use BufferedWriter, but it needs … | |
|
The End.