رفع الملفات إلى "/"

This commit is contained in:
2025-10-11 14:53:12 +00:00
commit ba8173de25
4 changed files with 148 additions and 0 deletions
+58
View File
@@ -0,0 +1,58 @@
package com.ecommerce;
import java.util.ArrayList;
public class Customer {
// id counter used to make the id increases each time there is more customer had added
private static int idCounter = 0;
// id variable is the id
private int id;
private String name;
private ArrayList<Product> shoppingCart;
public Customer(String name){
idCounter++;
setName(name);
shoppingCart = new ArrayList<>();
id = idCounter;
}
public int getId() {
return id;
}
public String getName() {
return name;
}
public void setName(String name) {
if(isAlpha(name)) {
this.name = name;
}
}
public ArrayList<Product> getShoppingCart() {
return shoppingCart;
}
// to add the product to the customer's shopping cart
public void addToShoppingCart(Product product) {
this.shoppingCart.add(product);
}
public static boolean isAlpha(String n){
for(int i = 0; i<n.length(); i++){
if (!Character.isLetter(n.charAt(i))){
return false;
}
}
return true;
}
}
+42
View File
@@ -0,0 +1,42 @@
package com.ecommerce.orders;
import com.ecommerce.*;
import java.util.ArrayList;
public class Order {
// id variable is the id
private int id;
// id counter used to make the id increases each time there is more customer had added
private static int idCounter = 0;
private Customer customer;
private double totalAmount;
public Order(Customer customer){
idCounter++;
this.customer = customer;
this.totalAmount = calcTotal(customer.getShoppingCart());
this.id = idCounter;
}
public int getId() {
return id;
}
public Customer getCustomer() {
return customer;
}
public double getTotalAmount() {
return totalAmount;
}
// to calculate the total amount that the customer should pay
private double calcTotal(ArrayList<Product> products){
double totalAmount = 0;
for(Product i : products){
totalAmount = totalAmount + i.getPrice();
}
return totalAmount;
}
}
+44
View File
@@ -0,0 +1,44 @@
package com.ecommerce;
public class Product {
// id variable is the id
private int id;
// id counter used to make the id increases each time there is more products had added
private static int idCounter = 0;
private String name;
private double price;
public Product(String name, double price) {
idCounter++;
setName(name);
setPrice(price);
this.id = idCounter;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
if(price > 0) {
this.price = price;
}
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getId() {
return id;
}
}
+4
View File
@@ -0,0 +1,4 @@
# Simple-Online-Store
A Simple Online Store App that built with Java
Developed a simple sales management application in Java that displays the product list, allows products to be added to the shopping cart, and calculates the grand total of the invoice. The Application runs via the command line and interacts with the user using the products ID. The project reflects my skills in programming and designing small applications