The idea is to create a program to add plants and retrieve plants from a Nursery. I created a class with the properties of the plants and also there is the class an Array list to keep track of the plants entered ( they will have to be printed later) (I am not too sure if adding a public class there is the best option.
The program will allow the user to pick and action and from there the code will do something. I don't want to have all the code inside 'main' The problem is in line 114.This is what I have so far.
Java Code:
package plant.nursery; import java.util.ArrayList; import java.util.Scanner; /**Class to create a plant for a nursery. public class PlantNursery
I need to get the string encodedString from the method encode able to be used in the decode method.
Java Code:
public String encode(String plainText) { int prepareString; int shiftChar; String preparedString2 = prepareString(plainText); String encodedString = ""; for(int c = 0 ; c < preparedString2.length();c++)
I need to create an applet that displays a grid of command buttons which I have done. I then need to create a new class that draws a silly picture of an alien, which I have also done. Where I am completely stuck and confused, is that I do not know how to get the drawing into the applet. My code is below. I really do not fully understand why this is not working or how to get it working.
import java.applet.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; public class MartianGame extends JApplet implements ActionListener { DrawMartian aMartian = new DrawMartian(); DrawJupiterian aJupiterian = new DrawJupiterian();
I am having problem to call a method from another class using arrays. I already know how to call a method without using arrays but I am not sure how to pass parameters to the main method using arrays. I'd really appreciate any feedback or comments!This is what I have so far.
public class Customer123 { public static void main(String [] args){ Scanner input = new Scanner(System.in); int x; System.out.print("Total number of customers: "); x = input.nextInt();
I have been reading about methods and I do have a beginner level understanding on how they work. I was trying to mess around and make a dog calculator using methods. I ran into a small snag; I cannot get the method to call to the main or the program to compile correctly. The first code below is the original. To me it looks like (based off of some examples I looked at) there should be no problems, but NetBeans gives me a few errors. 1) line 8- "cannot find symbol, variable dogYearCalc; 2) line 18 illegal start of expression; and 3) line 22 - unreachable statement.
import javax.swing.JOptionPane; public class KrisExample { public static void main (String[] args) { double dogYears = 0; JOptionPane.showInputDialog (null,"Please enter you dog's age in human years:");
[Code] ....
Someone told me that I was calling dogYearCalc without any arguments in your main method. I take that to mean that I needed to add it to the main, so I did here:
public static void main (String[] args, double dogYearCalc) {
That got rid of my first error, but then when I tried to run the program NetBeans said that I have no main class, so switched back to the original program above.
I thought that when I calling the dogYearCalc method on line 10 was the whole purpose of using a method. It seems to me that putting it somewhere in the main is counter productive.
calling a method from one class to another.I have two classes. One called Vacation and another called VacationDriver.I am trying to input an int for addVac and have the value update to the numSold within the updateSales() method in Vacation. From there it should update and display in the v1.toString in the VacationDriver.
Vacation import java.text.NumberFormat; public class Vacation { private String vacationName; private int numSold; private double priceEach;
I have a class for employees. This class has basic information for the employee but no real pay information. And 2 subclasses, one for employee's paid for hourly rates and one for those paid a yearly salary. Each subclass has their own pay() method, that calculates and returns their pay and extra fields relative to calculate that.
I'm just curious, if I do this and create an object for an hourly paid employee like so:
Can we recall the main method? I'm trying a code to recall main method (after the calling of JVM). I know this doesn't make any sense but I'm trying this just like that.
Code:
class derived { public static void main(String args[]) { System.out.println("Main Method class"); show(); } static void show()
I have a JSP page that calls a Java method .. using GlassFish 4.0 it worked just fine, now I'm trying to run it on a new server with Tomcat 6.0 but it keeps giving me this error: "the function result must be used with a prefix when a default namespace is not specified"
I have a file greenGrow.txt, and every three lines of the file has a last name, first name, and yard size. Every time a Customer object is created, I need to read the file 3 lines and assign the object a last name, first name, and yard size.
Snippet of my code:
import java.io.*; import java.util.*; public class Customer { private String lastName; private String firstName; private int yardSize;
[Code] .....
My issue is that I cannot call readFile() from the constructor, and I'm assuming that's because I throw Exception on readFile(). Is this a simple fix, or am I looking at it the wrong way?
My program crashes every time I call this method because of the while loop. I guess its going into a infinite loop. The game should keep running until the user ends it. Is the use of my .isKeyPressed correct and if so what else could it be?
public static void run() { while (true) { if (StdDraw.isKeyPressed(KeyEvent.VK_Q)) { break;
I need to access a method from a dll in java as below and is giving an error
"Exception in thread "main" java.lang.UnsatisfiedLinkError: Testdll.Decrypt(Ljava/lang/StringLjava/lang/String; at Testdll.Decrypt(Native Method) at Testdll.main(Testdll.java:31) " I have included the jna-4.0.0.jar and the HashMatchCryptography.dll to the project in eclipe and the java-library-path has the path for the lib
When I try to call an object it can't find the symbol in the argument list. NetBeans says that it cannot find the movieCategory symbol when I try to call it. When I compile it to test a popup comes up that states "One or more projects were compiled with errors. Application you are running may end unexpectedly. I ran it anyways and everything runs up to the point of where it should call the object.
At this point it should get the Movie object and run the code within that, but if I put one of the categories it throws. "Exception in thread "main" java. lang.RuntimeException: Uncompilable source code - Erroneous tree type: <any>at MovieApp.main(MovieApp.java:33)Java Result: 1"
From my understanding to call an object it requires objectName.methodName(argumentList). Here is my Main method
/** *This application will store a list of 100 movies and display them by category */ import java.util.Scanner; public class MovieApp { public static void main(String args[]) { //Displays <code>String</code> welcome message System.out.println("Welcome to the Movie Application."); System.out.println("There are 100 movies in the list."); System.out.println("What category are you interested in?"); System.out.println();
I've created a getMin method to return the smallest value in a queue. However, I'm having trouble calling the method in my main.
/** * Main method. * * @param args * the command line arguments; unused here */ public static void main(String[] args) { SimpleReader in = new SimpleReader1L(); SimpleWriter out = new SimpleWriter1L(); Queue<Integer> testQueue = new Queue1L<Integer>();
This current one is to calculate a planes holding pattern. I have to write a method to prompt user to enter speed in knots, then it converts it to km/hr. Another method to calc. pattern width using the speed, another method to calc. pattern length, than a main method which would call and print out the speed in knots, speed in km, pattern width and length.My current problem is on the second method. It works in that I can enter the values and it gives me the correct answers, however it's asking me to enter the speed twice, instead of just once. Anything I try just results in errors and won't compile.
import java.util.Scanner ; //main method public class TitleRemoved { public static void main(String[] args) { double airSpeedKm = airSpeedOts () ; System.out.println("That speed is " + airSpeedKm + " km/hr.") ;
[code].....
I want my code to not only work, but be organized and easily readable as well, so I want to avoid bad habits.
I have a paint program in Java where I can draw objects. The objects are stored in an arrayList. In the menubar the user can chooce "Back", which means the last item in the arrayList is removed. After that I want the program to loop through the arrayList and draw the remaining items.
My problem is that when I try to do that it will not work from the menu (menuItem2). If I instead add the code to one of the colorpanels (yellowPanel), from where the user can pick colors, it works fine.
menuItem2 uses ActionListener and yellowPanel uses MouseListener. public class PaintProgram extends JFrame implements ActionListener {
I have a PrimeFaces page with a calendar component on it. Radio buttons on that page work fine and call the setter method on the back end. The Calendar however doesn't call the setter. The getter method is called on page display.I'm using the PrimeFaces v 5.0 jar file.
a)Write a method that recursively displays any given character the specified number of times on one line.For example, the call: displayRowOf Characters(,5);
Produce a line: *****Write another method that uses a for-loop to perform the same process.
B is something like this ? for (i=1; i<=n; i++) i= '*' * n; System.out.print(i);
I have a driver and a main program. How would I go along with calling the encode method to the driver class that I made so I can have the user inputs affected by the encode method?
Java Code:
public class ShiftEncoderDecoder { private int shift; public ShiftEncoderDecoder(int shift) { setShift(shift); } public int getShift()
I'm trying to call the grade.processFile method from the main method but I'm getting this Error below. I'll post my code which includes the main method and the class underneath the error message:
Exception in thread "main" java.lang.NullPointerException at java.io.FileInputStream.<init>(FileInputStream.jav a:130) at java.util.Scanner.<init>(Scanner.java:611) at MyGrades.processFile(MyGrades.java:49) at myGradesMain.main(myGradesMain.java:19) import java.util.Scanner; import java.io.*;
Say I have two classes, Author and Book, and I have 2 author objects and 10 book objects. I would like to know how to do two things:
1) Make some sort of connection that makes clear that author X wrote books A, B and F. 2) Call a method from a book object that is connected to an author.
Seeing as I don't know which books will be connected to an author, is there some way to call a method of an object bases on a variable object name? Something like call the getFirstPage() method for every book that is linked to author X?