I have been working with a code to simulate an e-commerce website. As I am new with java, I have tried to save some concepts by viewing information on the web. Finally I have the program. Three classes, one for products, another for the car and the application class. Everything is fine except that in the end the code does not allow entering products into the shopping cart. Why the program comes up in this part, maybe the main class is wrong? I appreciate any help you can give me.
Product.java
public class Producto {
private String categoria;
private String categoriaMarca;
public Producto(String categoria, String categoriaMarca) {
this.categoria = categoria;
this.categoriaMarca = categoriaMarca;
}
public String getCategoria() {
return categoria;
}
public String getCategoriaMarca() {
return categoriaMarca;
}
public String toString() {
return "Categoria: "+this.getCategoria() + " / Marca: " + this.getCategoriaMarca();
}
}
Carro.java
public class Carro {
private String ingreso;
public Carro(String ingreso) {
this.ingreso = ingreso;
}
public String getIngreso() {
return ingreso;
}
public String toString() {
return "Este producto " + this.getIngreso() + " ha sido ingresado al carro de compras.";
}
}
Application.java
import java.util.*;
public class Aplicacion {
public static void main(String[] arg) {
Scanner s = new Scanner(System.in);
ArrayList<Producto> catalogo = new ArrayList<Producto>();
ArrayList<Carro> ingreso = new ArrayList<Carro>();
int productos = 1;
int contador = 0;
String cat, catMarca;
String resp1, resp2, resp3, resp4;
for(int i=0; i<2; i++) {
System.out.println("Escriba la categoría del producto: ");
cat = s.next();
System.out.println("Ingrese el producto: ");
catMarca = s.next();
catalogo.add(new Producto(cat, catMarca));
}
System.out.println("Para ver el catálogo de productos, presione 0 ");
productos = s.nextInt();
if (productos == 0) {
for (int f = 0; f < catalogo.size(); f++) {
System.out.println(catalogo.get(f));
}
}
System.out.println("Deseas agregar alguno de estos productos al carro de compras?: ");
resp1 = s.next();
if (resp1 == "si" || resp1 == "SI" || resp1 == "Si") {
System.out.println("Indica el producto que deseas ingresar");
resp2 = s.next();
ingreso.add(new Carro(resp2));
System.out.println("Deseas agregar algun producto más al carro de compras?: ");
resp3 = s.next();
while (resp3 == "si" || resp1 == "SI" || resp1 == "Si") {
contador = contador + 1;
ingreso.add(new Carro(resp3));
}
}
System.out.println("Deseas ver los productos ingresados al carro de compras? ");
resp4 = s.next();
if (resp4 == "si" || resp4 == "SI" || resp4 == "Si") {
for (int h = 0; h < ingreso.size(); h++) {
System.out.println(ingreso.get(h));
}
}
}
}