From ea92053d827b7daaefdf3319ba3a74516fffe25c Mon Sep 17 00:00:00 2001 From: Pradeep Dhupar Date: Tue, 12 Dec 2023 20:23:28 +0530 Subject: [PATCH 1/2] Assignment Completed --- Problem Statement 1.java | 29 ++++++++++++ Problem Statement 2.java | 97 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 126 insertions(+) create mode 100644 Problem Statement 1.java create mode 100644 Problem Statement 2.java diff --git a/Problem Statement 1.java b/Problem Statement 1.java new file mode 100644 index 0000000..b1c7705 --- /dev/null +++ b/Problem Statement 1.java @@ -0,0 +1,29 @@ +public class MathOperation { + int integerValue; + double doubleValue; + String stringValue; + + public void printCalculatedSum(int number1, int number2) { + int sum = number1 + number2; + System.out.println("Sum: " + sum); + } + + public void printStringIntoUppercase(String oldString) { + String uppercaseString = oldString.toUpperCase(); + System.out.println("String: " + uppercaseString); + } +} + +public class MainProgram { + public static void main(String[] args) { + MathOperation mathOperation = new MathOperation(); + + mathOperation.integerValue = 10; + mathOperation.doubleValue = 20.5; + mathOperation.stringValue = "hello"; + + mathOperation.printCalculatedSum(mathOperation.integerValue, 5); + + mathOperation.printStringIntoUppercase("world"); + } +} diff --git a/Problem Statement 2.java b/Problem Statement 2.java new file mode 100644 index 0000000..d722c40 --- /dev/null +++ b/Problem Statement 2.java @@ -0,0 +1,97 @@ +import java.util.ArrayList; +import java.util.List; +import java.util.Scanner; + +class Product { + private String name; + private double price; + private int quantity; + + public Product(String name, double price, int quantity) { + this.name = name; + this.price = price; + this.quantity = quantity; + } + + public String getName() { + return name; + } + + public double getPrice() { + return price; + } + + public int getQuantity() { + return quantity; + } + + public void setQuantity(int newQuantity) { + this.quantity = newQuantity; + } +} + +class InventoryManager { + private List productList; + + public InventoryManager() { + this.productList = new ArrayList<>(); + } + + public void addProduct(Product product) { + productList.add(product); + } + + public List getInventory() { + return productList; + } +} + +public class InventorySystem { + public static void main(String[] args) { + InventoryManager inventoryManager = new InventoryManager(); + Scanner scanner = new Scanner(System.in); + + while (true) { + System.out.println("\nInventory Management System"); + System.out.println("1. Add Product"); + System.out.println("2. Display Inventory"); + System.out.println("3. Exit"); + System.out.print("Enter your choice: "); + + int choice = scanner.nextInt(); + + switch (choice) { + case 1: + System.out.print("Enter product name: "); + String productName = scanner.next(); + System.out.print("Enter product price: "); + double productPrice = scanner.nextDouble(); + System.out.print("Enter product quantity: "); + int productQuantity = scanner.nextInt(); + + Product newProduct = new Product(productName, productPrice, productQuantity); + inventoryManager.addProduct(newProduct); + + System.out.println("Product added successfully!"); + break; + + case 2: + System.out.println("\nCurrent Inventory:"); + List products = inventoryManager.getInventory(); + for (Product product : products) { + System.out.println("Name: " + product.getName() + + ", Price: $" + product.getPrice() + + ", Quantity: " + product.getQuantity()); + } + break; + + case 3: + System.out.println("Exiting program. Goodbye!"); + System.exit(0); + + default: + System.out.println("Invalid choice. Please enter a valid option."); + } + } + } +} From a880b60b8757c576eb281d6259f667ad33b3e5a0 Mon Sep 17 00:00:00 2001 From: PradeepITT <148972812+PradeepITT@users.noreply.github.com> Date: Wed, 20 Dec 2023 12:14:57 +0530 Subject: [PATCH 2/2] Update Problem Statement 1.java --- Problem Statement 1.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Problem Statement 1.java b/Problem Statement 1.java index b1c7705..d592d47 100644 --- a/Problem Statement 1.java +++ b/Problem Statement 1.java @@ -1,7 +1,7 @@ public class MathOperation { - int integerValue; + int firstNumber; double doubleValue; - String stringValue; + String text; public void printCalculatedSum(int number1, int number2) { int sum = number1 + number2; @@ -18,11 +18,11 @@ public class MainProgram { public static void main(String[] args) { MathOperation mathOperation = new MathOperation(); - mathOperation.integerValue = 10; + mathOperation.firstNumber = 10; mathOperation.doubleValue = 20.5; - mathOperation.stringValue = "hello"; + mathOperation.text = "hello"; - mathOperation.printCalculatedSum(mathOperation.integerValue, 5); + mathOperation.printCalculatedSum(mathOperation.firstNumber, 5); mathOperation.printStringIntoUppercase("world"); }