I use the BlueJ software to develop my programs. I am creating a program which holds two data structures; Array List and Binary Tree. I have created a person class which is used to declare variables containing people, this class also contains a method which prompts the user to input 3 characters of a memorable word. These people are created within the array list and binary tree. This actually works in practice, within the program, but i get an error, and i need the program to contain no errors.
In my binary tree class, i want to call this method.I have attached 4 images to this post, an overview of the classes used, a look at highlighted code which is an attempt at calling a method from the person class, and the method contained within the person class itself. Note that the person class is just called "Person". The 4th image is the error being displayed.
having trouble trying to understand the insertion and removal of Nodes.
I have to insert a new node at the end of the linked nodes, if i insert by terminal : 1, 2, 3. The printed nodes are going to be in the same order, 1,2, 3.
I have done the exercise, but it only prints the last node created and i dont know where its the problem. We did it before with "insert at the beginning", may be the problem is with the print() method in SimpleList.java, but i dont know how to print "backwards".
This is the code:
Node.java
public class Node { public int infoNodo; public Node next; } SimpleList.java public class SimpleList { private Node head;
I have been doing a program that allows the user to input students names and numerical grade values. I have already completed 3/4 of the program but am stuck on the bubblesort method as this is what it requires:
The program must have an indefinite loop, which prompts the user to select a sorting criterion or to end the program, and must also use bubble sort. Note: The user may either select name or grade as the sorting criteria. The program must use bubble sort to sort that data according to the specific criteria and then use another loop to display the data. This process must continue until the user ends the program.
My problem is, while i can easily do the bubblesort, where to look on how to link elements of the two arraylists I'm using (one for grades, one for names) so that when the user decides what sort they want, the individual's name and grade stays together.
I have started coding recently and been working on a simple java timer. My problem is that the button does not show any response even though an action has been done via actionlistener.
Example: When I press the "Start Timing" button, it should start timing and output the counter to Static Timer but instead of doing that, it does nothing.
The important bits are under Timer code and Button Start Timing. Is their something that I'm missing?
//--- All imports have been handled --- public class GUI { double counter = 1; double inputA = 1; int delay = 1000; Timer timer = new Timer(delay, null);
I want to know is there any way we can call parent class method using child class object without using super keyword in class B in the following program like we can do in c++ by using scoop resolution operator
class A{ public void hello(){ System.out.println("hello"); } } class B extends A{ public void hello(){ //super.hello(); System.out.println("hello1");
I am just trying to test this array, for a locker combination program that involves classes...but the array is printing out the whacky numbers for the location. When I try to call the method in the main, it does not work. How do I call a method that exist within a class into the main method?
public class locker { public static void main(String[] args) { CombinationLock();
I am currently working on a dice game. I have a private method called rollDice and it performs the action of rolling two dice. For my project, I need to create another method called playerRolls and I am supposed to invoke the rollDice method in the playerRolls method and perform actions based off of that. My question right now is how do I invoke a method into another method of the same class?
i am having a problem while calling a method..i am having a class
Java Code:
public class MySer implements Runnable { public void getMessage(String msg) { ..., }.., } mh_sh_highlight_all('java'); i use the above class in another class
In the process of creating a new class, I need to move my main method from the class SaveDate to the class DynamicTest. Below I have listed the code of both classes.The objective is to be able to run my program from the DynamicTest Class. I need understanding the process of moving my main method to a different class and creating an Object of a class and calling its method.
public class SaveData { private static final Map<String, Object> myCachedTreeMap = new TreeMap<String, Object>(); public static final List<String> getLines(final String resourceParam, final Charset charset) throws IOException{ System.out.println("Please get: "+resourceParam); if (myCachedTreeMap.containsKey(resourceParam) ) { // Use the cached file, to prevent an additional read.
Im writing a simple program to understand classes and objects. Basically what I have is a file called Program.java where I have my main method.I have another file called Person.java which I want to use to create Person objects. That person can have a name, email adress, phone number, etc.I put both these files in the same folder.in Program.java my first statement is:
My problem is that when I compile Program.java i get an error message saying that the package Person.java does not exist.So my question is, when you create a class that you want to use for objects, how do you import that class into your class with the main method so that you can use instances of your other class?
// Add range to Vehicle. class Vehicle { int passengers; // number of passengers int fuelcap; // fuel capacity in gallons int mpg; // fuel consumption in miles per gallon
// Display the range. void range() { System.out.println("Range is " + fuelcap * mpg);
[Code] ....
I'm compiling it in Eclipse and this continues to show in the console display
Minivan can carry 7. Exception in thread "main" java.lang.NoSuchMethodError: Vehicle.range()V at AddMeth.main(AddMeth.java:34)
I have a program that reads some text, and draws or deletes objects on a JFrame according to what I say. My program works fine for the most part. So whenever I say something like makeStuff(star) in my console, a star is drawn on screen. I kept track of types of objects in an ArrayList, and add and remove certain objects depending on the type of text I input. My problem is when I get to the point when there are no more objects of the same type on screen, meaning I keep clearing objects of the same type until there are no more, when I go to draw another object of the same type, it does not draw the object.
I have two classes, one for my console and one for graphical objects to be drawn. Strangely enough if I call clear twice then I can draw which doesn't make a lot of sense. When going through the debugging everything is working right, including the counters I made, and the amount of objects of the same type have the right amount when they are supposed to. I did find a work around by simply making the object in the console program class instead of calling the draw method from the sandbox class but my console class is probably a 1000 lines of code and is far too big already. I just want to use the draw method from the other class. Here are some revelant lines of code as to what I am trying to do:
Console Class Java Code:
if (cmd.equals("clear") && arg.equals("star")) { //use a boolean for when this part is done if (starCounter > 0) { box.undoStar(); starCounter -= 1; starNum -= box.getWidth() / 6;
I can't get errors of this code I think the problem is that the first method name is the same as the class name and was wondering what the simplest way to fix that is.
class CreditCard{ int transactionNum; String merchantName; double charge; public void CreditCardMethod(int someTransactionNum, String someMerchantName, double someCharge){
I created a BankCommons java file, compiled nd packaged the class file under WEB-INF/classes/com/onlinebank/..I imported the class in the jsp file as <@page import="com.onlinebank.BankCommons.*" % > I ran it through tomcat....the class is being imported..no error there.....but when i try to use one of the method in the class as : BankCommons.update, ...it throws an error that BankCommons cannot be resolved...
I have an admin class that needs to access a method of another class and I'm unsure how to do it.
One of the methods in the admin class (DancerAdmin) accesses a .txt file with information in and each line is to be extracted and is to be created as an object of the Dancer class. The information in each line is to then be used to set the variables in the Dancer class.
To set the values the Dancer class has setter methods which I need to access each time a new object is created while cycling through the .txt file. I'm struggling to access these methods from the DancerAdmin class when I run the relevant method.
The snippet of code I have from the method in DancerAdmin is
while (bufferedScanner.hasNextLine()) { currentLine = bufferedScanner.nextLine(); lineScanner = new Scanner(currentLine); lineScanner.useDelimiter(","); dancer.add(new Dancer()); Dancer.setName(lineScanner.next()); mh_sh_highlight_all('java');
I get an error saying non static method setName cannot be referenced from a static content?
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();
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 don't know why class Object have two PROTECTED method -- clone() and finalize(). And in JUnit's source code, I notice that kent write :public class AClass extends Object {}I really don't understand what diffrient frompublic class AClass {}
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:
I have 2 classes. TestClassA has 1 getter and 1 setter. From my second class, TestClassB, I want to access the getter method of TestClassA. If I try to access it, I get null. How do I do it?I do not want the methods to be declared as static. How can the getter method value be printed in TestClassB (without marking anything as static)?
public class TestA { private String name; public String getName() { return name;