I am trying to write a code that allows you to input 2 lists and it tells you if they are identical or not. However, when I enter my fist list I can only enter two values and then it asks for the next list. How would I fix this to allow me to enter more than two values?
Also, If the second list is different it has me enter more values that list one.
public static void main(String[] args) { Scanner input = new Scanner(System.in); // Enter values for list1 System.out.print("Enter list1: "); int size1 = input.nextInt(); int[] list1 = new int[size1]; for (int i = 0; i < list1.length; i++) list1[i] = input.nextInt(); // Enter values for list2 System.out.print("Enter list 2: ");
I have an applet program here that allows the user to choose a movie then a number of tickets from a drop-down list. A check box should display for users to click so they can receive a discount for matinee movies. The user should be able to click a calculate price button to display the total cost and a clear button to clear each drop-down list and the check box. The program compiled but when I clicked the calculate button, it generated so many error codes like java.lang.nullPointerException and a lot more. I just wanted the program to work properly. Code below:
import java.awt.*; import java.awt.event.*; import java.applet.*; public class Proj4exe2 extends Applet implements ItemListener, ActionListener { Choice movieChoice = new Choice(); Button calcButton = new Button("CALCULATE");
The purpose of this function is to use a Movie object and a binary search tree to find all movies that have been read in through a file that have a certain rating (G,PG,PG-13,R). The error I am getting is that it seems I am not traversing fully through the tree and therefore only some movies with the rating I search for are output, not all of them with that rating. I have tried figuring out why this is happening and at first I thought my tree was unbalanced, but I am sure it is simply because I am not traversing the tree correctly. I think my implementation in the main is close to what I need but it needs some tweaking. This is my BST class which I created and required to use for this purpose.
public class BinarySearchTree { /** * The head of the tree. */ private Node root; /** * Constructor that declares the head of tree to null. */ public BinarySearchTree() { root = null; } /** * Returns null if head of tree is empty. * @return null if head of tree is empty. */ public boolean isEmpty(){
So basically I have to create a java program that accepts a string and does the following:
1.) Insert a blank space before capital letters 2.) Convert any capital letters into lower case except the first letter(if it is capital).
So if the user enters "HiMyNameIsJohn", the result should be "Hi my name is john". I am having problems inside my changeMe method. Everything works fine including putting a blank space in between upper case words. So from the previous example, my code would show "Hi My Name Is John". I am having issues making the code to convert the upper case letters into lower case. Im pretty sure the code should be right after the str.insert(i, " "). But I do not how to code it. Ive thought about Character.toUpperCase(ch); but doesnt work.
Java Code:
import java.util.*; public class WordSeparator { public static void main(String[] args) { String word1, word2; Scanner userInput = new Scanner(System.in);
This is titled "Creating static methods that accepts arguments and returns a value". I think that I understood everything about this except for the very bottom part of the code. I wasn't really sure where to put it. From the errors that I am seeing, I know which line is giving the errors but I'm not sure what is wrong with it.
import java.util.Scanner; public class ParadiseInfo2{ public static void main(String[] args){ double price; double discount;
[Code] ....
Errors:G:ParadiseInfo2.java:29: error: illegal start of expression public static double computeDiscountInfo(double pr, double dscnt) ^ G:ParadiseInfo2.java:29: error: illegal start of expression public static double computeDiscountInfo(double pr, double dscnt)
Write a method named hopscotch that accepts an integer parameter for a number of "hops" and prints a hopscotch board of that many hops. A "hop" is defined as the split into two numbers and then back together again into one.For example, hopscotch(3); should print:
How do I code this without having the need to use iterator? Code a Java method that accepts an ArrayList of integers and an integer. The method should delete all elements in the array list exactly divisible by the integer and return the number of remaining elements.
Write a class that accepts a user's hourly rate of pay and the number of hours worked. Display the user's gross pay (gross pay = hours worked * hourly rate), the tax withheld (tax withheld = gross pay * tax rate) and the net pay (net pay = gross pay - tax withheld).Use a named constant for storing the tax rate of 0.15
Here is my Code:
import java.util.Scanner; class Tutorial { public static void main(String[] args);
import java.io.*; public class pho { public static void main (String args[]) throws IOException { BufferedReader br = new BufferedReader (new InputStreamReader (System.in)); String name = new String [50]; long phn = new long [50]; System.out.println("enter A for adding phone numbers");
how many integers the user wants to use. The user will enter for example a 4. The user inputs a 2, 4, 6, and 10. So then we get our outputs...Then the code will ask if you want to run this program again. My question is, if the user inputs a -1 for example 2, 4, 6, -1....the code will not continue. I wanted to use a while loop, such as while (scores != -1) but it doesn't work.
Enter the amount of integers you want to use4 Intenger # 1 2 Intenger # 2 4 Intenger # 3 6 Intenger # 4 10 You entered 2.0 4.0 6.0 10.0 Average = 5.5 Variance = 8.75 Standard Deviation = 2.96 Do you have another set of numbers?
I am working on allowing a user to enter an ID # using JOptionPane. If the ID is valid, then it will display the ID#, student name, and GPA. If it is not valid, then the window should pop up again to allow the user to enter a valid ID. I have managed to get that far.
I am struggling with once a valid ID # is entered, how do I get the loop to stop? I have tried several different ways, but the code below is the most recent one, and it is still not working!
import javax.swing.*; public class StudentIDArray { public static void main(String[] args) { String enteredID; int idNumber; int x = 0;
I have problem with this applet. the browser gives page.I don't know wether its not loading or if its extremely slow.Also I am confused on the html part.Should I use tag object or applet and for entering class name data,classid or name.
import java.lang.reflect.InvocationTargetException; public class NewJApplet extends javax.swing.JApplet { @Override public void init() { this.add(fesText); this.add(jButton1); this.add(jLabel1); this.add(jLabel2); this.add(jPanel1);
i am writing a program that would be used for ticket sales and their are 100 tickets and a person can only buy 4 at a time. i need my program to not go negative at the end and also i need to stop the user from entering a negative number.
import java.util.Scanner; public class ticketmaster { public static void main(String[] args) { // Variable decoration uses strings , doubles and final doubles. Scanner in = new Scanner(System.in);
i am writing a program that would be used for ticket sales and their are 100 tickets and a person can only buy 4 at a time. i need my program to not go negative at the end and also i need to stop the user from entering a negative number here is the code.
import java.util.Scanner; public class ticketmaster { public static void main(String[] args) { // Variable decorationuses strings , doubles and final doubles. Scanner in = new Scanner(System.in);
I mainly would like to know is a int[4][4] or a int [4*4] is more efficient to use. Which takes more storage? Which requires more to process? that kind of stuff.
If I try CLASSPATH: C:Program FilesMicrosoft JDBC Driver 4.0 for SQL Serversqljdbc_4.0enusqljdbc4.jar I receive a "Could not find or load main class" error.
I think, is of concern to a large Swing-JTabbedPane users and which does not appear in the Sun-Oracle tutorial [URL]
How to add functionality to the hidden 'Action Listener' of JTabbedPane to obtain the two following functionalities, when passing from Tab_Panel_1 to Tab_Panel_2 ?
- To call a home made function as very last task when the 'tab selection change' is triggered and just before control and visibility are leaving Tab_Panel_1.
For example : Calculations and table fillings need to be operated. One assume that the fact of leaving Tab_Panel_1 (by clicking another 'tabPanel') means that the input data in Tab_Panel_1 are completely introduced and that calculations and/or table fillings may occur (to be used by other 'Tab_Panel's).
- At the moment of entering Tab_Panel_21 or Tab_Panel_22, the very first task is to use the previous calculation results and/or table fillings as input parameter of methods own to Tab_Panel_21 and Tab_Panel_22.
For example, these data are further processed and used to feed a graph, different for Tab_Panel_21 and Tab_Panel_22.
The problem is, the JTextArea that's created has a "limited" number of rows - it seems you can still enter more lines than the "limit", but they don't show. I thought it was a problem with the JScrollPane but I'm not so sure...
I'm trying to make a stock program that stops the user from entering in textfield and displays a message when stock is low. There's just 2 problem the entered value by the user is only decremented twice then the total stock resets for example with SofaTotal and the if statement doesn't work:
I'm wonder about the issue of constructor for arrays. Let say I have a class tablica, and one component int[] tab. If I get it right until now tab is nothing more than empty reference to some unexisting array?
import java.util.Random; class tablica{ int[] tab; tablica (){ // i wish it was constructor
[code]....
Then, I'm trying to build the constructor for class tablica. What can be the parameter of such constructor? Is it fields of array? It is simple forf for basic variable
- I liken values defined in constructor with those global defined in class. But how to do it with array component tab.
If I create array object in main method then how can I use this constructor?
In the program below I populated three arrays: student id, name, and GPA. The findStudent() method attempts to match users input with the input stored in the studentID array using an if/ else statement. When I use the if/ else statement the else always executes regardless if the IDs match? I am trying to get JOptionPane.showMessageDialog(null, "Incorrect entry"); to print only if the IDs don't match.
Java Code:
//FILE: StudentIDArray.java import javax.swing.*; //Used for the JOption dialog boxes import java.util.*; //Used for Scanner input public class StudentIDArray { boolean nameFound = true; final int numOfElements = 2; //Final int to control to loop for data
I'm working on a side project, which will eventually hopefully be a Pokedex, and I've just been going to it at the end of every chapter and using the stuff I've learned to work on it.So I just read chapter 3, which is all about variables and teaches how to use arrays.
my question is, does an array have to be declared inside a method? Because I'm trying to create an array inside a class without any methods and without the main, and I continuously get errors. Here's a quick working of my code that won't compile.
class blah { blah a[] = new blah[7]; a[0] = new blah(); }
The error message focuses on a[0] = new blah(); Telling me the 0 should be a ], the = is an illegal start of type, so on and so forth. The program compiles completely fine if it's within a method, like this:
class blah { void a() { blah a[] = new blah[7]; a[0] = new blah();
}
}
Or if I have public static void main (String[]args); But I'm trying to practice working outside of main.So does an array have to be within a method,