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?
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
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..
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.
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?
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;
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....
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);
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 {
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");
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)
- 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 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.
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?
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.
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 :
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.
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.
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?