Solved

Arrays in Java

Posted on 2006-11-22
11
231 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
[X]
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
  • 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

688 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