Using Private ArrayList Of Items?

Apr 29, 2014

It isn't messing up it just keeps making me make my arraylist static and i'm not sure why.

public class driver
{
private static ArrayList<AddItems> items;
public driver()

[Code]....

View Replies


ADVERTISEMENT

EJB / EE :: How To Search Items In ArrayList

Jan 26, 2015

I try to create a jsf project within ejb which is add new car with entering attributes listing attributes and search by make.

Add and list methods working well , but have problem of list method. I tryed many combinations (using enhanced loop, iterative loop) but i cant provide working well. Always outputText returns nothing ,when i enter attributes.

Here is ejb code for adding ,getting and listing car items :

@Stateful
public class CarsBusiness implements CarsBusinessLocal {
List<Car> cars;
public CarsBusiness() {
cars = new ArrayList<Car>();

[Code] .....

View Replies View Related

Error - ArrayList Has Private Class

Jan 30, 2015

Java Code:

import java.util.Scanner;
import java.util.ArrayList;
public class Problem1
{
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
ArrayList<String> list = new ArrayList<String>();

[Code] ....

There is an error and says that my ArrayList has private access. I can't figure out how to fix it.

The code runs but when I enter "Quit", the program just stops. The arraylist isn't printed out?

View Replies View Related

Deleting A Block Of Items From ArrayList

Jan 7, 2015

My current lesson in Java is about ArrayLists and I'm having a tough time to understand this bit of code: This exercise is concerned with the problem of deleting a block of items from an ArrayList.

public static void deleteBlock( ArrayList<String> strings, int n )
{
for ( int i = 0; i < n; i++ )
{
if ( strings.size() > 0 )
strings.remove( i );

[Code] ....

This is the output: [rosion, sion, on, n]

View Replies View Related

Using Arraylist Index And Items As Hashmap Key And Values?

Apr 6, 2014

I am working on the Kevin Bacon - 6 degrees of bacon problem. I want to take my Array List and use the index and Values that I have saved in it as the Key and Value of a Hashmap. Below is my code.

HashMap<Integer, ArrayList<String>> actors =
new HashMap<Integer, ArrayList<String>>();
ArrayList array = new ArrayList();
try (BufferedReader br = new BufferedReader(
new FileReader("actors.txt"));)

[code]...

saving each one in it's own spot. I want to use the index of each one as the key to find it in the Hashmap....

View Replies View Related

ArrayList Only Adding 1 Item When There Are Multiple Items

Oct 25, 2014

I managed to retrieve data, and set data in my own ways in which I like. But my problem is, if the file does not contain anything (fully empty), when I try to use my

set("", "");
method, it only sets the last one that is called.

Example:

set("section1", "section1Item");
set("section2", "section2Item");
set("section3", "section3Item");

Only section3 would get set, and not the others.

Otherwise, if the file contained a section already, then each section (section1, section2, section3) would get set.

Here's how I set the data to the file:

public static void set(String section, String data) {
files.openFileWriter();
files.file.delete();
reCreateFile();
String beforeItem = section + ":" + files.dataList.get(section);
if(files.hasReadData) {

[Code] ....

And here is how a retrieve the data and set them to my arraylist/hashmap:

public void getData() {
String line = null;
openFileReader();
StringBuffer sb = new StringBuffer();

[Code] ....

View Replies View Related

Counts Ticket Objects In ArrayList - Accessing Private Fields

Nov 4, 2014

I am trying to create a method for my "ticketmachine" object that counts ticket objects in an arraylist of "ticket" objects with a specified field "route". The method works if i change the field type of the ticket class to public, however according to the homework task "route" of the ticket class needs to remain a private field.

Here is my code for the method.

public int countTickets(String route) //HAD TO CHANGE Ticket class FIELD "ROUTE" TO PUBLIC!!!!
{
int index = 0; //returns the number of Ticket objects in the machine with the specified "route".
int ticketCounter = 0;
while (index < tickets.size())

[Code] ....

Is my general approach to the problem wrong? also is there a way to access a private field?

View Replies View Related

Query Database To Retrieve A Column For All Menu Items In ArrayList

Sep 5, 2014

Having trouble figuring out the code in order to find the price column for all items in a ArrayList. So far i have:

private double calculateSubtotal() {
  try {
  myConnection = DriverManager.getConnection(DATABASE_URL);
myStatement = myConnection.createStatement();
myResultSet = myStatement.executeQuery("SELECT price FROM menu");

[Code] ....

I am not sure if i am going about this the right way or not?

View Replies View Related

POS System / Printing Receipt When Items Sold - ArrayList Out Of Bound

Nov 8, 2014

Basically I am trying to make a POS system and need a way to print a receipt whether there are 1 items sold or 50. So I used a Arraylist. This is the format for the printer that is needed:

printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, " 2 200 Tx Hashi Chop Sticks" + LF);

This is what I tried to do:

ArrayList<String> receiptLine = new ArrayList<>();
public void captureSales(){
receiptLine.add("Test");
System.out.println("Size of the receipt list is: "+receiptLine.size());
System.out.println("Element at index 1: " + receiptLine.get(0));

printer.printNormal(POSPrinterConst.PTR_S_RECEIPT, " " + receiptLine.get(0) + LF);

Error:

Size of the receipt list is: 1
Element at index 1: Test
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0

View Replies View Related

ArrayList Only Adding 1 Item Even Though There Are Multiple Items (Setting Data To Files)

Oct 25, 2014

I managed to retrieve data, and set data in my own ways in which I like. But my problem is, if the file does not contain anything (fully empty), when I try to use my

set("", "");

method, it only sets the last one that is called.

Example:

set("section1", "section1Item");
set("section2", "section2Item");
set("section3", "section3Item");

Only section3 would get set, and not the others.

Otherwise, if the file contained a section already, then each section (section1, section2, section3) would get set.

Here's how I set the data to the file:

public static void set(String section, String data) {
files.openFileWriter();
files.file.delete();
reCreateFile();
String beforeItem = section + ":" + files.dataList.get(section);

[code]....

And here is how a retrieve the data and set them to my arraylist/hashmap:

public void getData() {
String line = null;
openFileReader();
StringBuffer sb = new StringBuffer();

[code]....

View Replies View Related

What Does Static Private Actually Mean

Mar 19, 2015

So I'd like to know what all the statement, not sure if it's the correct way of calling them but I'd like to know what like all of those purple-ish colored words in eclipse actually mean.Here's what I know so far, so if you can add some stuff to it or just correct me:

public - can be accessed by different classes.
private - can't be accessed by different classes.
static - adds a '.' which pretty much lets you like use methods on it? Not really sure about this one.
final - a final value of a variable meaning it couldn't and willn't change?
super - I have no clue, maybe something that has to be executed first? Not sure.
void - bassicly you don't have to use return as it doesn't return any value.
this - Uh-.. I think it has something to do with the class this keyword has been entered into, not quite sure what it does though.

I assume there are alot more but I am just not sure about these common ones, what the actually do and what's their purpose?

View Replies View Related

Using Main As Private?

Mar 25, 2014

What happened when we use main() as a private. . . . .???????

View Replies View Related

Create Own ArrayList Using Collection Without Implementing ArrayList Itself

Feb 28, 2014

I'm trying to create my own arraylist using Collection. My program doesn't do anything. Obviously, I haven't a clue.

import java.util.Collection;
import java.util.Iterator;
public class MyArrayList<T> implements java.util.Collection<T> {
private int size = 4;
private T[] mArray;
public MyArrayList(String[] args) {

[Code] ....

View Replies View Related

Private JTextField Update

Jan 22, 2015

I am creating a slot machine using eclipse. I am trying to get the "winnings" JTextField to be updated in a way so that when the random images have been selected it adds to the number that is already displayed in the JTextField as opposed to what it is doing at the minute which is just displaying how much was won on that particular spin. I am also struggling to set a code for when noting is won, nothing is added. My code is below.

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import java.util.*;
import javax.swing.Timer;

[Code] ....

View Replies View Related

Each Class Contain Private Variable

Sep 22, 2014

I'm working on a project that contains multiple classes. Each class contains and must contain only PRIVATE variables. Here's my issue. When my test code calls for a new instance of "StudentClass" as so:

StudentClass studentClass = new StudentClass(offeredClass.getClassIdNumber(),
offeredClass.getClassName(),
offeredClass.getClassroom());

The corresponding constructor won't let me initialize it's variables because they are declared private within another class, as shown here:

StudentClass (float classIdNumber, String className, Classroom room){
this.classIdNumber = classIdNumber;
this.className = className;
this.room = room;
}

When getClassName, getClassroom, and getClassIdNumber are passed to a toString() method elsewhere in my test code. the output is returned just fine. When passed through the StudentClass, I'm getting Null across the board.

View Replies View Related

Inheritance And Private Methods

Jul 6, 2014

The first is clear , new Person().printPerson(); displays Person but for the second : new Student().printPerson(); it accesses the Student constructor that points to the Person class => object. It builds the Person instance then goes back to the Student constuctor .Both methods are private and to my knowledge invisible one to the other , except that you cant run the the Person one because it's private so the only one in the Student class is the Student one . Guess it 's incorrect , but why ? (is because private methods cant be overriden and somehow the super class one always has priority ? , even if it's private?)

public class Test {
public static void main(String[] args) {
new Person().printPerson();
new Student().printPerson();

[code]....

View Replies View Related

Access Private Member

May 7, 2014

public class StudentNumber {
/*
public StudentNumber(){
System.out.println("test");
}
*/
private char c='W';
public StudentNumber(float i){
System.out.println(i);

[Code] ....

Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - c has private access in extention.pkgsuper.StudentNumber
at extention.pkgsuper.ExtentionSuper.main

I did cast type. So what's the problem?

View Replies View Related

Java - Private Arrays / Integers?

Jan 16, 2015

I have a project for a class where I'm supposed to be something with private arrays and private integers and I still don't understand the point of private anything within java. if I want to change a variable I'll change it. if I want it to stay the same I'll leave it the same. so what point is all this private/public nonsense unless I'm trying to stop hackers or something?

View Replies View Related

Private Variables In Class / Constructor

Jan 7, 2014

When creating a class with a constructor, why does one have to create private variables (attributes) to be used as parameters by the object? The object's parameters will be set to be exactly equal to the private variables (attributes), so what is the point of having the private variables (attributes) Why are both private variables (attributes) and parameters needed when they are set to be equal each other anyway?

View Replies View Related

Does Encapsulation Mean That Variables By Default Need To Be Private

Apr 9, 2015

I just recently started learning about encapsulation, how to set variables private and only accessible to other classes through setters() and getters(). I've seen a couple of programming examples, perhaps not enough but some from here, and I sort of built the assumption that by default all variables need to be private. to make things more clear, here's a card dealer I made which simply

1- generates a fulll deck of 52 cards
2- lets user decide how many players, with 5 as Max number allowed as each player is dealt 10 cards.
3- deal cards

I approached this by making A deck , card , player and game class

import java.util.ArrayList;
public class Deck {
//an Object of this Class would generate a full deck ie an ArrayList of 52 Cards
private String[] suits={"Spades","Diamond","Clubs","Hearts"};
private int[] number={1,2,3,4,5,6,7,8,9,10,11,12,13};
ArrayList<Cards> deck= new ArrayList<Cards>();

[code]....

I can understand why for example Deck class's suit and number arrays are set to private , as they only need to be accessed by this class only. however, both the Deck class's deck arraylist and the Player class arraylist are not private, as I need to transfer these values from one to the other and it felt to me that setting them to private would make it more difficult to deal with them, but what I did instead is to set the Game class dealCard(), which is the only method that have access to them as private. does this achieve the same effect or do I need to set both of these arrayList to private?a follow up question, this is more related to the actual card dealer program, in this code

private void dealCards(){

for(int x = 0 ; x < playerCount ; x++){
for(int y = 0 ; y < 10; y++){
playerList.get(x).pile.add(deck.deck.get(0));
deck.deck.remove(0);
}
}
}

is there an API in ArrayList class that moves(adds to receiver and remove from giver) element across ArrayLists?

View Replies View Related

Accessing Private From Driver Class

May 14, 2015

I came across the below

1) When a variables are declared "Private" How should it be accessed from the driver class ? Sometimes i get an error in driver class saying "your variable is declared Private" why am I getting this error ...

The document says "Private" declared variables should be accessed only through methods. What does that mean.

View Replies View Related

Cannot Access Field Even Though It Is Declared As Private?

Jul 9, 2014

I think the following code should trigger a compiler error.

public final class IPoint3D {
private double x;
private double y;
private double z;
public IPoint3D(double x, double y, double z)

[Code] .....

View Replies View Related

Encapsulation Hide Private Variable

Sep 10, 2014

As below code showing that you cannot directly access the private variable as i understood,  
 
public class EncapsulationDemo{   private int ssn;  
private String empName;   private int empAge;   //Getter and Setter methods  
public int getEmpSSN(){   return ssn;   }  
public String getEmpName(){   return empName;  

[Code] .....

View Replies View Related

JSP :: How To Iterate Over Supplied Items

Mar 11, 2014

I facing issue with nested <c:forEach in my jsp page.I am using jstl.jar..Here is my code

in JAVA I have -->
List<ProductDefViewBean> productList = new ArrayList<ProductDefViewBean>();
productList.add(objProductDefViewBean);
request.setAttribute("ProductList", productList);
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>

[code]...

javax.servlet.jsp.JspTagException: Don't know how to iterate over supplied "items" in <forEach>

View Replies View Related

Adding Items To The Game

Jan 4, 2015

I made my items class and I am storing my item as a String array to list them all and what I want to be able to do is type pickup, have the game read my location and display the items that are avaible to pickup at current location then type the item and store it in my playerInventory. Then, have it check the slot if it is doesn't equal null go to next.

Use a boolean value of 0 = false and 1 = true. then, have it check if the inv array = 1 or 0. if 1 go to next inv. If all are full then, ask player if they would like to replace an item. Use a 2d array for storage for slots and true or false value.

Here is my code

Player.java
package com.PenguinGaming;
import java.util.Random;
import java.util.Scanner;
public class Player {
public void User(){
Commands commands = new Commands();
Map map = new Map();

[Code] .....

View Replies View Related

How Can Items Be Added To List

Feb 13, 2014

I have the following code. how can items be added to that list?

private List<IComponentNode> comp;
interface IAAAView {
  // returns component with given code or null
  IComponentNode findComp(String a);
  // returns component with given renderer or null

[Code] .....

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved