Trying To Initialize Arrays - Assigning Variables
Apr 1, 2014
I'm making a card game and have a class I used to assign all my card variables.
However, it's giving me multiple errors and I can't seem to be able to access the variables from my other classes.
Java Code:
package com.summoners.Screen;
class Cards {
public static String[] names;
name = new String[1000];
atk = new int[1000];
[Code] .....
View Replies
ADVERTISEMENT
Feb 14, 2015
The problem is to figure out the number of cartons needed to box up the strawberries picked by the farmer and his wife. The farmer picks 8.4 lbs per hour and the wife pick 10.8 pounds per hour. They pick from 8 am until 4Pm (8 hours). You can put 20 pounds per box.I understand the word problem and how to declare and initialize variables. I'm just confused how to display the math into java to solve it.
View Replies
View Related
Jun 13, 2014
I am able to get output from my constructor when I place a loop inside of it. However when I try to access the private variable that I thought was set by the constructor I get nothing. When I check its size it is zero as well.
Java Code:
public class WinningHand extends PokerCalculator {
private int p1Size;
private int p2Size;
private String[] p1Hand = new String[p1Size];
private String[] p2Hand = new String[p2Size];
[Code] ....
View Replies
View Related
Oct 3, 2014
Write a program OutCircle.java that declares and initializes three floating-point variables (r, x, y): the first variable represents the radius r of a circle centered at (0,0) and the second and third variables are the coordinates (x, y) of a point in the plane.Your program should print true if the point is outside the circle and false otherwise. Hint: A point is outside the circle when its distance to the center is greater than the radius.
View Replies
View Related
Jul 17, 2014
I have an requirement of splitting a Date-Time String i.e. 2013/07/26 07:05:36 As you observe the above string has Date and Time with space in between them.
Now I want just want split the string not by delimiter but by length i.e. after 10th place and then assign it to 2 variable i.e. Date <----2013/07/26 and Time <---07:05:36 separately.
View Replies
View Related
Apr 7, 2014
So like, in lua programming language you can do things like,
Array = {1, 2, 3, abc = 5, efg = {123, 456, 789, hij = {"tests","works!"}}, hij = true}
Array[1] = 5
Array[3] = true
Can you do atleast something like this in java or?
I would like to do this because if let's say I was making a game, I could define what tiles are passable and which are not and then their location or something, so like this:
//p (passable) stands for if possible to walk on
//c stands for tile image
t = ["grass.png","water.png","chest.png"]
Tiles = [
[p = false, c = t[1], x = 3, y = -2 ],
[p = true, c = t[0], x = 4, y = 3 ],
[Code] ....
Or something...
View Replies
View Related
Jan 17, 2015
I used the string split method in the following lines of code like this:
String[] numbers = out.split("[^d.]", 0);
String[] operations = out.split("[.d()]", 0);
When out is equal to the String "2x2.5", the array operations ends up looking like this when it is printed using the toString method:
[, , , x]
As you can see, before the array element x, there are three String variables which only contain whitespace. Why does this occur, and how can I prevent this from happening?
View Replies
View Related
Jun 16, 2014
while (gamesPlayed<gameQty) {
userChoice = JOptionPane.showInputDialog("Rock, Paper, or Scissors?");
//Determine winner for each game
if (compChoice.equalsIgnoreCase(userChoice));
[Code] ....
It seems to circle through the loop gameQty times, without comparing.
View Replies
View Related
May 2, 2015
I'm working on a program where the user inputs song information (name, artist, filesize, duration) which is stored in a database. Once the user adds a song, the details should be stored in the first empty song slot (4 song slots total) and then taken back to the menu interface.
What I'm having trouble with is that I can add the first song fine (song1), but when I try to add another song, the information entered into song1 is gone. I've worked out that this is because every time I call upon the addNewSong() method, I'm creating four Song objects that are brand new with the line:
Song song1 = new Song();
Song song2 = new Song();
Song song3 = new Song();
Song song4 = new Song();
How to fix this problem is where I'm stuck because if I move these lines elsewhere, I get a 'cannot find symbol - variable song1' error.
Here is my code:
public class SongDatabase {
Scanner console = new Scanner(System.in);
public void addNewSong() {
Song song1 = new Song();
Song song2 = new Song();
Song song3 = new Song();
Song song4 = new Song();
if (song1.isEmpty()) {
[code]....
View Replies
View Related
Apr 29, 2014
What's up with this. Just trying to test my hands on java packages, and had this error(by java) after successful compilation:
Error occurred during initialization of VM
java.lang.Error: Properties init: Could not determine current working directory.
at java.lang.System.initProperties(Native Method)
at java.lang.System.initializeSystemClass(System.java :1119)
Main.java
package com.aceix.simplecalc;
import com.aceix.simplecalc.inputhandler.InputHandler;
import com.aceix.simplecalc.mathoperation.MathOperation;
public class Main {
public static void main(String[] args) {
[Code] ....
Any suitable way to accept input from console.
View Replies
View Related
Nov 13, 2014
Write a program to input a person''s age and salary, if the age is over 32, add $100 if otherwise subtract $500 from salary, finally output the age and new salary here is my code. I am getting a red line underneath the word 'salary' and i would like to know why and why i have to initialize it. and this is what i have tried.
</Scanner scan = new Scanner (System.in);/>
</int age, sum, difference, old_salary, new_salary, salary;/>
</System.out.println("Please enter the person age");/>
</age = scan.nextInt();/>
[code]....
View Replies
View Related
Mar 19, 2015
What is happening in below mentioned java code. Why in method insert, int l, int w is declaring & it is assigning to length & width.
class Rectangle{
int length;
int width;
void insert(int l,int w){
length=l;
width=w;
[Code] ....
View Replies
View Related
Aug 10, 2014
initialize the min and max to be the first numbers entered, need to improve the code, because if the number entered is < 0 there is an error. but i dont understand how i would initialize to the first number entered, my understanding is tha if the user enters a 5 , then i should initialize to value 5, but i cant anticipate what the user will enter. I could initializa to null, but that still is not the first number entered.
int min = 0;
int max = 0;
int option = JOptionPane.YES_OPTION;
while ( option == JOptionPane.YES_OPTION){
[code]....
View Replies
View Related
Sep 22, 2014
Trying to make me understand when to initialize a string 'null' and when not..??
View Replies
View Related
Jan 9, 2015
In my JSP I need to retrieve some data from MySQL. I need to assign a "email" variable to the "WHERE" clause. The variable is retrieved from the session attribute. So far, I have this code:
<sql:query dataSource="${user}" var="result">
SELECT * from users where email = ${sessionScope.email};
</sql:query>
It doesn't work.
View Replies
View Related
Oct 16, 2014
import java.util.Scanner;
public class Try{
static String name;
static int age;
static Scanner a = new Scanner(System.in);
static Scanner b = new Scanner(System.in);
static Scanner c = new Scanner(System.in);
public Try(String name, int age){
[Code] ....
I was trying to make a program that asks the user to create a person or a group of persons and assign names and age to them. So I made a constractor "Try" and a method "AskUser".in AskUser() I use a do/while loop where user is asked to input a name, an age and if he likes to create another person. Now how do I take the input data each time the loop runs, and send it to constractor to create new objects with it? And how these new objects will be called?
View Replies
View Related
Apr 27, 2014
I have a program that using one JFrame which opens one of two JDialog windows depending on which button is pressed.
How do I assign listeners to the buttons and fields on the JDialog window? I added listeners on the View end, but how do I process them? I tried adding the '..implements ActionListener" class in the main Controller but it does not recognize/hear anything.
View Replies
View Related
Feb 13, 2014
I tried this:
String[][]f = new String[1][1] {{"Harry"}{"Hairy"}};
I also tried this:
String[][]f = new String[1][1] {{"Harry"},{"Hairy"}};
but I get an error
View Replies
View Related
Apr 7, 2014
I have been asked to write a library program that will keep record of books and the year it was published. The program should ask the user how many rows he wants accept the string input from the user and display them in rows and columns. This is how i code it
package multidimension;
import java.util.Scanner;
public class bookrecords {
public static void main(String[]args){
//declaring a scanner variable
Scanner input =new Scanner(System.in);
[code]....
View Replies
View Related
May 27, 2014
I have a txtfile which I read and go through. My question is what are the ways I could do to read a txtfile of words and assign an empty score to each of the word in it. So each word will have a 0 value. Later on I will manipulate the score but for now I want each word to have a 0 score.What I have at the moment is reading a text file full of words eg:
private void readtextfile() {
try {
Scanner rd = new Scanner(
new File("filename"));
List<String> lines = new ArrayList<String>();
while (sc.hasNextLine()) {
lines.add(sc.nextLine());
[code]...
how to make each of the words to have a score of zero 0?
View Replies
View Related
Apr 23, 2014
If you write
byte b = 100; it works (implicit conversion of implicit int literal 100 to byte.
But if you have a methodvoid bla(byte b){}
And want to invoke it with a literal (which is an int by default):bla(8) then there is no implicit conversion.
Is the byte b = 100; just an exception in Java? And is it the rule that one has to explicitely cast (narrow) integer literals when passing to smaller-than-int types?
View Replies
View Related
Apr 24, 2015
I am looping through data in Android, using Parse data. I came up with this as a way to get user information; the larger goal is to create a model of data that I can use in an array adapter, so I can create a custom list view (as described here [URL] .... In the example, the data are hard-coded, not pulled from a database.
public static ArrayList<Midwifefirm> getUsers() {
//Parse data to get users
ParseQuery<ParseUser> query = ParseUser.getQuery();
query.orderByAscending(ParseConstants.KEY_PRACTICE_NAME);
query.findInBackground(new FindCallback<ParseUser>() {
[Code] ....
The intention is that for every user that does not have the type patient, collect this data about them, then store it in the arrayList.
On the return statement, though, there is an error: cannot return a value from a method with a void return type.
I may be over complicating this...read through various sources to get a model for this...in the end, I want to display a list of information about specific users, after the user makes a selection of a city...it would therefore display all the information about the medical practices in that city.
View Replies
View Related
Jun 28, 2014
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.
View Replies
View Related
Aug 18, 2014
Write a program to initialize and display variable size array.
View Replies
View Related
May 20, 2014
After this problem is fixed, my math game will run. The answer variable is supposed to be equal to the cases in the second switch statement by random but I get errors whenever I try to initialize it this way. I have been writing this program for almost 5 days now and it is finally wrapping up. Why I can't map the answer variable to the second switch statement the way I want to?
package pkgnew;
import java.util.Scanner;
import java.util.Random;
public class New {
public static void main(String args[]) {
//Declare and construct variables
Random randomnum = new Random();
int fnum, snum, answer;
[Code] .....
View Replies
View Related
Sep 9, 2014
I'm trying to make an array of objects, which I then initialize using objects that I have already created. I have main class, a secondary "Other" class, and a third "Other2" class. In the first Other class, I create three objects of the Other2 class, an object array of the type Other2 , and I then try to add the three objects to the object array, which results in the errors:cannot find symbol: class objectArray, ] expected, identifier expected
here is my code:
Other class
public class Other
{
Other2 object1 = new Other2();
Other2 object2 = new Other2();
Other2 object3 = new Other2();
[code]....
View Replies
View Related