`Konnte den Hauptklassenfehler in Java mit Eclipse keinen Fehler in Java finden oder ladenJava

Java-Forum
Anonymous
 `Konnte den Hauptklassenfehler in Java mit Eclipse keinen Fehler in Java finden oder laden

Post by Anonymous »

Ich habe eine Befehlszeilenanwendung, die ein grundlegendes Online-Einzelhandel oder ein E-Commerce-System simuliert. Es ermöglicht Benutzern, über textbasierte Eingaben mit dem System zu interagieren, um Bestellungen zu ergeben, das Inventar zu überprüfen und (auf sehr grundlegend) Kundenkonten zu verwalten. /> Inventarverwaltung: Verfolgung der Verfügbarkeit von Produkten.

Code: Select all

package com.example.retail;

import com.example.retail.order.OrderProcessor;
import com.example.retail.inventory.InventoryManager;
import com.example.retail.customer.CustomerAccountService;
import com.example.retail.payment.PaymentGatewayService;
import com.example.retail.shipping.ShippingService;
import java.util.Scanner;

public class RetailApplication {

public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
InventoryManager inventoryManager = new InventoryManager();
CustomerAccountService customerAccountService = new CustomerAccountService();
PaymentGatewayService paymentGatewayService = new PaymentGatewayService();
ShippingService shippingService = new ShippingService();
OrderProcessor orderProcessor = new OrderProcessor(inventoryManager, customerAccountService, paymentGatewayService, shippingService);

System.out.println("Welcome to the Retail Application!");

while (true) {
System.out.println("\nOptions:");
System.out.println("1. Place Order");
System.out.println("2. Check Inventory");
System.out.println("3. Manage Customer Account");
System.out.println("4. Exit");

System.out.print("Enter your choice: ");
String choice = scanner.nextLine();

try {
switch (choice) {
case "1":
orderProcessor.processOrder(scanner);
break;
case "2":
inventoryManager.displayInventory();
break;
case "3":
customerAccountService.manageAccount(scanner);
break;
case "4":
System.out.println("Exiting Retail Application. Goodbye!");
return;
default:
System.out.println("Invalid choice.  Please try again.");
}
} catch (Exception e) {
System.err.println("An error occurred: " + e.getMessage());
}
}
}
}

package com.example.retail.order;

import com.example.retail.inventory.InventoryManager;
import com.example.retail.customer.CustomerAccountService;
import com.example.retail.payment.PaymentGatewayService;
import com.example.retail.shipping.ShippingService;
import java.util.Scanner;

public class OrderProcessor {
private final InventoryManager inventoryManager;
private final CustomerAccountService customerAccountService;
private final PaymentGatewayService paymentGatewayService;
private final ShippingService shippingService;

public OrderProcessor(InventoryManager inventoryManager, CustomerAccountService customerAccountService, PaymentGatewayService paymentGatewayService, ShippingService shippingService) {
this.inventoryManager = inventoryManager;
this.customerAccountService = customerAccountService;
this.paymentGatewayService = paymentGatewayService;
this.shippingService = shippingService;
}

public void processOrder(Scanner scanner) {
System.out.println("Processing Order...");
System.out.print("Enter customer ID: ");
String customerId = scanner.nextLine();
if (!customerAccountService.isValidCustomer(customerId)) {
System.out.println("Invalid customer ID.");
return;
}

System.out.print("Enter product ID: ");
String productId = scanner.nextLine();
System.out.print("Enter quantity: ");
int quantity = Integer.parseInt(scanner.nextLine());

if (!inventoryManager.checkInventory(productId, quantity)) {
System.out.println("Insufficient stock for product " + productId);
return;
}

double totalPrice = calculatePrice(productId, quantity);
System.out.println("Total price: $" + totalPrice);

System.out.print("Enter payment information: ");
String paymentInfo = scanner.nextLine();
if (!paymentGatewayService.processPayment(customerId, totalPrice, paymentInfo)) {
System.out.println("Payment failed.");
return;
}

if (shippingService.scheduleShipping(customerId, productId, quantity)) {
inventoryManager.updateInventory(productId, quantity);
System.out.println("Order placed successfully.  Shipping scheduled.");
} else {
System.out.println("Shipping scheduling failed.");
}
}

private double calculatePrice(String productId, int quantity) {
return quantity * 19.99;
}
}

package com.example.retail.inventory;

import java.util.HashMap;
import java.util.Map;

public class InventoryManager {
private final Map inventory = new HashMap();

public InventoryManager() {
inventory.put("PRODUCT001", 100);
inventory.put("PRODUCT002", 50);
inventory.put("PRODUCT003", 75);
}

public boolean checkInventory(String productId, int quantity) {
return inventory.containsKey(productId) && inventory.get(productId) >= quantity;
}

public void updateInventory(String productId, int quantity) {
inventory.put(productId, inventory.get(productId) - quantity);
}

public void displayInventory() {
System.out.println("Current Inventory:");
for (Map.Entry entry : inventory.entrySet()) {
System.out.println(entry.getKey() + ": " + entry.getValue());
}
}
}

package com.example.retail.customer;

import java.util.Scanner;

public class CustomerAccountService {
public boolean isValidCustomer(String customerId) {
return customerId != null && customerId.startsWith("CUST");
}

public void manageAccount(Scanner scanner) {
System.out.println("Customer Account Management (Simulated):");
System.out.println("Functionality to manage customer accounts is not implemented in this example.");
}
}

package com.example.retail.payment;

public class PaymentGatewayService {
public boolean processPayment(String customerId, double amount, String paymentInfo) {
System.out.println("Processing Payment (Simulated): $" + amount + " from customer " + customerId);
return true;
}
}

package com.example.retail.shipping;

public class ShippingService {
public boolean scheduleShipping(String customerId, String productId, int quantity) {
System.out.println("Scheduling Shipping (Simulated) for customer " + customerId + ", product " + productId + ", quantity " + quantity);
return true;
}
}
Wenn ich versuche, mit Javac Com/Beispiel/im Einzelhandel/im Einzelhandel zu laufen.

Code: Select all

C:\Users\compiler> javac com/example/retail/RetailApplication.java

Error: Could not find or load main class RetailApplication
Caused by: java.lang.ClassNotFoundException: RetailApplication

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post