Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Arrays in Java

Posted on 2006-11-22
11
216 Views
Last Modified: 2010-03-31
Hi I’m bit confused about the array system. Could anyone help me, How to create an array system which, we can enter multiple items. For example an inventory system which hold more than one information per product. How to create it and how to display it? (Just in dos mode to understand the system)

Like a class named as computer
Serial number     - string         default:??????
Model                 - string         default: Unknown
Laptop                - Boolean      default: false
Year purchased    - integer       default: -1
0
Comment
Question by:mysiva
  • 4
  • 2
  • 2
  • +1
11 Comments
 
LVL 16

Accepted Solution

by:
suprapto45 earned 250 total points
ID: 18001358
You create the JavaBean for that and put it into a kind like ArrayList or etc.

public class Computer {
    private String serialNumber;
    private String model;
    private boolean laptop;
    private int yearPurchased;
   
public String getSerialNumber() {
    return this.serialNumber;
}
public void setSerialNumber(String serialNumber) {
    this.serialNumber = serialNumber;
}
public String getModel() {
    return this.model;
}
public void setModel(String model) {
    this.model = model;
}
public boolean getLaptop() {
    return this.laptop;
}
public void setLaptop(boolean laptop) {
    this.laptop = laptop;
}
public int getYearPurchased() {
    return this.yearPurchased;
}
public void setYearPurchased(int yearPurchased) {
    this.yearPurchased = yearPurchased;
}

}

Then later, you can use it like

ArrayList arr = new ArrayList();
Computer c1 = new Computer();
c1.setSerialNumber("SerNumber");
c1.setModel("Model");

arr.add(c1);
0
 

Author Comment

by:mysiva
ID: 18001405
Could you please write the full code, thus I can see how it’s works; and develop it more
0
 
LVL 24

Assisted Solution

by:sciuriware
sciuriware earned 250 total points
ID: 18001428
Make that:

    ArrayList<Computer> arr = new ArrayList<Computer>();  // Java 5 !

Other options:

     1) Give 'Computer' a full constructor :

            Computer u = new Computer(serial, model, false, 2006);

     2) Use an array sometimes:

            Computer[] list = new Computer[1000];

;JOOP!
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 16

Expert Comment

by:suprapto45
ID: 18001432
How if you post your current codes / progress?

I may need to go for meeting and will be back in few hours time

David
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 18001434
mysiva, that was almost the full code.
If that was enough (all the answers), first take a basic course in JAVA.

;JOOP!
0
 
LVL 6

Expert Comment

by:SamsonChung
ID: 18003120
LOL Sciuriware......

btw,

you can always do this

Object arrayName[4];

arrayName[1] = new Integer();
arrayName[2] = new String;
.....

That'd be customized arrays... (i think it works...)

but use a class.. its much easier.
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 18003236
SamsonChung,
I gave that answer to you in another question.

;JOOP!
0
 
LVL 6

Expert Comment

by:SamsonChung
ID: 18003427
What answer?

for which one?

LOL..
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 18003492
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Unhandled exception type Exception 18 42
by zero exception 10 52
jsp login check 12 42
Fast way to search item into Java Array (Rhino compatible) 2 31
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
The viewer will learn how to implement Singleton Design Pattern in Java.

791 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question