Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Arrays in Java

Posted on 2006-11-22
11
Medium Priority
?
236 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 1000 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 1000 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

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…
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 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…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Suggested Courses

636 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