Solved

Arrays in Java

Posted on 2006-11-22
11
189 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 16

Expert Comment

by:suprapto45
Comment Utility
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 24

Expert Comment

by:sciuriware
Comment Utility
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
Comment Utility
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
Comment Utility
SamsonChung,
I gave that answer to you in another question.

;JOOP!
0
 
LVL 6

Expert Comment

by:SamsonChung
Comment Utility
What answer?

for which one?

LOL..
0
 
LVL 24

Expert Comment

by:sciuriware
Comment Utility
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

762 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now