Buenas tardes, como hago para ingresar en una matriz los datos de un objeto de otra clase ne java
//esta es mi clase objeto
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package momentovalorativo_2;
import java.util.Random;
/** * * @author Hormiguin */ public class Producto {
private double cantidad; private String descripción; private int id; private double precio;
public Producto(int id, String descripción, double cantidad, double precio)//constructor { this.cantidad = cantidad; this.descripcion = descripción; this.id = id; this.precio = precio; }
public double getCantidad() { Random rd = new Random(); cantidad = rd.nextInt(100);//se le asigna valor aleatorio a la variable return cantidad; }
public void setCantidad(double cantidad) { this.cantidad = cantidad; }
public String getDescripcion() { Random rd = new Random(); descripción = ("Producto " + rd.nextInt(100)); return descripción; }
public void setDescripcion(String descripción) { this.descripcion = descripción; }
public int getId() { Random rd = new Random(); id = rd.nextInt(100); return id; }
public void setId(int id) { this.id = id; }
public double getPrecio() { Random rd = new Random(); precio = rd.nextInt(100000); return precio; }
public void setPrecio(double precio) { this.precio = precio; }
public double valor() { return precio * cantidad; }
@Override public String toString() { return String.format("Sucrsal: \n\t" + "ID %d Descripción %es Precio %,.2f " + "Cantidad %,.2f valor %,.2f "); } }
// en esta otra clase debo llenar la matriz con los datos del producto
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package momentovalorativo_2;
import java.util.Random;
/** * * */ public class Productos { private int categorías=10; private int sucursales=10; private Producto productos [][];
public Productos(int categorías, int sucursales) {//constructor this.categorias = categorías; this.sucursales = sucursales; //productos=new Producto [categorías][sucursales]; fill(); } private void fill() { //Producto pro =new Producto(categorías, null, categorías, categorías); //Random rd=new Random(); for (int i = 0; i < 5; i++) { for (int j = 0; j < 10; j++) { productos[j] =; } } } @Override public String toString() { String aux = ""; for (int i = 0; i < 10; i++) { for (int j = 0; j <5; j++) { aux += String.format("%5d", productos[j]); } aux += "\n"; } return aux; } }
//gracias