The question I have is on the awt import.If I have import java.awt.*;I assume that that will include all I need under the awt directory but the next line, import java.awt.event.* why the java.awt.*; does not include the .event.*; directory as well?
My first Java project contains 30+ imports, all of which are for specific classes -- I'm using NetBeans and whenever I instantiate a new, unimported class I just click on the "light bulb" and tell it to import. I'm only now starting to worry about code management and conventions.
As you can imagine, many of these imported classes live in just a few packages, like awt and file.nio. It's starting to make my code a little cluttered. In the real world, what is the convention for import statements? My instincts tell me I should just import using the .* wildcard, but how do professionals do it? If an experienced programmer were to pull my code from Github, what would they want or expect to see in the import lines of code: a bunch of specific imports, or wildcard imports?
The followings are what I see just now..... //****************************************** Ambiguities
Wildcard imports have one problem though: they can lead to ambiguities when classes with the same name exist in two packages you import via wildcard.
Imagine the following two imports:
import foo.*; import bar.*;
Now you want to use the class foo.Node but there is also a class bar.Node. Now you need to use non-wildcard imports to resolve the ambiguity that would happen otherwise.
I made a game but i didn't add imports, i have been told i need to have imports and it needs to be in a normal swing format or it will not pass . How to change my code to swing format?
My code is
public class TextTwist extends javax.swing.JFrame implements java.awt.event.ActionListener { // hard code, should be picked from a Problem class private String[] letters = {"F","O","C","I","E","F"}; // hard code, should be picked from a Problem class private String[] solutions = {"ICE","OFF","FOE","FOCI","OFFICE"};
[Code] ....
How do i get the program to move on to the next one String?
I have assigned random numbers to an 2D array, and I had to write a method that prompts the user for a number between 100 and 200. If that number is in the array, it should return 1. If not, 0. It only stays 0 though, even when the number matches one of the numbers in the array.
public static int Findit(int[][] numbers, int guess) { int Findit = numbers[0][0]; int i = 0; int x = 0; boolean found = false; for(i=0;i<numbers.length;i++)
I have been struggling to find out what to change to allow my code to find the GCF of two numbers. The instance variable in the class is num, so I need to find the GCF of a and num. It works for the example problem of 25 and 15, returning 5, however it will not work for other problems.
public int findGCD(int a) { int result = 0; int newNum = num; if ((a > num) && (a % num != 0))
My current problem is when im trying to choose case 2 and call markItemOnLoan i cant seem to find the title i want after i enter a few. I will include all of my code but i have mentioned what I am currently stuck on :
import java.util.Scanner; public class Library { public static void main(String[] args) { Scanner input = new Scanner(System.in); MediaItem mCall = new MediaItem(); Library call = new Library();// makes instance
How to declare a 2 dimensional array of interger of size 10 by 10. and then set every element of the array to 3. After this I need to add up all the element in this array and return the value.
final int ROWS = 10; final int COLS = 10; int[][] foo = new int[ROWS][COLS]; for (int i = 0; i < ROWS; i++){ for(int j = 0; i< COLS; i++){ foo[i][j] = 3; } }
This is what i have done so far(not 100% if is correct..) but how to add up all the array.
I have an assessment for college, the part of my code that im struggling with is the part where the user enter their first name followed by a space and then their second name. I m using ---------------fullname = JOptionPane.showInputDialog("enter your firstname followed by a space then your second name " ); ------------- to capture this. the issue is if the user only enter 1 name I need to output an error. the issue is I cant find a way to tell if the user entered a second name. This is what I have so far:
public void makename() { // makes an inputbox to ask their name fullname = JOptionPane.showInputDialog("enter your firstname followed by a space then your second name " ); //separates the first and second name into 2 strings in order to make the username
[code]....
The problem is it accepts anything I type in without causing an error. What should I type in to stop this? ive tried anything but I cant find a way to tell if a surname has been entered or not.
Often times i don't remember which package a specific class (like ArrayList) belongs to. Is there an easy way to find that java.util.* is what i need to import, if i wanted to use the class ArrayList ?
I'm trying to find the median of a set of numbers inputted into an array and I wanted to know how I would pass the array to the median calculator after I use selection sort to organize the numbers.THIS IS THE CODE THAT ORGANIZES THE ARRAY:
public void selectionSort(double[] myArray) { for (int i = 0; i < myArray.length - 1; i++) { int index = i; for (int j = i + 1; j < myArray.length; j++)
if (myArray[j] < myArray[index])
[code]....
The code that finds the median will only work if the array being used is already organized. How do I pass the new sorted array to the code that finds the median?
I am writing a code based on the following question: "Write a method called arrayMin that accepts as an argument an array of numbers and returns the minimum value of the numbers in that array.Create an array to test your code with and call the method from main to print the min to the screen".
I cannot seem to get the code to calculate the minimum number.
Here is my progress thus far:
import java.util.*; public class Lab11q3 { public static void main(String[] args) { Scanner console = new Scanner(System.in); int number;
class triangle { public static void main (String[] args) { System.out.println("Provide three side lengths - 000 to terminate."); int a = In.getInt(); int b = In.getInt(); int c = In.getInt();
[code]....
My problem is that when I enter 5,2,5 it should be isosceles and acute but it comes out as isosceles and obtuse, and when I type 5,5,5 it comes out equilateral and right. The only one that works is if I enter 3,5,4 it will come out as scalene and right. I been at this for a while and my math looks correct.
For my project I have to write a piece of code where it returns true or false value depending whether the indicated cell is on edge of a rectangular grid (true) or not (false). Any algorithm for the following method: public static boolean onEdge (int n, int numRows, int numCols)?? To highlight, numRows and numCols and n start from 0.
I'm almost finished with my assignment, I'm just having one small issue. The goal of this assignment is to have a user input as many values they want(up to 10) into a list. I need to store those in an array then figure out the sum of the numbers, the average, the Largest value, and the smallest value. I get everything to print out correct so far except for the Smallest number, it is returning a 0 every time. Here is my code:
import java.util.Scanner; public class SimpleList{ Scanner in = new Scanner(System.in); final private static int ARRAY_LENGTH = 10; private float[] List = new float[ARRAY_LENGTH]; private int count = 0;
I'm trying to apply a subset problem without using O(n^2) complexity. I need to find the smallest possible sum between 2 sets of 2 numbers in a lists so n1 + n2 = n3 + n4 = sum.
I have found solutions that all involve having the sum first and just finding the two pairs which involves using a hash table and then taking each number and subtracting it off the sum and looking for possible combinations.
How to do it if nothing but the list of numbers is given. So no sum and no hint of the pairs.
I put this in the Java section because I'm doing it in Java and there seems to be no generic algorithm/programming Topic area.
I have written the following code to try and find a factorian but it doesn't work all the time. A factorian is supposed to be the sum of the factorials.
public static boolean isFactorion(int n){ boolean rv = false; int sum =0; int fact = 1; for(int i = n;i>=1;i--){ fact = fact * i;
I'm trying to create a class that takes an String from a Stack and checking if it's a palindrome than taking a another String from a queue and checking if that is also a palindrome.
import java.util.Stack; public class Palindrome { public static void main(String[] args) { // TODO Auto-generated method stub String enteredLine; int leftStack, rightStack; int leftQueue, rightQueue; PalinedromeArray stack1 = new PalinedromeArray();
Here is my code that is supposed to read a user-selected document, create text boxes from that info, and display them. (There is a lot of code in there that may not be relevent, but just ignore that.) When I compile, I receive errors that it can not find the symbols color, xIn, yIn, w, and h.
Here's my code:
import javax.swing.*; import javax.swing.event.*; import java.awt.*; import java.awt.event.*; import java.util.*; import java.io.*; public class Ex22 extends Basic {
I am having a problem finding string objects in a jTable. I use setValueAt() to write string variables into a jTable.
I can then use getValueAt() to search to find any of those strings. All works fine until I edit an entry in the table. Then I can never find that string again.
In fact, if I just click in the cell type a character, then delete that character, something changes. The contents of the cell look the same but the search for it doesn't find it.
For example if I have a string "xyz" that was written in a cell. If I set the search value, "a=xyz", and "b=getValueAt(some cell)".
Then at the compare:
if(a==b) I can hover over a and b and I see that; a = (java.lang.String) xyz
and
b = (java.lang.String) xyz
[note I am using NetBeans to do this]
after the compare, the true path is taken .
If I then click in the cell then click out and try the same compare, everything is exactly the same including what gets reported when I hover. But the false path is taken at the "if".
public class StuTest { private static Scanner keyboard = new Scanner(System.in); public static void main(String[] args){ int[][] testScores; // [students][tests] String[] stuNames;
[Code] ....
The method I am having issues with is the "printStudentReport" method. I am trying to calculate the average of a randomly generated number of students and tests. For my "printTestReport" method, I have to calculate the average of the test by test number.