How To Assign Values To Object
Apr 25, 2015
simple assignment of values to a previously initialized object?
See the method useModel ()
The idea is, assign the values to the temporary object, data
Then plunk it into this statement:
model.addRow ( data );
Simple enough?
I've been putzing with the syntax for multiple hours, over days, now.
With and without
[0];,
Netbeans keeps giving me: Illegal start of expression data is declared as an array of Object, although, in this case, it does not need to be an array. What is the correct syntax?
Java Code: //--
import java.awt.BorderLayout;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Date;
import javax.swing.JFrame;
[Code]....
View Replies
ADVERTISEMENT
Apr 27, 2015
This code currently just prints out the memory for the objects. What I am doing that it obviously wrong?
import java.util.ArrayList;
import java.util.List;
public class deck extends Card {
public final String[] SUITS = { "Heart", "Diamond", "Clubs", "Spade" };
ArrayList<Card> deck = new ArrayList<Card>();
[Code] .....
View Replies
View Related
Apr 25, 2014
Can I assign multiple values to one variable? For example I want myNum = 0 thru 9 you see im trying to program a password checker program to verify that the password meets all the criteria 8 char long, 1 upper case, 1 lower case, 1 numeric, 1 special, and don't contain and or end
View Replies
View Related
Apr 13, 2014
i am trying to assign unique values to nodes read from XML file.. eg: consider this XML file:
<breakfast_menu>
<food>
<name>Belgian Waffles</name>
<price>$5.95</price>
<description> ...Strong Belgian waffles...</description>
<calories>650</calories>
[code]....
now assigning these nodes "a unique value" has to be done following the LSDX labelling pattern i.e:
To the document element we first give an “a”.As there is no parent node for the document element, we assign “0” at the front of that “a” . “0a” is the unique code for the document element (breakfast_menu). For the children nodes of “0a”, we continue with the next level of the XML tree which is “1” then the code of its parent node which is “a” and a concatenation “.” . We then add a letter “b” for the first child, letter “c” for the second child, “d” for the third child and so on.Unique codes for children nodes of “0a” shall be “1a.b”, “1a.c”, “1a.d”, etc.Hence foe the above given XML the mapping would look something like this:
0a breakfast_menu
1a.b food
2ab.b name
2ab.c price
2ab.d description
2ab.e calories
2ab.f chef
3abf.b chef1
3abf.c chef2
1a.c food
2ac.b name
2ac.c price
2ac.d description
2ac.e calories
2ac.f chef
3acf.b chef1
3acf.c chef2
For more samples about LSDX labelling : 1.) Section 3.1 LSDX Labelling on this link: [URL]
2.) Fig 3 on page 1189 on this link:[URL]
right now i am using SAX parser to read xml and get the nodes in their hierarchical order..now the problem is that i have to assign these specific value to their respective nodes using java.
View Replies
View Related
Feb 7, 2015
I am trying to create an empty array that has no assigned length as the amount of elements it needs to hold will be dependent on another value. I then want to use a while loop to assign values to it. Here is an example of what im looking for it doesnt work. Iam trying to do:
int x = 12;
int i = 1;
int k = 0;
int[] factors = {}
while (i<x) {
if (x%i==0) {
factors[k] = i;
k++;
i++;
View Replies
View Related
Jul 12, 2014
I've been referencing my text and a few other sites to assist in building this class...and I'm still uncertain of the purpose of a few of the methds: next(), hasNext().
Also, I have not found a clear explanation of the following code example: tail.next = tail; There are several instances of this in the code below....I'm just not sure exactly how this assigns the value to the next object in the other class..?? ??
public class MySinglyLinkedList<T> implements SinglyLinkedList<T>{
protected NodeList<T> head, tail, current, newNode;
String name;
int size = 0;
public MySinglyLinkedList(){
head = null;
tail = null;
[Code]...
View Replies
View Related
Apr 3, 2015
I'm trying to build a monopoly like game, and atm I'm trying to find way how to build the Community and Chance chest cards. so far, my logic is
1-create an ArrayList of cards with a given order
2-for a given number of times(for loop) generate 2 random numbers ,which will be the parameters for Collection.swap().
3-swap.
here's the code for the shuffler Button
shuffler.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
for(int i=0;i<shuffeledMessages.length;i++){
int randoma=(int)(Math.random()*4);
int randomb=(int)(Math.random()*4);
Collections.swap(myMessages,randoma,randomb);
}
}
});
For now things seem to work pretty ok, but I'm wondering if this is a good and efficient way to shuffle a card chest especially in case of large number of cards. plus, I'm not sure what would be a good loop count for effective shuffling, in my case I used i<arraylist.size
View Replies
View Related
Apr 16, 2014
Started learning about Array's I'm doing an exercise where you create a for loop that randomly assigns values to each element within the array, but where is my code going wrong?
import java.util.Scanner;
public class ArrayExamples{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
double exampleArray[] = new double[5];
System.out.print("Enter a Number: ");
int num1 = input.nextInt();
[Code] .....
View Replies
View Related
Dec 16, 2014
I am writing a program for a game. It is between the user and a virtual player. The game starts with a pool of consecutive integers 1-100. The size of the pool is based on a random generated number at the beginning of the game. At the start, both players' scores are 0. For each turn, the player picks one number from the pool. That value is added to the player's score, the computer gets the sum of all the remaining numbers in the pool that divide evenly into the player's pick. The player's pick and its divisors are then removed from the pool.
The player should be able to play the game as many times as she wants without ending the program. Instructions should appear on the screen only once at the start of the program.
For each turn, both players' current score, the current pool of numbers, and a prompt for a number to be entered should show onscreen. I have written the code until I get to the function that updates the pool of numbers after a turn.
import java.util.Scanner;
import java.util.Random;
public class SlickPick {
public static void main (String[] args){
Scanner read = new Scanner(System.in);
int []pool = new int[100];
[Code] ....
My thinking is that I need to use the binary search to find the indexes of the divisors array and then use those indexes as the start values. I'm not sure how to assign the divisors indexes to start. Do I need an array for start? Whenever I run the program, the only value missing is 3.
//Name : poolUpdate
//Description : This function modifies the contents of the pool as a result of a turn of play.
//Parameters : The pool array, the divisors array, the size, and the user's pick.
// :
//Return :
public static void poolUpdate(int[] pool, int[] divisors, int size, int pick){
int low=0;
int high=size-1;
[Code] ....
View Replies
View Related
Jul 26, 2014
I have the following code:
public class CollisionManager<T> {
private boolean collision = false;
private T mainEntity;
public <T extends Entities> void handleCollision(T mainEntity, T secondEntity){
this.mainEntity = mainEntity; // This is illegal.
}
}
Why "this.mainEntity = mainEntity" is incorrect and also show me the correct way to achieve this?
The error I am getting is "Type mismatch: cannot convert T to T"
View Replies
View Related
Aug 8, 2014
How do I retrieve values of an object?
public Software[] getSoftware(int index){
return software;}
The object is initialized and i get no errors when entering values .. but when i try to print by calling getSoftware I get :
[Ldd1318398project4.Software;@257f6796
View Replies
View Related
Feb 5, 2015
Let's pretend I'm working on an RPG. Like in all RPGs, there are items found all throughout the imaginary world. Each player and NPC can obtain an item. My question will concern those items.
In other words, I'd like to use instances of a class in multiple places of the code. Each instance will have its own, individual values of instance variables, with one obvious exception: itemQuantity should have a different value in playerInventory, npcInventory, etc. Also, I'd like a list of all items that can be found in the game. This list doesn't need itemQuantity at all.
class Items {
String itemName;
float itemWeight;
int itemQuantity;
[Code] ....
The question is: should I really make itemQuantity an instance variable of the Item class? It seems as though for each copy of the Item class I should create a separate copy with different value of itemQuantity, but that's not very efficient. Where is the error in my logic?
What's important is that there may be plenty items in a game and a player may be given power to create new items during the course of the game.
View Replies
View Related
Jan 22, 2015
first i looked at this example and understand this fine:
import java.util.ArrayList;
import java.util.Iterator;
public class Main {
[Code]....
View Replies
View Related
Mar 29, 2014
I'm working with a project there ill need to enter some values for an Object and for this i'm using JTextField. However some of the variables are of the types double, int and bool. Is there a different method of reading thees types?
for example:
double playTime = this.playTime.getText();
This won't work because playTime is of type double and .getText(); takes a String.
How will i handle this? Id rather not convert from String to Double if its possible.
View Replies
View Related
Mar 8, 2015
I have an object that has an instance of another object class as its parameter :
CombinationLock oneHundred = new CombinationLock(28,17,39);
Locker Mickey = new Locker(100, "Mickey", 3, oneHundred);
This is for a locker, which has a combination assigned to the student. Within the locker class I have the following constructor:
public Locker(int locker, String student, int numberOfBooks, CombinationLock combo) {
this.locker = locker;
this.combo = combo;
this.student = student;
this.numberOfBooks = numberOfBooks;
}
combo is the private CombinationLocker object I created within the Locker class. Do I need to pass the combo object on to the CombinationLock class? For reason, I do not comprehend, the combination password from the main class is not passing through to the CombinationLock class, and the combination values are all zero.
View Replies
View Related
Oct 30, 2014
public class Check2
{
private int red;
private int green;
private int blue;
public Check2(){
red = 0;
green = 0;
blue = 0;
[Code] .....
And when i uses it in another class named "Check" it returns zeroes :
public class Check
{
public static void main(String[] args) {
Check2 obj = new Check2(125,254,12); // the toString method should return the values i gave it here . but it shows me zeroes instead.
System.out.println("the colors are " + obj.toString());
}
}
Output : the colors are (0,0,0)
View Replies
View Related
Feb 11, 2015
So I want to write a constructor that creates a new object with the data from the array values. I don't know where to start. It's the last method in the code:
public class Measurements {
private double[] values;
private double[] newArray;
private int n; //numberofvalues
private double[] ms;
public Measurements(int max) { //constructor
[code]....
View Replies
View Related
Dec 10, 2014
This program is basically complete. It compiles and runs. It is a college course assignment that I pretty much completed but for the last part in which I'm suppose to change the values of all fields and display the modified values using a toString method. Modifying the values of the fields is where I am stuck. I don't think I need to create a new text data file to do this. The instructor only asked that all the values of fields be changed and this was the last part of the assignment so I don't think it involves creating additional ObjectOutputStream and ObjectInputStream objects. I'm getting a NullPointerException error on line 161.Here is the code. I'm also including the input data file.
//create program so that objects of class can be serialized, implements interface Serialiable
//create constructor with 4 parameters with accompanying get and set methods, Override toString method
//create text file with 5 records, create Scanner object,ObjectOutputStream, and ObjectInputStream
//create new ItemRecord object, change values of all fields in ItemRecord object using object's set methods
//modify ItemRecord object using toString method
[hightlight =Java]import java.io.Serializable;
public class ItemRecord implements Serializable
[Code] .....
This is the error message:
----jGRASP exec: java ItemRecordReport
Item Cost Quantity Description
Number
A100 $ 99.99 10 Canon PowerShot-135
A200 $149.99 50 Panasonic-Lumix T55
A300 $349.99 20 Nikon- D3200 DSRL
A400 $280.99 30 Sony- DSC-W800
A500 $ 97.99 20 Samsung- WB35F
Exception in thread "main" java.lang.NullPointerException
at ItemRecordReport.main(ItemRecordReport.java:161)
----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.
Here is the data file:
A100 99.99 10 Canon PowerShot-135
A200 149.99 50 Panasonic-Lumix T55
A300 349.99 20 Nikon- D3200 DSRL
A400 280.99 30 Sony- DSC-W800
A500 97.99 20 Samsung- WB35F
Here is the data file for the modified field values.
B100 98.00 10 ABC1010
B200 97.00 15 DEF1020
B300 96.00 10 GHI1030
B400 95.00 05 JKL1040
B500 94.00 01 MNO1050
View Replies
View Related
Apr 2, 2014
How do i take input values for TwoDPoint (which are objects) and return it back in numerical values also print them.
When i create an object in main method and pass values to my function of return type TwoDPoint,it gives error:- found int,int need TwoDPoiint,TwoDPoint.
// Here is what i tried to do:
Created class TwoDPoint that contains two fields x, y which are of type int. Defined another class TestTwoDPoint, where a main method is defined.In the main method created two TwoDPoint objects.
Then I modified the class TestTwoDPoint and add another function to it. This function takes two TwoDPoints as input and returns the TwoDPoint that is farthest from the point (0,0).
Then I added another function to TestTwoDPoint. This function takes two TwoDPoints as input and returns a new TwoDPoint whose x value is the sum of x values of the input TwoDPoint's and whose y value is the sum of the y values of the input TwoDPoint's.
class TwoDPoint {
int x = 2;
int y = 4;
}
class TestTwoDPoint {
public static void main(String args[]) {
TwoDPoint obj1 = new TwoDPoint();
System.out.println(obj1.x);
System.out.println(obj1.y);
[Code] ....
View Replies
View Related
Sep 25, 2014
I am doing an assignment where I have to find the price per square inch of a pizza, compare them and display the results. I have everything figured out with the values and stuff. Now when I have to displays the results I have to display which of the two pizzas is more favorable.
I have both values / square inch for both. and I know how to find the minimum value of the two wit the Math.min class.
My question is how can I assign the char, PIZZA A to the value that I had so I can display it in the output statement, without writing PIZZA A. It should display after the difference is calculated.
Here's my code so far.
// This programs finds the price per square inch of a pizza
import java.util.Scanner;
import java.text.DecimalFormat;
public class PizzaSquareInches {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
DecimalFormat df = new DecimalFormat("#.###");
[Code] .....
View Replies
View Related
Feb 24, 2015
//Output is:ERROR.. one of the books says, we can assign float value to int variable, but its giving error.
class floint
{
public static void main(String arg[])
{
int i;
float j=10.12f;
i=j;
System.out.println(i);
}
}
View Replies
View Related
Jan 29, 2014
Below is my first ever code. I bolded where i am getting a syntax error. Why am i getting an error here if i assigned that word to a string?
public class BeerBottleTest {
public static void main(String[] args) {
int beerNum = 99;
String bottle = "bottles";
while (beerNum > 0) {
if (beerNum == 1) {
bottle = "bottle"; }
[Code] ....
View Replies
View Related
Feb 3, 2015
I'm focusing on the player1Turn() method. When I run this and say temp = A, it says pit = 0. I don't know why this is.
import java.util.*;
public class Mancala {
Scanner input = new Scanner(System.in);
public static void main(String[]args) {
[Code] .....
View Replies
View Related
Sep 25, 2014
Im new to jsp. I have the following html in my jsp
<select name="job" id="job">
<option value="Booked">Booked</option>
<option value="Assigned">Assigned</option>
<option value="In Process">In Process</option>
<option value="Completed">Completed</option>
</select>
How do I assign job in the scriplet like how we do <% String job = request.getParameter("job")%> but on the same page? <% String job = request. getParameter("job")%> returns null value.
View Replies
View Related
May 23, 2014
Let's say I have a loop that loops through objects in an ArrayList then does stuff with them. Is it better for me to store the object in a temporary local variable and do stuff with it, or always use the ".get(arrayindex)" thing?
View Replies
View Related
Dec 15, 2014
I'm working with doubles I'm trying to figure out how to set this up so it works?
I'm just stuck on how to set and Assign a double FedTaxWitholding that gets the Fed Tax Withholding = Gross Pay * Fed
Tax Withholding Rate.
Do I need a string for Gross pay?
View Replies
View Related