How To Print Stored Content When Using ArrayList

Oct 5, 2014

I have a main class AddressBook where I use ArrayList<Contact> addressBook = new ArrayList<>(); to add information such as name and phone numbers in my Contact class. How do I go about accessing all the information (names, and phone numbers) that is stored in my Contact class? What happens when I print it out is it only prints out the last input of name and phone number and not the entire collection of names and phone numbers. How do I print out the contents of ArrayList?

View Replies


ADVERTISEMENT

Loaded ArrayList But Can't Retrieve Stored Values

Nov 4, 2014

I am creating a shopping list, with each element and object called product from the Item attribute class. Each product object has a description, price, and priority. From user input, I am able to create each product object, and then .add to my arraylist. I know that it successfully adds because I have it printed in each iteration of the do-while loop. Once the user indicates they want to quit, the loop ends. I then want to print each description, price, and quantity but this for loop will only print the last element over and over. Here is what I have:

ArrayList <ItemAttribute> list = new ArrayList<ItemAttribute>();
Scanner keyboard = new Scanner(System.in);
ItemAttribute product = new ItemAttribute();
public void findDescrPrice() {
/**
* Get the item name (description) for each list item

[code]...

View Replies View Related

How To Print Out All Keys Currently Stored In A HashMap

Jul 4, 2014

I want to write a method to print the all the names of a phone book. phoneBook is a HashMap<String, String> , that has names as keys and phone numbers as values.

Reading the documentation for both HashMap and Set, I have more or less an idea of how it could be done but I cant put it on code..
 
public String getName()
{
  String[] keys = phoneBook.keySet().toArray();
return keys[0];
  }

This is wrong. It doesnt compile saying incompatible types. I was thinking first to manage to succeed to get a key from my phone book and then I change it to print all the keys.

View Replies View Related

Copy Array Content To Arraylist

Apr 27, 2015

I have a text file which contains to integer values I need to retrieve for each item (total of 56 items in the file). One is an item number, the other the weight ("Item: " + number + "Weight: " + weight). I am trying to build an array list that will add each set of data to it. I know that when I add the item array to the arraylist it is storing the array variable and not its contents, so is there a way to easily copy that data array to the array list?

ArrayList newInventory = new ArrayList();
int[] item = new int[2];
while(sc.hasNext()) {
String itemVal = br.readLine();
if(sc.hasNextInt()) {
item.add(sc.nextInt());
}
}

View Replies View Related

Invoke Some Methods In For Loop In Order To Print Some Info Stored In A List

Apr 28, 2014

I am trying to invoke some methods in a for loop in order to print some info stored in a List. But for some reason, compiler pops a message saying "cannot find symbol - method getEmpID(). You are using a symbol here (a name for a variable, method or class) that has not been declared in any visible scope." But I am pretty sure that method getEmpID (as also getName(), getAfm(), and payment() ) have been declared as public.

Note: My List contains objects of different type (SalariedEmployee, HourlyEmployee). I hope this is not the factor causing this problem.

Java Code:

import java.util.*;
abstract class Employee{
private String name = "";
private String afm = "";
private long EmpID;
static long count=0;

[code]....

View Replies View Related

Swing/AWT/SWT :: How To Print JFrame Content Using NetBeans Java

Sep 10, 2014

I am developing a program in netbeans forms. I've got to a point where I will click a jButton to print the content of either JFrame or JPanel. I am using Netbeans forms to develop the project....

View Replies View Related

Create New File / Ask User To Write In It And Save Final Print Content Of File

Mar 15, 2014

1. creates a file.
2. ask user to write into that file
3. save the file
4. print content of file.

Is my current exercise, so far i have gotten the code to create a file. What should i use to ask user to write into that file and save?

package assignment7;
 
import java.io.*;
public class Exercise2
{
public static void main ( String [ ] args ) {
String filePath="newfile.txt";
File newFile = new File ( filePath ) ;

[Code] .....

View Replies View Related

Create New File / Ask User To Write In It / Save Finally Print Content Of File

Mar 17, 2014

1. creates a file.

2. ask user to write into that file

3. save the file

4. print content of file.

is my current exercise.so far i have gotten the code to create a file, and ask the user to input their age.what should i use to save what the user writes into the file?

Java Code:

package assignment7;
import java.io.*;
import java.util.*;
public class Exercise2
{
public static void main ( String [ ] args ) throws IOException
{
Scanner scan = new Scanner(System.in);

[code]....

View Replies View Related

Print Contents Of Arraylist In Object

Nov 7, 2014

i have a class that creates an object made of 2 strings and an arraylist

class Users{
private String ip;
private String userName;
private ArrayList <String>cons=new ArrayList();
Users(String i_p,String un,ArrayList con){//construc

[Code] .....

This object then gets returned to an arraylist of these objects

static ArrayList<Users>users=new ArrayList();

My question is how can i then get the arraylist from this object to print its contents?

View Replies View Related

How To Print Out All Elements Inside ArrayList

Oct 5, 2014

When this program runs it gives me

workbook.Contact@46e5590e
Number of contact: 1

The number of Contact that I input is just one when I run the program so the Number of contacts: 1 is correct, but it gives me workbook.Contact@46e5590e instead of printing out all the contacts stored inside the Contact class. Yes I do loop through the ArrayList and I also have a method inside the Contact class, the printNameAndPhone(), which prints out the name as well as the phone number but how do I incorporate the printNameAndPhone() method (located in the Contact class) inside the print() method (located inside the AddressBook class)???

Basically I'm asking how to access all the elements in the ArrayList<Contact> addressBook = new ArrayList<>();??My main class AddressBook

package addressbook;
import java.util.Scanner;
import java.util.ArrayList;
public class AddressBook {

[code]....

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

Values In Array Not Stored?

Oct 6, 2014

I just forgot to increment n while trying to store the humidity... I do this every time and I suddenly realize what I did wrong ...

My problem is that after printing humidity[n] in the "Humidity(%)" row, it seems that humidity[n] becomes 0. I checked like this:

System.out.println(humidity[5] + " " + humidity[6]);

In the "Humidity(%)" row, they come out fine, but when I do this, they come out as 0, which I think would explain why my heat indices are consistently lower than the temperature when the temperature is over 80.

My code:

import java.util.Scanner;
import java.io.File;
import java.io.IOException;
public class HeatIndex {
public static void main(String[] args) throws IOException {
System.out.printf("%70s", "Heat Index: Key West, Florida");

[Code] ......

View Replies View Related

How To Make Print Employee Button To Print Info Of Other Class

Apr 12, 2014

Basically the class is supposed to have a static variable that keeps track of the number of companies (numberOfCompanies) that have been created and a static method that returns the value of this variable. I need to have a constructor and a method to addEmployee, a method to printCompany, and a toString method. The addEmployee method will check that there is only 1 salesperson, 2 designers, and 4 manufacturing persons at a time and will check that there are no more than 7 employees of the company.

The addEmployee method will return a String indicating what the error is (i.e. "There is already a sales person in this company") or a null if the employee was added. If attempting to name a third company, an error message will be shown. what i have so far but my print company mmethod returns null company class :in which i am obliged to use inputdialog because it says that it cannot return void when i use the showmeassage diaolog.

company class:

import java.util.ArrayList;
import javax.swing.JOptionPane;
public class Company {
private ArrayList<Employees> list ;
private static int numberOfCompanies;

[Code] ....

error message when print button is clicked:

Exception in thread "AWT-EventQueue-0" java.lang.RuntimeException: JOptionPane: parentComponent does not have a valid parent
at javax.swing.JOptionPane.createInternalFrame(Unknown Source)
at javax.swing.JOptionPane.showInternalOptionDialog(Unknown Source)
at javax.swing.JOptionPane.showInternalMessageDialog(Unknown Source)

[Code] ......

View Replies View Related

Get The Value Of A Variable Stored In Another Class Of Another Package?

Nov 12, 2014

Source packages

1.First package : CarDealer.java (JFrame form)

2. Second package : Vehicle.java (JFrame form)

- The user runs CarDealer JFrame in which appears a JTexField in which he types in some characters (pretending he types some data about selling licence).
- The user clicks on the JButton "Save" that stores the characters typed in inside a String variable called strLicence.
- The user clicks on the JButton "Open 'Vehicle Form'" that opens the Vehicle JFrame.
- Finally, in the Vehicle JFrame I want to write a code that can see/use the value of the String variable called strLicence.

In other words, for example, I want to store the value of strLicence in a new variable declared in the Vehicle class.

(Actually I'm working with a long and elaborate project for the dissertation of my bachelor's degree, so, for cutting to the chase, I simplified it by creating an essential JFrame project.)

I used netbeans

1. CarDealer.java

package Firstpackage;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.JFrame;

[code]....

I also attach the netbeans project in a zip file ....

View Replies View Related

JSP :: How To Call Stored Procedure Through Code

May 29, 2014

I have a .csv file ,and I have written a jsp code which uploads csv file to a local folder . Now I want to upload that csv file to database using stored procedure. Below I have included the code which uploads the csv to database.

<%@page import="org.apache.commons.fileupload.*,java.util.*,java.io.*"%>
<%@page import="java.sql.*"%>
<!DOCTYPE HTML>
<html>
<head>
</head>
<body>
<img border="1" src="img/tss.JPG" alt="portal" />
<br><br><br><br><br><br>
<%
try{

[Code]....

View Replies View Related

Java Object Stored In Array?

Apr 8, 2014

I have been having trouble with a recent hw assignment requiring us to sort user defined data types in an array. so far, i have implemented the sorting algorithms correctly but i cant seem to store a string and an integer together. I have an employee class

[public class employee {
private String Name;
private int IdNumber;
public employee(int IdNumber,String Name){
this.Name=Name;
this.IdNumber=IdNumber;}

[Code] .....

And in my app, i create a employee object-----> employee john=new employee(1020, "John");

How can I prompt my insert method to take in employee id and string name together?

View Replies View Related

Where Are All Keywords Like Final And This Stored In Java

Jan 23, 2014

Which package or class i can find all the predefined keywords in java like "this" etc...

actually i want to know if this operator is itself final in nature or not from its syntax?

View Replies View Related

Servlets :: Why Objects Stored In Session Should Be Serializable

Feb 5, 2015

Why is it that objects stored in session object should be serializable?

View Replies View Related

Find Arithmetic Mean Of The Numbers Stored In Array

Feb 23, 2014

The program below is intended to find the arithmetic mean of the numbers stored in the array q in two ways: once by storing the numbers in an ArrayList d, where you allow all the necessary conversions to be performed automatically; and once by storing them in an ArrayList e, where you perform all the conversions by hand. Complete the program.

Here is what I have so far:

double[] q = { 0.5, 2.4, 7.4, 2.8, -6.2 };
ArrayList<Double> d = new ArrayList<Double>();
ArrayList<Double> e = new ArrayList<Double>();
for ( double x : q ) {
d.add( x );
e.add ( new Double ( x ) );

[Code] .....

Why does it still show "a / d.size?" I thought I fixed that. Whatever, it's supposed to be "dTotal / d.size()", etc.

View Replies View Related

Display PDF File Which Is Stored In MySQL Database?

Apr 2, 2015

How to display pdf file which is stored in mysql database by using jsp and servlet ....

View Replies View Related

JSF :: Upload File With Path Stored In Database?

May 20, 2014

I'm using jsf 2 to upload file, first I upload the file in a system directory, then trying to store the path to database with other information, my stuck is that when submitting I upload the file successfully, find it in the right place, find the other information such as description, file name ... in database but don't find the path. this is my managed bean :

package mbeans;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
import java.util.List;

[code]...

View Replies View Related

How To Modify Property Of Object Stored In List

Jul 31, 2014

I'm facing a problem in below scenario:

List lst = tDAO.executeReport();

lst contains list of objects and one of the objects contains the property bDate(Timestamp) which has the value 28-2-1989 00:00:00.0, now I just wants to change the value into 28-2-1989 and store it back into the List as a Timestamp. how can I do that.

View Replies View Related

Greek Characters Are Stored In MySQL Database

Oct 25, 2013

I did an application with jframe which i store member personal info like name, surname etc.But when i save it to Mysql database the values are ??????.I have changed database and table and columns collation to utf8, i checked java encoding it's utf-8 but the problem remains.i have spent hours in google search but nothing that works.

View Replies View Related

Java Stored Procedure - Connecting To 8i Database

Sep 17, 2014

I am new to Java Stored Procedures. There is a PL/SQL package in our legacy application(Oracle 9i) which pulls data from Oracle 8i source database through a DB link. Now we have upgraded our databas to Oracle 11g R2 from 9i. So the DB lint to Oracle 8i will no longer work in 11g. Hence I have created a Java stored procedure that establishes JDBC thin connection to the source 8i database. I have loaded the java stored procedure in the database using loadjava and have created a call specifaction.

I have called this java stored procedure inside the PL/SQL package. Now while executing the PL/SQL package, it takes the default driver ojdbc6.jar to establish JDBC connection and fails to connect to the 8i database giving ArrayIndexOutOfBounds Exception. While running the code in the linux application server with classes12.jar the code succeeds. But when the same is called in the database it fails.
 
1.  How can I make my PL/SQL call use classes12.jar while calling the Java Stored Procedure?
 
2. How can I load the jar file(which includes my classes and the classes12.jar) into the datase as one object? (When I tried to load the whole jar, in database the classes and dependent jar loaded separately)
 
3. Is there a way to use classpath while calling the Java Stored Procedure like how we do from Unix?

View Replies View Related

Two Threads - One Will Print Odd And Other Will Print Even Numbers In Sequence

Jul 25, 2014

I want to create two thread one thread will print odd number and another thread will print even number. but the number should be in a sequence like

1 2 3 4 5 6 7 8 9 10

View Replies View Related

Test Values Stored In 2D Arrays - Program Keeps Looping

Jan 13, 2014

I am trying to test values stored in 2d arrays once but i my program just keeps looping what am i doing wrong

Java Code:

tempi=i;
tempx=x;
for( i=0;i<3;i++) {
for( x=0;x<4;x++) {
if(rounded[i][x]<395 || rounded[i][x] >405) {
System.out.println("there is an error with probes "+rounded[i][x]);

[Code] .....

View Replies View Related







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