> I need some java help?

I need some java help?

Posted at: 2014-12-18 
In the Pencils class

public Pencils(int number, String brandName){

this.number=number;

this.brandName=brandName;

Germs=new ArrayList();

}

Simple way to auto assign unique number:

public class Pencils {

private static int id = 1;

private int uniqueNumber;

public Pencils(String brandName) {

uniqueNumber = id++;

}

}

So now when you create Penclis using

new Penclis("brandA"); uniqueNumber will be 1

new Penclis("brandB"); uniqueNumber will be 2

new Penclis("brandC"); uniqueNumber will be 3

etc

}

using java.util.UUID, example of usage is listed.

import java.util.*;

public class Program {

public static void main(String[] args) {

Box box = new Box();

List pencils = box.getPencils();

for (Pencil pencil : pencils) {

System.out.println( pencil);

}

}

}

class Box {

private List pencils;

public Box() {

pencils = build(12, "brandname");

}

public List getPencils() {

return this.pencils;

}

private List build(int quantity, String brand) {

List pencils = new ArrayList<>();

for (int i = 0; i < quantity; i++) {

pencils.add(new Pencil(brand));

}

return pencils;

}

}

class Pencil {

private UUID number;

private String brand;

public Pencil(String brand) {

this.number = UUID.randomUUID();

this.brand = brand;

}

public UUID getNumber() {

return this.number;

}

public String getBrand() {

return this.brand;

}

@Override

public String toString() {

return String.format("ID:%s Brand:%s", getNumber().toString(), getBrand());

}

}