Trouble inputting to an Array...

I have the following setup:
CLASS STORAGEBUSINESS
private ArrayList<Customer> storageCustomer;
// setters & getters
public void setCustomers() {
  if (storageCustomer == null)
     storageCustomer = new ArrayList<Customer>();
public ArrayList getCustomer() {
  return storageCustomer;
// This method adds a customer ...
public boolean addCustomer(Object inCustomer)
  if (inCustomer instanceof Customer)
       return getCustomer().add(inCustomer);
  else
     return false;
}CLASS INTERFACE
public void createACustomer()
  if (storageBusiness != null)
    Customer customer
     = new Customer(
                Console.readInt  ("Customer ID created: "),
                Console.readLine ("Please enter name:  "),
          Console.readLine ("Please enter address: "),
          Console.readInt  ("Please enter contact phone number: "));
                System.out.println(customer);
    if (storageBusiness.addCustomer(customer))
     System.out.println("\n Customer was added successfully");
    else
     System.out.println("\n Customer was -NOT- added");
  else
         System.out.println("Function did not perform");
}But for some reason I am not able to input into Array storageCustomer, can anyone help.

Do you mean that,
private ArrayList<Customer> storageCustomer;
public void setCustomers() {
  if (storageCustomer == null)
     storageCustomer = new ArrayList<Customer>();doesn't actually create an array (or array list). I must be way off here. What do I need to create an array? One that is created from Class Customer.

Similar Messages

  • How to test if input is in array + number?

    Hi, I have an array, [0, 1, 2], and also a stored number: 5
    If I ask the user to input a number, how do I make the user continue input until the number is either one of the numbers in the array or the stored number?
    I can do this with a while loop, a for loop, and an if, else loop, but it's too complicated:
                   boolean match = false;
                   DONE: while (match != true) {
                        for (int i =0; i < number; i++) {
                             if (userInput == array[i] || userInput == -1) {
                                  match = true;
                                  break DONE;
                             } else {
                                  match = false;
                        System.err.printf("\nERROR: Input not in array or stored number.\n\n");
                        System.out.printf("Input again:\n    ");
                        userInput = input.nextInt();
                   }Is there an easier method? Could someone point me in the right direction? I'm wondering if it might be faster if I create a new array that includes the original array + the stored number, then test to see if the input is simply in this new array.
    Thanks for any help.
    Edited by: fishy on Feb 23, 2009 11:16 AM

    Hello,
    To check the number against the array, you would have to loop through the entire array checking each element for the input value. A for loop should do the trick:
    private static int checkArray(int [] a, int inputNumber)
    for (i = 0; i < a.length; i++) { 
    if (a[i] == inputNumber)
          return 1;
    return 0;
    }Then you can use a do while for the input:
    do {
       System.out.println("Enter a number: ");
       userInput = sc.nextInt;
    } while ( (checkArray(userInput) == 0) & (number != userInput) ); This should ask the user for input as long as the number they enter is not in the array and it's not the stored number.
    Hope this helps,
    ~Vin

  • Having trouble inputting email in iCloud...

    I'm having trouble inputting my email address in iCloud. It says "Your email address must be less than 21 characters", mine is 25 characters, and I can't change it because it's a standardised work email. Can I somehow bypass this?

    Hi Csound1,
    I have tried cutting down the email to less than 21 characters and it says...
    'Your email address can only contain non-accented Roman letters, numbers, underscores (_), and periods (.)'
    I have tried everything but it won't let me set up an email address!
    Re the contacts - I have restored from my back-up then, merged with the cloud again and the same thing has happened - all my contacts have disappeared and I am left with only Apple Inc.

  • DAQ Input Signal into Array

    Hi,
    I have an input (voltage) signal comming into my DAQ assistant (6008). This information displays well into a chart, but I also want to covert the same data into array format so that I can do further calculations. So, basically I would like to put a DAQ signal into an array. I'm having a lot of trouble doing so, please help,
    thank you
    Nick

    Hello Nick,
    I can use the function "From DDT" in the Function palette Express -> Signal Manipulation.
    When you place it on the block diagram, a windows opens and you can configure: 1D Array of Scalar - Automatic.
    Best regard
    Nick_CH

  • How to call proc in package having input as accociative array

    Hi,
    I want to call a proc inside a package having input paramter as accociative array.How can it be called.?
    The signature of package is as follows
    TYPE ar_line_details_rec IS RECORD (
    mfg_part_num VARCHAR2 (100),
    description VARCHAR2 (1000),
    line_amount NUMBER (14, 2)
    TYPE ar_line_dtls_tab IS TABLE OF ar_line_details_rec
    INDEX BY BINARY_INTEGER;
    PROCEDURE dca_saf_feedback_pr (
    p_dca_id IN dca_header.dca_id%TYPE,
    p_memo_number IN dca_header.memo_number%TYPE,
    p_memo_amt IN dca_header.memo_amt%TYPE,
    p_memo_created_date IN dca_header.memo_created_date%TYPE,
    p_ar_line_dtls IN ar_line_dtls_tab,
    p_code IN NUMBER,
    p_mesg IN VARCHAR2,
    p_rtncode OUT NUMBER,
    p_rtnmessage OUT VARCHAR2
    I want to calls the proc dca_saf_feedback_pr .So can it be done?
    Thanks,
    Tanmoy

    Yes, %TYPE is not required here.
    -- If your package name is DCA_SAF_FEEDBACK_PKG & you want to pass associative array as assoc
    DECLARE
    -- declare associative array
      assoc dca_saf_feedback_pkg.ar_line_dtls_tab;
      retcode VARCHAR2(200);
      remsg   VARCHAR2(200);
    BEGIN
    -- initialize associative array
      assoc(1).mfg_part_num:=10;
      assoc(1).description :='assoc';
      assoc(1).line_amount :=1000;
    --pass associative array
      dca_saf_feedback_pkg.dca_saf_feedback_pr (
              p_dca_id =>1,
              p_memo_number => 2,
              p_memo_amt => 200,
              p_memo_created_date=> SYSDATE,
              p_ar_line_dtls =>assoc,
              p_code=> 100,
              p_mesg =>'assoc',
              p_rtncode => retcode,
              p_rtnmessage =>rmsg);
    END;Regards,
    Ankit Rathi
    http://theoraclelog.blogspot.in

  • Trouble while passing an array as a parameter to an JDBC Control

    Hi everyone, recently I have upgraded my WLS Workshop 8.1 application to WLS 10gR3 using the workshop 8.1 application upgrade but after the upgrade to beehive controls I'm having troubles in a couple of methods that receive an array as a parameter. One of the methods is the following:
    * @jc:sql array-max-length="all" max-rows="all"
    * statement::
    * select COUNT(*) FROM (
    * SELECT la.lea_gkey,la.eme_gkey
    * FROM (SELECT gkey, name, role FROM employees WHERE {sql:fn in(gkey,{emeGkeyArray})}) e,
    * lead_assignees la,
    * leads le,
    * cities ct,
    * (select lea_gkey,name,email,phone,title from contacts where principal = 'X') cn,
    * (SELECT lea_gkey, tag FROM lead_tags WHERE tag = 'TARGET') targets,
    * (SELECT lea_gkey, tag FROM lead_tags WHERE tag = 'TOP5') top5,
    * (SELECT lea_gkey, tag FROM lead_tags WHERE tag = 'TOP100') top100
    * WHERE e.gkey = la.eme_gkey
    * AND la.lea_gkey = le.gkey
    * AND le.city = ct.gkey(+)
    * AND le.gkey = cn.lea_gkey(+)
    * AND le.gkey = targets.lea_gkey(+)
    * AND le.gkey = top5.lea_gkey(+)
    * AND le.gkey = top100.lea_gkey(+)
    * {sql: whereClause}
    * UNION
    * SELECT DISTINCT la.lea_gkey,la.eme_gkey
    * FROM (SELECT gkey, name, role FROM employees WHERE {sql:fn in(gkey,{emeGkeyArray})}) e,
    * lead_assignees la,
    * shared_accounts sa,
    * leads le,
    * cities ct,
    * employees asign,
    * (select lea_gkey,name,email,phone,title from contacts where principal = 'X') cn,
    * (SELECT lea_gkey, tag FROM lead_tags WHERE tag = 'TARGET') targets,
    * (SELECT lea_gkey, tag FROM lead_tags WHERE tag = 'TOP5') top5,
    * (SELECT lea_gkey, tag FROM lead_tags WHERE tag = 'TOP100') top100
    * WHERE e.gkey = sa.eme_gkey
    * AND asign.gkey = la.eme_gkey
    * AND asign.active='X'
    * AND sa.lea_gkey = le.gkey
    * AND sa.lea_gkey = la.lea_gkey
    * AND le.city = ct.gkey(+)
    * AND le.gkey = cn.lea_gkey(+)
    * AND le.gkey = targets.lea_gkey(+)
    * AND le.gkey = top5.lea_gkey(+)
    * AND le.gkey = top100.lea_gkey(+)
    * {sql: assigneeClause}
    * UNION
    * SELECT DISTINCT la.lea_gkey,la.eme_gkey
    * FROM (SELECT gkey, name, role FROM employees WHERE {sql:fn in(gkey,{emeGkeyArray})}) e,
    * lead_assignees la,
    * shared_accounts sa,
    * leads le,
    * cities ct,
    * (select lea_gkey,name,email,phone,title from contacts where principal = 'X') cn,
    * (SELECT lea_gkey, tag FROM lead_tags WHERE tag = 'TARGET') targets,
    * (SELECT lea_gkey, tag FROM lead_tags WHERE tag = 'TOP5') top5,
    * (SELECT lea_gkey, tag FROM lead_tags WHERE tag = 'TOP100') top100
    * WHERE e.gkey = la.eme_gkey
    * AND sa.lea_gkey = le.gkey
    * AND sa.lea_gkey = la.lea_gkey
    * AND le.city = ct.gkey(+)
    * AND le.gkey = cn.lea_gkey(+)
    * AND le.gkey = targets.lea_gkey(+)
    * AND le.gkey = top5.lea_gkey(+)
    * AND le.gkey = top100.lea_gkey(+)
    * {sql: sharedClause})::
    @JdbcControl.SQL(arrayMaxLength = 0,
    maxRows = JdbcControl.MAXROWS_ALL,
    statement = "select COUNT(*) FROM ( SELECT la.lea_gkey,la.eme_gkey FROM (SELECT gkey, name, role FROM employees WHERE {sql:fn in(gkey,{emeGkeyArray})}) e, lead_assignees la, leads le, cities ct, (select lea_gkey,name,email,phone,title from contacts where principal = 'X') cn, (SELECT lea_gkey, tag FROM lead_tags WHERE tag = 'TARGET') targets, (SELECT lea_gkey, tag FROM lead_tags WHERE tag = 'TOP5') top5, (SELECT lea_gkey, tag FROM lead_tags WHERE tag = 'TOP100') top100 WHERE e.gkey = la.eme_gkey AND la.lea_gkey = le.gkey AND le.city = ct.gkey(+) AND le.gkey = cn.lea_gkey(+) AND le.gkey = targets.lea_gkey(+) AND le.gkey = top5.lea_gkey(+) AND le.gkey = top100.lea_gkey(+) {sql: whereClause} UNION SELECT DISTINCT la.lea_gkey,la.eme_gkey FROM (SELECT gkey, name, role FROM employees WHERE {sql:fn in(gkey,{emeGkeyArray})}) e, lead_assignees la, shared_accounts sa, leads le, cities ct, employees asign, (select lea_gkey,name,email,phone,title from contacts where principal = 'X') cn, (SELECT lea_gkey, tag FROM lead_tags WHERE tag = 'TARGET') targets, (SELECT lea_gkey, tag FROM lead_tags WHERE tag = 'TOP5') top5, (SELECT lea_gkey, tag FROM lead_tags WHERE tag = 'TOP100') top100 WHERE e.gkey = sa.eme_gkey AND asign.gkey = la.eme_gkey AND asign.active='X' AND sa.lea_gkey = le.gkey AND sa.lea_gkey = la.lea_gkey AND le.city = ct.gkey(+) AND le.gkey = cn.lea_gkey(+) AND le.gkey = targets.lea_gkey(+) AND le.gkey = top5.lea_gkey(+) AND le.gkey = top100.lea_gkey(+) {sql: assigneeClause} UNION SELECT DISTINCT la.lea_gkey,la.eme_gkey FROM (SELECT gkey, name, role FROM employees WHERE {sql:fn in(gkey,{emeGkeyArray})}) e, lead_assignees la, shared_accounts sa, leads le, cities ct, (select lea_gkey,name,email,phone,title from contacts where principal = 'X') cn, (SELECT lea_gkey, tag FROM lead_tags WHERE tag = 'TARGET') targets, (SELECT lea_gkey, tag FROM lead_tags WHERE tag = 'TOP5') top5, (SELECT lea_gkey, tag FROM lead_tags WHERE tag = 'TOP100') top100 WHERE e.gkey = la.eme_gkey AND sa.lea_gkey = le.gkey AND sa.lea_gkey = la.lea_gkey AND le.city = ct.gkey(+) AND le.gkey = cn.lea_gkey(+) AND le.gkey = targets.lea_gkey(+) AND le.gkey = top5.lea_gkey(+) AND le.gkey = top100.lea_gkey(+) {sql: sharedClause})")
    public Long getProspectsCount(String[] emeGkeyArray, String whereClause, String assigneeClause, String sharedClause) throws SQLException;
    The execution of the method is the following:
    pendingApprovals = leadsListingDB.getProspectsCount(employeeHierarchyArray, pendingApprovalsClause, pendingApprovalsClause, pendingApprovalsClause);
    When the method is executed all the String parameters (whereClause, assigneeClause & sharedClause) are replaced well except the array parameter (emeGkeyArray) so the execution throws the following exception because the array is not replaced:
    <Jan 20, 2010 1:01:26 PM CST> <Debug> <org.apache.beehive.controls.system.jdbc.JdbcControlImpl> <BEA-000000> <Enter: onAquire()>
    <Jan 20, 2010 1:01:26 PM CST> <Debug> <org.apache.beehive.controls.system.jdbc.JdbcControlImpl> <BEA-000000> <Enter: invoke()>
    <Jan 20, 2010 1:01:26 PM CST> <Info> <org.apache.beehive.controls.system.jdbc.JdbcControlImpl> <BEA-000000> <PreparedStatement: select COUNT(*) FROM ( SELECT la.lea_gkey,la.eme_gkey FROM (SELECT gkey, n
    me, role FROM employees WHERE (gkey IN ())) e, lead_assignees la, leads le, cities ct, (select lea_gkey,name,email,phone,title from contacts where principal = 'X') cn, (SELECT lea_gkey, tag FROM lead
    tags WHERE tag = 'TARGET') targets, (SELECT lea_gkey, tag FROM lead_tags WHERE tag = 'TOP5') top5, (SELECT lea_gkey, tag FROM lead_tags WHERE tag = 'TOP100') top100 WHERE e.gkey = la.eme_gkey AND la.l
    a_gkey = le.gkey AND le.city = ct.gkey(+) AND le.gkey = cn.lea_gkey(+) AND le.gkey = targets.lea_gkey(+) AND le.gkey = top5.lea_gkey(+) AND le.gkey = top100.lea_gkey(+) AND LA.ACTIVE = 'X' AND LE.WE
    KLY_POTENTIAL > 0 AND (LE.APPROVED IS NULL OR LE.APPROVED != 'Y') AND LA.SALE_STAGE IN(3034,3005) UNION SELECT DISTINCT la.lea_gkey,la.eme_gkey FROM (SELECT gkey, name, role FROM employees WHERE (gkey I
    ())) e, lead_assignees la, shared_accounts sa, leads le, cities ct, employees asign, (select lea_gkey,name,email,phone,title from contacts where principal = 'X') cn, (SELECT lea_gkey, tag FROM lea
    tags WHERE tag = 'TARGET') targets,  (SELECT leagkey, tag FROM lead_tags WHERE tag = 'TOP5') top5, (SELECT lea_gkey, tag FROM lead_tags WHERE tag = 'TOP100') top100 WHERE e.gkey = sa.eme_gkey AND asi
    n.gkey = la.eme_gkey AND asign.active='X' AND sa.lea_gkey = le.gkey AND sa.lea_gkey = la.lea_gkey AND le.city = ct.gkey(+) AND le.gkey = cn.lea_gkey(+) AND le.gkey = targets.lea_gkey(+) AND le.gkey
    = top5.lea_gkey(+) AND le.gkey = top100.lea_gkey(+) AND LA.ACTIVE = 'X' AND LE.WEEKLY_POTENTIAL > 0 AND (LE.APPROVED IS NULL OR LE.APPROVED != 'Y') AND LA.SALE_STAGE IN(3034,3005) UNION SELECT DISTINCT
    la.lea_gkey,la.eme_gkey FROM (SELECT gkey, name, role FROM employees WHERE (gkey IN ())) e, lead_assignees la, shared_accounts sa, leads le, cities ct, (select lea_gkey,name,email,phone,title from c
    ntacts where principal = 'X') cn, (SELECT lea_gkey, tag FROM lead_tags WHERE tag = 'TARGET') targets, (SELECT lea_gkey, tag FROM lead_tags WHERE tag = 'TOP5') top5, (SELECT lea_gkey, tag FROM lead_tags
    WHERE tag = 'TOP100') top100 WHERE e.gkey = la.eme_gkey AND sa.lea_gkey = le.gkey AND sa.lea_gkey = la.lea_gkey AND le.city = ct.gkey(+) AND le.gkey = cn.lea_gkey(+) AND le.gkey = targets.lea_gkey(+
    AND le.gkey = top5.lea_gkey(+) AND le.gkey = top100.lea_gkey(+) AND LA.ACTIVE = 'X' AND LE.WEEKLY_POTENTIAL > 0 AND (LE.APPROVED IS NULL OR LE.APPROVED != 'Y') AND LA.SALE_STAGE IN(3034,3005)) Params:
    {}>
    <Jan 20, 2010 1:01:26 PM CST> <Debug> <org.apache.beehive.netui.pageflow.FlowController> <BEA-000000> <Invoking exception handler method handleException(java.lang.Exception, ...)>
    [LeadsMailer] Unhandled exception caught in Global.app:
    java.sql.SQLSyntaxErrorException: ORA-00936: missing expression
    So the big question is if that behavior is due to a bug of I'm doing something wrong. Do someone can give me an advice about this problem because the array parameter has no problems in workshop 8.1?
    Thanks in advance!

    Greetings
    I may not have an answer for you, but i am in the same boat! I am trying to pass an array to store in the database. I have 2 out of 8 columns that need to be stored as arrays. Everything saves EXEPT for the 2 arrays in question. I am using BEEHIVE with my web app. The strange thing is that i do not receive any syntax errors or runtime codes. I am still searching for an answer. If i find anything out, i will let you know.
    John Miller
    [email protected]

  • How build a function with an array in input and another array in output

    Hi, I need to create a function, which receive in input a list of Group's name and retrieve the correspondent list of Group's id.
    So I need to have these conditions:
    1) The parameter in input has to be only one "p_user_name" (an array of values)
    2) the return parameter has to be p_user_id (array of values)
    3) in the WHERE condition p_user_name has to be used in order to retrieve the list of user_id I need
    Following, a little example:
    FUNCTION get_group_id (p_user_name IN VARCHAR2) RETURN p_user_id
    IS
    BEGIN
    SELECT group_id FROM jtf_rs_groups_vl
    WHERE group_name = p_user_name
    RETURN p_user_id;
    END get_group_id;
    I think I have to create a new type with p_user_name, but I don't know after, how to join group_name (varchar2) with p_user_name.....
    Anybody can help me to find the light ?
    Thanks in advance
    Alex

    I need to create a function, which receive in input a list of Group's name and
    retrieve the correspondent list of Group's idAt the beginning the argument "p_user_name IN VARCHAR2" is not what you need. You should create global type - nested table of varchar2 values where you
    can keep the list of names. And you also need to create nested table of numbers
    to return IDs (if you really need collection but not ref cursor !):
    SQL> select empno, ename from emp;
         EMPNO ENAME
          7369 SMITH
          7499 ALLEN
          7521 WARD
          7566 JONES
          7654 MARTIN
          7698 BLAKE
          7782 CLARK
          7788 SCOTT
          7839 KING
          7844 TURNER
          7876 ADAMS
          7900 JAMES
          7902 FORD
          7934 MILLER
    14 rows selected.
    SQL> create type d_v is table of varchar2(10);
      2  /
    Type created.
    SQL> create type d_n is table of number;
      2  /
    Type created.
    SQL> create or replace function get_ids
      2  (names d_v) return d_n
      3  is
      4   ret_ids d_n;
      5  begin
      6   select empno
      7   bulk collect into ret_ids
      8   from emp, table(names) t
      9   where ename = t.column_value;
    10   return ret_ids;
    11  end;
    12  /
    Function created.
    SQL> declare
      2   d d_n;
      3  begin
      4 
      5   d := get_ids(d_v('KING','ALLEN'));
      6 
      7   for i in 1..d.count loop
      8    dbms_output.put_line(d(i));
      9   end loop;
    10 
    11  end;
    12  /
    7839
    7499
    PL/SQL procedure successfully completed.Rgds.

  • Array output from formula node with input variable as array size

    Hi,
    I have created a formula node with an array output called al, but I get an error "you have connected a scalar type to an array with that type".
    I declare the output as follows..
    float64 al[len_as];
    where len_as is an scalar input to the formula node.
    It only works when I put a number as.
    float64 al[5];
    ,but I don't know beforehand how many elements I need, so I cannot use this.
    Please help! This is so stupid.
    Thanks

    Don't define your array in your formula node.
    Initialize the array as the size you want and pass it in as an input into the formula node.
    Are you sure you even need to use a formula node?  Can you implement your formula using all native LabVIEW functions?
    Message Edited by Ravens Fan on 10-07-2009 11:51 PM
    Attachments:
    Example_VI_BD.png ‏3 KB

  • How to plot XY graph from 2 input of dynamic array ? ...

    I have 2 problem when I plot XY graph with 2 dynamic array :
    - I want to make the graph look like sweep chart. But it's seem not possible to use waveform graph?
    - The graph shoul move from left to right , then right to left, then left to right,.....
    Any one can give me some hints?  Thanks alot.
    Attachments:
    U1.PNG ‏21 KB
    XY radom value input.vi ‏147 KB

    I have to make Y change  from 0-10, then 10-0,.... Any one can help me to make it better?
    - How I shift the graph?
    Attachments:
    working_increse_decrease.vi ‏20 KB

  • Input into 2d array table

    code is not right :( will repost.
    Edited by: jettaz on May 24, 2008 3:43 PM
    I have initialized a 14x4 array and filled it myself, while allowing the user to further input 4 more rows if he so wishes.
    The array table is 2d for an inventory, sorted by type and brand.
    try
    plainWrapString = JOptionPane.showInputDialog("Please enter Plain Wrap type:");
    brandAString = JOptionPane.showInputDialog("Enter serial for brand A:");
    brandCString = JOptionPane.showInputDialog("Enter serial for brand C:");
    brandXString = JOptionPane.showInputDialog("Enter serial for brand X:");
    for(rowsInteger = 0; rowsInteger < 14; rowsInteger++)
    if(plainWrapString.equalsIgnoreCase(inventoryArray[rowsInteger][columnInteger]))
    throw new IllegalArgumentException("Duplicate found! Please retry.");
    inventoryArray[rowsInteger][columnInteger] = plainWrapString;First of all, my try... catch statement, doesn't catch even when plainWrapString input is a copy of the already entered data in the array table. I had it working okay, though, before I attempt to get the user tp further input more data corresponding to the plainWrapString's row. I'm not sure if this works for inputting the following data according to brands.
    for (columnInteger = 0; columnInteger < 4; columnInteger ++)
    inventoryArray[rowsInteger][columnInteger] = brandAString;
    columnInteger = 0; // resets columnInteger back to zero to continue filling next
                                // column in array?
    for (columnInteger = 0; columnInteger < 4; columnInteger++)
    inventoryArray[rowsInteger][columnInteger] = brandXString;
    columnInteger = 0;
    for (columnInteger = 0; columnInteger < 4; columnInteger++)
    inventoryArray[rowsInteger][columnInteger] = brandCString;
    selectionDropMenu[rowsInteger] = plainWrapString; // something extra to add to a
                                                                               // drop menu
    catch(IllegalArgumentException error)
    JOptionPane.showMessageDialog(null, error.getMessage());
    }Any help is appreciated :)
    Edited by: jettaz on May 24, 2008 3:46 PM
    Edited by: jettaz on May 24, 2008 4:20 PM

    A HashMap would be a better way to ensure that you have unique elements. This approach will allow you to get away from using exception. I have attached two classes. I have assumed that you only want to store one type, but each type can have many brands. The types will be unique but the brands can be duplicates. The brand object counts the number of duplicate entries. An additional benefit of this approach is that you do not need to know the size of your collection before hand.
    The test class contains the main() method.
    import java.util.HashMap;
    import java.util.Iterator;
    import java.util.Set;
    import java.util.SortedSet;
    import java.util.TreeSet;
    public class TestClass{
         private HashMap<String, Brand> type = new HashMap<String, Brand>();
         public TestClass(){
         public void addTypeAndBrand(String typeName, String brandName){
              Brand b = type.get(typeName);
              if(b==null){
                   type.put(typeName, new Brand(brandName));
              }else{
                   b.addBrand(brandName);
         public void listTypeAndBrand(){
              Set<String> types = type.keySet();
              SortedSet<String> sortedTypes = new TreeSet<String>(types);
              Iterator<String> typeIter = sortedTypes.iterator();
              Brand b = null;
              String typeName = "", brandName = "";
              int frequency=0;
              while(typeIter.hasNext()){
                   typeName = typeIter.next();
                   b = type.get(typeName);
                   Set<String> brands = b.getKeys();
                   SortedSet<String> sortedBrands = new TreeSet<String>(brands);
                   Iterator<String> brandIter = sortedBrands.iterator();
                   while(brandIter.hasNext()){
                        brandName = brandIter.next();
                        frequency = b.getCount(brandName);
                        System.out.println("Type: " + typeName + ",     Brand: " + brandName + ",     Brand Count: " + frequency);
         public static void main(String[] arg){
              TestClass test = new TestClass();
              test.addTypeAndBrand("Japan", "Toyota");
              test.addTypeAndBrand("Japan", "Honda");
              test.addTypeAndBrand("Japan", "Honda");
              test.addTypeAndBrand("USA", "Ford");
              test.addTypeAndBrand("USA", "Chevy");
              test.addTypeAndBrand("USA", "Dodge");
              test.listTypeAndBrand();
    }The Brand class is:
    import java.util.HashMap;
    import java.util.Set;
    public class Brand {
         private HashMap<String, Frequency> brand = new HashMap<String, Frequency>();
         public Brand(String brandName){
              brand.put(brandName, new Frequency());
          * Add brand to HashMap. If brand does not already exist, add brand to HashMap.
          * Otherwise increment count of brand.
          * @param newBrand brand to be added to HashMap
         public void addBrand(String newBrand){
              Frequency freq = brand.get(newBrand);
              if(freq==null){
                   brand.put(newBrand, new Frequency());
              }else{
                   freq.add();
         public Set<String> getKeys(){
              return brand.keySet();
         public int getCount(String key){
              Frequency f = brand.get(key);
              return f.getFrequency();
          * Inner class for frequency counts.
         class Frequency{
              private int total;
              public Frequency(){
                   total = 1;
              public void add(){
                   total++;
              public int getFrequency(){
                   return total;
    }The output I get is:
    Type: Japan, Brand: Honda, Brand Count: 2
    Type: Japan, Brand: Toyota, Brand Count: 1
    Type: USA, Brand: Chevy, Brand Count: 1
    Type: USA, Brand: Dodge, Brand Count: 1
    Type: USA, Brand: Ford, Brand Count: 1

  • Using a scanner to interpret user input in an array

    Hi
    Does anyone know how to use an array to store user input?
    I'm a beginner in Java and I need help making an array with 5 positions that can be filed by the user as they type.
    This is needed as a guide to read up more complex user input methods. I have been told to use a "scanner" (java.util.Scanner) to do this and frankly, I'm ridiculously lacking in Java skills. Any help would mean a whole lot.
    So far, this is the scanner I've been working with:
    import java.io.*;
    import java.util.Scanner;
    import java.util.*;
    public class ReadConsole
    public static void main(String[] args)
    Scanner input = new Scanner(System.in);                                                                
    System.out.println("Menu System - Please enter your choice");
    System.out.println("Option 1");
    System.out.println("Option 2");
    System.out.println("Option 3");
    for(int i = 0; i < 1; i++){
    int num = input.nextInt();
    if(num==1){
    System.out.println("Option 6");}
    else if(num==2){
    System.out.println("Option 7");}
    else if(num==3){
    System.out.println("Option 8");}
    else{
    System.out.println("Try again");
    i = 0;
    }

    That sounds do-able, but im struggling when it comes to inputing 5 values from the user. what do i do to separate the values? i know that sounds vague, ... but if I can make one "position", why can't I make five??
    Take a look at what I've done:
    import java.io.*;
    import java.util.Scanner;
    import java.util.*;
    public class Input
    public static void main(String[] args)
    Scanner input = new Scanner(System.in);    
    System.out.println("Please select your lucky number");
    System.out.println("Options are:");
    System.out.println("1");
    System.out.println("2");
    System.out.println("3");
    System.out.println("or 4");
    for(int i = 0; i < 1; i++){
    int num = input.nextInt();
    if(num==1){
    System.out.println("Your lucky number is 1. Cool");}
    else if(num==2){
    System.out.println("Your lucky number is 2. Cool");}
    else if(num==3){
    System.out.println("Your lucky number is 3. Cool");}
    else if (num==4){
    System.out.println("Your lucky number is 4. Cool");
    //ELSE STATEMENT DOESNT COMPILE ... ((not a big deal right now))
    //else{
    //System.out.println("Start Over. You've done it all wrong");
    //i = 0;
    }okay I see that the scanner works this way, but when I copy-pasted that whole section of my code from "Scanner input = " down, it wouldn't compile at that first line.
    I had named it "Scanner input = new2 Scanner(System.in);"
    How can I make another user input position with the scanner?
    Message was edited by:
    tark_theshark

  • Trouble with sending huge arrays via DataSocket​s.

    Hi,
    I am having trouble sending huge arrays via Data Sockets from my main vi on the server PC to the vi on the client PC.
    To further elaborate, in my main vi program I have created 3 arrays called Array1, Array2 and Array3 on my front Panel. By right clicking the mouse on each set of array and from the pop-up menu I selected Data Operations-> DataSocket Connection and I entered dstp://localhost/Array1 and clicked on Publish to broadcast the data from Array1. Similarly, I did the same for Array2 and Array3.
    Now, in my client vi program I have created three arrays on my front Panel to read (Subscribe) the data from the three arrays broadcasted via DataSockets from the server’s main vi program. To subsc
    ribe the data I did the similar process above and clicked on Subscribe to read the data (of course the IP address of the client PC will be different then the server PC so enter the hosts IP address). Once the data is received in the client arrays, I am using LV2 globals so that I can use these arrays on other sub-vi’s locally (instead of having each sub-vi get data from the server directly).
    I succeeded in doing this with two arrays, however when I added the third array the DataSockets would not work consistently. For example the refresh rate would get slower at times and sometimes 2 out of the 3 arrays would update. I don’t know if I have exceeded the limit on how much data DataSockets can broadcast, but I need to have some mechanism to broadcast 6 arrays (approx. 10000 elements for each array) of double digits precision.
    Has anyone come across this issue? Is there another way of broadcasting data more efficiently then DataSockets?
    I would appreciate any
    help that I can get.
    I have attached the files for this program in the zip file.
    First run the Server main program, testServeMainVI.vi, and then the client program, testClientMainVI.vi.
    Thanks
    Nish
    Attachments:
    beta2.zip ‏70 KB

    DataSocket can be a lossy communication. I like the advice to flatten the data to a string, but another option would be to buffer the communcation. The problem might be that the data is being overwritten on the server faster than it is being read. There is an example of buffered datasocket on NI web page: http://venus.ni.com/stage/we/niepd_web_display.DIS​PLAY_EPD4?p_guid=BA3F9DFED17F62C3E034080020E74861&​p_node=DZ52000_US&p_submitted=N&p_rank=&p_answer=&​p_source=Internal
    Also, I have played with the new built in buffered datasocket in LabVIEW 7.0. It is pretty slick. If buffers the data both on the server and the client side.

  • What is the Problem in the way that I get input into an Array

    Hi Guru's,
    Im learning Java and I have written a simple program to get the input and write into an Array. The program is as follows.
    import java.util.*;
    public class ArraysSort {
         public static void main(String[] args)
              System.out.println("Enter the Number of Entries that you want to Enter");
              Scanner num = new Scanner(System.in);
              int len = num.nextInt();
              int arr[] = null;
              System.out.println(len);
              System.out.println("Enter the Numbers");
              for (int i=0;i<len;i++)
    *               *arr[i] = num.nextInt();*
              //System.out.println("The Numbers in Ascending Order are:");
              //Arrays.sort(arr);
              for (int i=0;i<arr.length;i++)
                   System.out.println(arr);
    Can anyone tell me what is wrong with the Way that I get the input. I have marked the statement in Bold for easy identification.
    Thanks a lot for all your help..

    VijaySwaminathan wrote:
    *               *arr[i] = num.nextInt();*I don't think you can just say
    int arr[] = null;and then expect it to insert? Surely first create an array like this....
    int arr[] = new int[len];

  • Putting input into an array

    I've created a java program with an array of 7 numbers. the first number indicated how many numbers will be entered.
    for ex. 6, 202, 303, 101, 303, 505, 404
    I created an array with the above examples number, and all my methods are working to compute the average, values equal to average, below average and above average.
    However, right now its not quite right because ive entered the numbers into the array manually. What i need to do is take the numbers from the input stream and enter them into the array. How do I do this? Ive been doing so much research and can't figure out how to do it/get it right.
    // shortcut, creates array manualy. need to change this to take the numbers from the standard input stream.
    int[] numbers = { 6, 202, 303, 101, 303, 505, 404};
    // position 0 holds how many numbers there are
    int howMany = 0;
    howMany = numbers[0];
    // average numbers in array
    int numHolder = 0;
    int average = 0;
    int add = 0;
    for (int i = 1; i<numbers.length; i++) {
        add = numbers[i] + add;
        average = add / howMany;
    // number of integers that is less than the average
    int lessThan = 0;
    for (int i=1; i<numbers.length; i++){
        if (numbers[i] <  average) {
            lessThan ++ ;
    // number of integers exactly equal to the average
    int equal = 0;
    for (int i=1; i<numbers.length; i++){
         if (numbers[i] ==  average) {
         equal ++ ;
    // number of integers that greater than the average
    int greaterThan = 0;   
    for (int i=1; i<numbers.length; i++){
        if (numbers[i] <  average) {
            greaterThan ++ ;
    // print the results
    System.out.println("Average Value : " + average + "\n");
    System.out.println("Number of values below the average : " + lessThan);
    System.out.println("Number of values equaling average  : " + equal);
    System.out.println("Number of values above the average : " + greaterThan + "\n");

    BufferedReader buffy = new BufferedReader(new InputStreamReader(System.in));
    String input = buffy.readLine();   
    int num = Integer.parseInt(input);
    array[somenumber] = num;You should have try/catch statements so the program does not let the client enter strings.
    Hope this helped

  • Comparing input value to array value for equality

    Hi all,
    I'm fairly new to java and I am finding this forum to be a great resource. I am learning more by seeing the problems others are having and the solutions. thanks ahead of time for the help.
    Here is my problem.
    I am using InputStreamReader and Buffered Reader to take keyboard input and add to a string ( lets call it name)
    I then search an array for a match
    for ( int i=0; i<array.length; i++
    if ( name == array[i] )
    blah blah blah
    I can compile and run but my input never matches a value I know is in the array.
    Do I need to do something to the input string to make it usable?
    Any insight would be much appreciated

    When comparing objects (including Strings) you usually want to use obj1.equals(obj2), rather than obj1 == obj2. The equals method uses semantics defined by each object to determine whether the contents are "equal". For Strings it compares the characters, for a MyEmployee class it could compare employee IDs or names, birthdates, and whatever else you decide is important.
    The == operator, when used on references (anything that's not a primitive like int, float, etc.), tests whether both references refer to the same object. In your case, name and array[j] may have the same contents, but they're stored in two different String objects, so the == test fails.
    Oh, and when you post code, use [ code ] blocks to format it, and don't use i as an array index (gives you italics) See
    http://forum.java.sun.com/faq.jsp#messageformat

Maybe you are looking for