I am trying to call a constructor from PrepaidCard class in my main method, but I am not sure how to proceed.
As seen below, both the PrepaidCard constructor and the setCardID method have the ability to set the card ID.
public class PrepaidCard { public PrepaidCard(String id, int token) { cardID = id; tokenBalance = token; } public void setCardID(String id, int token) { cardID = id; tokenBalance = token; } }
Now in this block of code, I can successfully pass the id and token value by calling the setCardID method from the PrepaidCard class. Now I would like to call the PrepaidCard constructor from the PrepaidCard class to pass the id and token value, instead of using the setCardID method.
public class PrepaidCardTest { public static void main(String[] args) { PrepaidCard card2 = new PrepaidCard(id, token); System.out.print("Enter Card2 cardID: "); id = input.nextLine(); card2.setCardID(id, token); } }
How to call the PrepaidCard constructor from the PrepaidCard class, to successfully pass the id and token value, in my main method?Specifically how to modify or replace this line of code so that it can correctly call the PrepaidCard constructor?
I am getting error in second constructor that I have created, it gives an error: cannot find symbol variable
package Objects;
import javax.swing.JOptionPane; public class Constructor { public static void main(String[] args) { Piggybank1 pg1 = new Piggybank1("Abhinav", 500); pg1.deposit(200); pg1.withdraw(10);
So I'm making a trading card game and each card can be moved around like chess pieces. So far, I've made the cards simple rectangles and detect if clicks are made within that rectangle and then move them appropriately, but I'm not sure if that's the best solution.
Its written that every constructor calls its super class constructor. And we know, constructors are called to create an object. Does it mean that if I am creating an object of a class, I am actually creating objects of all its super class???
I can call a child method from a main method. If I have a parent called "Assessment", a child called "Quiz", and another child called "test". Can I instinate an object like Assessment a = new test(); and call a method in test.I know the method can be called if I instinate the test t = new test() but that defeats the purpose of inheritance which I'm learning in class.
public class Person{ /*Complete*/ public String format(){ return String.format( "Name: %s", name );
[Code] ....
And I have been asked to add a new field called name, and call the display method in the main. I need to use an appropriate type and privacy for the name field, and once the code is finished, I should see 'Harry Potter' appear on the command line. However I don't know what it means by field. I've tried googling it and one search result said it is a field parameter, and another search result said it was something completely different, and I don't know which one it is. I've created a parameter 'Private String name;' but it only prints out 'name: null'
This is the code I wrote but it obviously doesn't work?
package Practical8;
public class Person{ Private String name; public String format(){ return String.format( "Name: %s", name );
The following code is located in my main class called InjectionFix. I have another class where I need to call or initiate the string in the code below. How can I achieve this. I tried to create an Object of the class but I cant do this because my other class doesnt contain a main method.How can I get the other class to initiate the code below which is loacted in my main class.
public static String escapeDN(String name) { StringBuilder sb = new StringBuilder(); // space or # character at the beginning of a string if ((name.length() > 0) && ((name.charAt(0) == ' ') || (name.charAt(0) == '#'))) {
I have this program, I am wondering if it is possible to call files from the main method and sort them into my saveOneRocord method? If so, how would that look?
I am trying to make a 2d graphical animation using the java swing classes in order to make a frame. I had a basic version working when all of the code was under the main method, but when I moved some into another method it broke it. With y understanding of java my code should work as I create a variable of the method containing the code and then assign the size and exit button. However this causes many problems such as my BeaconFrame method informing me that it is unused when I have used it. Here is my code:
import javax.swing.*; import java.awt.*; public class BelishaBeacon { public void BeaconFrame() { JFrame frame = new JFrame(); JPanel panel1 = new JPanel();
For reference I am programming Java in BlueJ. I am fairly new to the language and I am having trouble with sorting.
I am trying to call / test all of the 5 sorting methods (at the same time) in the main class. To be specific, the sorted list has to technically outputted 5 times.
I figured out how to call / test Quicksort:
Sorting.quickSort(friends, 0, friends.length-1);
But the others are not working correctly. Specifically these:
For reference, this is the output when it is not sorted:
Smith, John 610-555-7384 Barnes, Sarah215-555-3827 Riley, Mark 733-555-2969 Getz, Laura 663-555-3984 Smith, Larry464-555-3489 Phelps, Frank322-555-2284 Grant, Marsha243-555-2837
This is the output when it is sorted:
Barnes, Sarah215-555-3827 Getz, Laura 663-555-3984 Grant, Marsha243-555-2837 Phelps, Frank322-555-2284 Riley, Mark 733-555-2969 Smith, John 610-555-7384 Smith, Larry464-555-3489
This is the class Sorting, which I should note is all correct:
public class Sorting{ /** * Swaps to elements in an array. Used by various sorting algorithms. * * @param data the array in which the elements are swapped * @param index1 the index of the first element to be swapped * @param index2 the index of the second element to be swapped */ private static <T extends Comparable<? super T>> void swap(T[] data, int index1, int index2){ T temp = data[index1]; data[index1] = data[index2];
[Code]...
This is the Main class in which I am supposed to call the sorting methods, SortPhoneList:
public class SortPhoneList{ /** * Creates an array of Contact objects, sorts them, then prints * them. */ public static void main (String[] args){ Contact[] friends = new Contact[7]; friends[0] = new Contact ("John", "Smith", "610-555-7384"); friends[1] = new Contact ("Sarah", "Barnes", "215-555-3827");
public Unit(String code, String name) { enrolStudent(student); this.unitCode = code; this.unitName = name; } public void enrolStudent(Student newStudent){ students = new ArrayList<Student>(); newStudent = new Student(24662496, "Kingsley", " Iwunze"); students.add(newStudent); }
how can I call this enrolStudent() method on this Unit constructor in another class when I create a new Unit. all I need is to enroll students in units when units are created. below is my create unit method.
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've been trying to get a card generator working, but hells bells nothing is easy in java (unless you already the correct answer) trying to figure out the correct way to apply a method you don't understand is like being asked for the German word for banana in Spanish class.
import java.util.Random; import java.util.Scanner; class jacktest { public static void main ( String[] args ) { Random r = new Random();
[code]....
my next step might be using object (hammer >=computer)=watch telly instead.
I'm creating a card game and I'm having trouble getting a card gif to display. A card is drawn from an 52 card deck arraylist, and I then need to match that drawn card with the similarly named gif in an arraylist of card gifs, to display the gif on a card GUI. I have put my game, card, deck and graphical class below:
Card - public class Card { public String number; public String suit; public Card(String n, String s) { number = n; suit = s;
[Code] ....
The arrayList of card gifs (which contains all 52 gifs for the cards) is in the graphical class and my arrayList that contains the deck of cards in textual form (that I've imported from a textfile) is in deck. The names of the gifs in the gif arraylist are the same as the card names in my textual card arraylist (for example, 3h.gif is 3h in my card arraylist), so I believe I can use a .equals statement to match the card that has been drawn to the gif.
Here is what the gifs look like in their folder, which is an arraylist in my graphical class :
Here is what the drawn card looks like after the textual card arraylist has been shuffled:
The brown card in that image isn't the displayed card that has been drawn, it's just a graphical deck that I put in, I can't get the card that has been drawn on the GUI to display on the actual card frame, as you can see.
I am making the card game War, I have gotten fairly far without a huge snag but I have been working on this. I need to compare 2 cards to find the larger of the 2. I have a function that will do that, but it is comparing the wrong numbers. The function is comparing their index values but I need it to compare the card value. The card value is found at rank(card).
I'm trying to create a program that will be able to generate random Bingo cards. This is what I have so far.
Java Code:
import java.util.Random; public class BingoCard { private int[][] card;
public BingoCard(Random random) { card = new int[5][5]; for (int c = 0; c < 5; c++)
[code]...
The problem with this program is that even with the checkForDuplicateValues method, which checks for duplicate values of a column and replaces the values, it still prints out bingo cards with duplicate values!
I am facing with a JAVA code needed for my assignment.We are implementing a Card Game.. There is a Card Class which i have not included in the code below .We have a Dec class that has various arrays..
privateCard[] masterPack >> Is a master Pack that is initialized once and has all the 52 cards.
private Card[] cards >> Is the array that has the card values from masterPack array.
My problem is :
After I called the Deck object D1, it goes to the Deck COnstrucutor OK.It then populates the values of masterPack as per the allowmasterPack method.Then it stores the values of masterPack into cards array in the init method..I get an exception when line below is executed..
cards[pack * 52 + k]= masterPack[k];
I get a java.lang.NullPointerException error..
public class debug { public static void main(String[] args) { int pack = 1; Dec D1; D1 = new Dec(pack);
I have a table called card which got list of card ,now in my java application i got validation which what certain card to be validated e,g mastro, visa, amex etc now i have problem when i create new card its throwing error because the new card is not in the hard coded values, the new card is not affected by the validation. How to approch this ....
I'm nearing the final development stages of my first game, but have run into a problem. I've constructed 4 different levels and allow the user to select the level they want to play from a central JPanel in a Card Layout system. My problem is that once a level is completed, I can't switch the JPanel which is displayed to start the next level, since I don't know how to access the original JPanel which acts as a driver for the other panels.
What it's supposed to do: This code is supposed to see if the clicked card is selected. If it's not, select it and show the player where it can move / attack. If it is selected, then find out what card the player clicked on. If he clicked on the card that was already selected, deselect it. If he clicks on a friendly card (same playerID), then select that card. If he clicks on an enemy card (different playerID), attack that card. If he clicks on a tile, move it to that tile.
The problem: However, line 24-58 give me a bit of a problem. Right now, it works fine BECAUSE lines 46-58 are commented (which also means the unit can't move). If I uncomment those lines, the unit becomes able to move, however, lines 34-46 cease working...
Java Code:
@Override public void mouseClicked(MouseEvent e) { mainloop: for (int i = 0; i < Main.cards.size(); i++) { Card c = (Card) Main.cards.get(i); if (Card.cardSelected == null) {// Contains / Is not selected if (c.contains(e.getX(), e.getY())) { Tile.reset(); Card.reset(); Card.cardSelected = c;