Question: convert the following to swift code import java.text. Number Format; import java.util.Scanner; // A Java program that illustrates the use of: // various data types,

convert the following to swift code

convert the following to swift code import java.text. Number Format; import java.util.Scanner;

import java.text. Number Format; import java.util.Scanner; // A Java program that illustrates the use of: // various data types, control structures, I/O (scanner), import, arrays, number formatting, // use of multiple classes, etc. public class Go Shopping2 { public static void main(String[] args) { Scanner sc; String str; int qty; String name; double pr; ShoppingCart myCart = new ShoppingCart(); // get a new cart object Number Format fmt = Number Format.getCurrency Instance(); // this shows how to format currency; see below do { System.out.println("Enter the name, price, and quantity of the item"); sc = new Scanner(System.in); // get a scanner object to scan input from the standard input name = sc.next(); // get the name pr = Double.parseDouble(sc.next(); // get the price (remember to convert) qty = Integer.parseInt(sc.next(); // get the qty (remember to convert) myCart.addToCart(name, pr, qty); System.out.println(myCart); System.out.println("Do you wish to continue (y)?"); str = sc.next(); } while(str.equalsIgnoreCase("y")); sc.close(); System.out.println("Please pay + fmt.format(myCart.getTotalPrice()); // display in the proper currency } } import java.text. Number Format; import java.util.Scanner; // A Java program that illustrates the use of: // various data types, control structures, I/O (scanner), import, arrays, number formatting, // use of multiple classes, etc. public class Go Shopping2 { public static void main(String[] args) { Scanner sc; String str; int qty; String name; double pr; ShoppingCart myCart = new ShoppingCart(); // get a new cart object Number Format fmt = Number Format.getCurrency Instance(); // this shows how to format currency; see below do { System.out.println("Enter the name, price, and quantity of the item"); sc = new Scanner(System.in); // get a scanner object to scan input from the standard input name = sc.next(); // get the name pr = Double.parseDouble(sc.next(); // get the price (remember to convert) qty = Integer.parseInt(sc.next(); // get the qty (remember to convert) myCart.addToCart(name, pr, qty); System.out.println(myCart); System.out.println("Do you wish to continue (y)?"); str = sc.next(); } while(str.equalsIgnoreCase("y")); sc.close(); System.out.println("Please pay + fmt.format(myCart.getTotalPrice()); // display in the proper currency } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!