diff --git a/README.md b/README.md index 44540b9..20239d6 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,318 @@ -### تمرین سری پنجم +#Address +import java.util.Scanner; -### با توجه به توضیحات موجود در فولدر first کلاسهای مربوطه را پیاده سازی کرده و به کمک مثال مطرح شده کد خود را تست کنید. +class Address { + private double latitude; + private double longitude; + private String written_address; -### ضروری است ابتدا ریپازیتوری را فورک کنید، سپس با کلون کردن و ساختن یک برنچ جدید به صورت لوکال کد مورد نیاز را به ریپازیتوری اضافه کنید. + public Address(double latitude, double longitude, String written_address) { + this.latitude = latitude; + this.longitude = longitude; + this.written_address = written_address; + } -### سعی کنید در هر مرحله تغییرات خود را کامیت کنید و در نهایت پس از اطمینان از درستی عملکرد کد خود با پوش کردن روی برنچ ساخته شده در صفحه خودتان آن را از حالت لوکال به شکل گلوبال روی گیت دربیاورید. + public double getdistance_from(Address address) { + double earthRadius = 6371; + double lat1 = Math.toRadians(this.latitude); + double lon1 = Math.toRadians(this.longitude); + double lat2 = Math.toRadians(address.latitude); + double lon2 = Math.toRadians(address.longitude); -### در نهایت با ارسال پول ریکوئست به صفحه تمرین کد شما تصحیح خواهد شد. + double dLat = lat2 - lat1; + double dLon = lon2 - lon1; -### ددلاین تمرین تا روز یکشنبه 9 اردیبهشت 1403 ساعت 11.5 صبح می باشد. -### موفق باشید :) + double a = Math.pow(Math.sin(dLat / 2), 2) + + Math.cos(lat1) * Math.cos(lat2) * + Math.pow(Math.sin(dLon / 2), 2); + + double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); + + return earthRadius * c; + } + + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + + System.out.println("Enter the latitude of the first address:"); + double lat1 = scanner.nextDouble(); + System.out.println("Enter the longitude of the first address:"); + double lon1 = scanner.nextDouble(); + scanner.nextLine(); + System.out.println("Enter the written address of the first address:"); + String writtenAddress1 = scanner.nextLine(); + + Address address1 = new Address(lat1, lon1, writtenAddress1); + + System.out.println("Enter the latitude of the second address:"); + double lat2 = scanner.nextDouble(); + System.out.println("Enter the longitude of the second address:"); + double lon2 = scanner.nextDouble(); + scanner.nextLine(); + System.out.println("Enter the written address of the second address:"); + String writtenAddress2 = scanner.nextLine(); + + Address address2 = new Address(lat2, lon2, writtenAddress2); + + double distance = address1.getdistance_from(address2); + System.out.println("The distance between the two addresses is: " + distance + " kilometers"); +scanner.close(); + } +} + +#Customer +import java.util.Scanner; + +class Customer { + private static int customerCounter = 0; + private int customerNumber; + private String name; + private Address address; + + public Customer(String name, Address address) { + this.customerNumber = ++customerCounter; + this.name = name; + this.address = address; + } + + public int getCustomerNumber() { + return customerNumber; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Address getAddress() { + return address; + } + + public void setAddress(Address address) { + this.address = address; + } + + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + + System.out.println("Enter the name of the customer:"); + String name = scanner.nextLine(); + + System.out.println("Enter the latitude of the customer's address:"); + double latitude = scanner.nextDouble(); + System.out.println("Enter the longitude of the customer's address:"); + double longitude = scanner.nextDouble(); + scanner.nextLine(); + System.out.println("Enter the written address of the customer:"); + String writtenAddress = scanner.nextLine(); + + Address customerAddress = new Address(latitude, longitude, writtenAddress); + Customer customer = new Customer(name, customerAddress); + + System.out.println("Customer number: " + customer.getCustomerNumber()); + System.out.println("Customer name: " + customer.getName()); + System.out.println("Customer address: " + customer.getAddress().getdistance_from(customer.getAddress())); +scanner.close(); + } +} + +#food +import java.util.Vector; +import java.util.Scanner; + +class Food { + private static Vector menu = new Vector<>(); + private String name; + private int price; + + public Food(String name, int price) { + this.name = name; + this.price = price; + menu.add(this); + } + + public String getName() { + return name; + } + + public int getPrice() { + return price; + } + + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + + System.out.println("Enter the name of the food:"); + String foodName = scanner.nextLine(); + + System.out.println("Enter the price of the food:"); + int foodPrice = scanner.nextInt(); + scanner.nextLine(); + + Food food = new Food(foodName, foodPrice); + + System.out.println("Food added to the menu:"); + System.out.println("Name: " + food.getName()); + System.out.println("Price: " + food.getPrice()); + + System.out.println("\nMenu:"); + for (Food f : menu) { + System.out.println("Name: " + f.getName() + ", Price: " + f.getPrice()); + } + + scanner.close(); + } +} + +#Invoice +import java.util.ArrayList; +import java.util.Scanner; + +class Invoice { + private Customer customer; + private ArrayList items; + private int state; + private static final float tax_rate = 9.4f; + + public Invoice(Customer customer) { + this.customer = customer; + this.items = new ArrayList<>(); + this.state = -1; + } + + public boolean addItem(Item item) { + if (state != -1) { + return false; + } + + items.add(item); + return true; + } + + public boolean removeItem(Item item) { + if (state != -1 && items.contains(item)) { + items.remove(item); + return true; + } else { + return false; + } + } + + public void nextStage() { + state++; + } + + public int getTotalPrice() { + int total = 0; + for (Item item : items) { + total += item.getFood().getPrice() * item.getCount(); + } + total += Math.round(total * tax_rate / 100); + return total; + } + + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + + System.out.println("Enter customer name:"); + String customerName = scanner.nextLine(); + + System.out.println("Enter customer address:"); + String customerAddress = scanner.nextLine(); + Address address = new Address(0.0, 0.0, customerAddress); + Customer customer = new Customer(customerName, address); + Invoice invoice = new Invoice(customer); + + System.out.println("Customer: " + invoice.customer.getName() + " - " + invoice.customer.getAddress()); + + System.out.println("Adding items to the invoice:"); + System.out.println("Enter the name of the food:"); + String foodName = scanner.nextLine(); + System.out.println("Enter the price of the food:"); + int foodPrice = scanner.nextInt(); + scanner.nextLine(); + Food food = new Food(foodName, foodPrice); + + System.out.println("Enter the count of the item:"); + int count = scanner.nextInt(); + scanner.nextLine(); + + System.out.println("Enter the description of the item:"); + String description = scanner.nextLine(); + + Item item = new Item(food, count, description); + boolean added = invoice.addItem(item); + + if (added) { + System.out.println("Item added to the invoice successfully."); + } else { + System.out.println("Item could not be added to the invoice."); + } + + System.out.println("Total price of the invoice (including tax): $" + invoice.getTotalPrice()); + + scanner.close(); + } +} + +#Item +import java.util.Scanner; +import java.util.Vector; + + +class Item { + private Food food; + private int count; + private String description; + + public Item(Food food, int count, String description) { + this.food = food; + this.count = count; + this.description = description; + } + + public Food getFood() { + return food; + } + + public int getCount() { + return count; + } + + public String getDescription() { + return description; + } + + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + + System.out.println("Enter the name of the food:"); + String foodName = scanner.nextLine(); + + System.out.println("Enter the price of the food:"); + int foodPrice = scanner.nextInt(); + scanner.nextLine(); + + Food food = new Food(foodName, foodPrice); + + System.out.println("Enter the count of the item:"); + int count = scanner.nextInt(); + scanner.nextLine(); + + System.out.println("Enter the description of the item:"); + String description = scanner.nextLine(); + + Item item = new Item(food, count, description); + + System.out.println("Item details:"); + System.out.println("Food: " + item.getFood().getName()); + System.out.println("Price: " + item.getFood().getPrice()); + System.out.println("Count: " + item.getCount()); + System.out.println("Description: " + item.getDescription()); + + scanner.close(); + } +}