JAVA 11
Main.java Guest on 20th September 2022 09:33:10 PM
  1. package lab3;
  2.         import java.util.*;  
  3.         public class Main
  4.         {
  5.                 public static void main(String[] args) {
  6.                        
  7.                         try (//taking inputs like name, price from the user
  8.                         Scanner sc = new Scanner(System.in)) {
  9.                                 System.out.print("Enter your name: ");  
  10.                                 String user_name = sc.nextLine();
  11.                                
  12.                                 System.out.print("Enter the item's weight in ounces: ");  
  13.                                 float items_weight= sc.nextInt();  
  14.                                
  15.                                 System.out.print("Enter the price per pound: ");  
  16.                                 float price = sc.nextFloat();
  17.                                
  18.                                 //calculating weight_in_pound
  19.                                 float weight_in_pound = items_weight/16;
  20.                                
  21.                                 //calculating total_price
  22.                                 float total_amt = price*weight_in_pound;
  23.                                
  24.                                 //replacing spaces in names with dot .
  25.                                 user_name = user_name.replace(" ", ".");
  26.                                
  27.                                 //generating random confirmation code
  28.                                 Random random = new Random();
  29.                                 int random_num = random.nextInt(90) + 10;
  30.  
  31.  
  32.                                
  33.                                 //printing the results
  34.                                 System.out.println("\n\n\\\\\\"+"Welcome "+user_name+"///");
  35.                                 System.out.println("=================================");
  36.                                 System.out.println("Unit price:     "+String.format("%.2f",price)+" per pound");
  37.                                 System.out.println("Weight:         "+String.format("%.2f",weight_in_pound)+" pounds");
  38.                                 System.out.println("=================================");
  39.                                 System.out.println("Toatl:         "+String.format("%.2f",total_amt));
  40.                                 System.out.println("\n\nconfirmation code: "+random_num);
  41.                         }
  42.         }
  43.  
  44. }

Paste is for source code and general debugging text.

Login or Register to edit, delete and keep track of your pastes and more.

Raw Paste

Login or Register to edit or fork this paste. It's free.