Posts

Showing posts from September, 2024

Product Calculation

// INCLUDING TAX WITH PRODUCT CALCULATION// import java.util.Scanner; public class TaxCalculator { public static void main(String[] args)  { Scanner scanner = new Scanner(System.in);          // Define the tax rate (for example, 7% tax rate) final double TAX_RATE = 0.07; // Get the product name from the user System.out.print("Enter the product name: "); String productName = scanner.nextLine();          // Get the product amount from the user System.out.print("Enter the product amount: "); double amount = scanner.nextDouble();          // Calculate the tax double tax = amount * TAX_RATE;           // Calculate the total amount including tax double totalAmount = amount + tax;          // Display the result System.out.printf("Product: %s%n", productName); System.out.printf("Amount: $%.2f%n", amount); System.out.printf("Tax (7%%): $%.2f%n", tax); System.out.print...

FILE OPERATIONS

 import java.io.*; import java.util.Scanner; class FS {  public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String fileName = "java.txt"; int choice; do { System.out.println("\nFile Operations Menu:"); System.out.println("1. Create a File"); System.out.println("2. Write to the File"); System.out.println("3. Read from the File"); System.out.println("4. Update the File"); System.out.println("5. Delete the File"); System.out.print("Enter your choice: "); choice = scanner.nextInt(); scanner.nextLine(); switch (choice) { case 1:       createFile(fileName);       break; case 2:       System.out.print("Enter content to write: ");       String content = scanner.nextLine();        writeToFile(fileName, content);        break; case 3:        readFromFile(fileName);        break; case 4:         ...