Solved

Arrays in Java

Posted on 2006-11-22
11
210 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
ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

 
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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
oracle 11g 23 84
How to execute a Python program and gather return output in Java 2 30
jboss wildfly 10.1 10 94
Chrome and Firefox Java 5 34
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
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…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

810 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