Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Can you rewrite this Java code in the Swift programming language? I don't need the shopping cart class that is referenced to be converted, just
Can you rewrite this Java code in the Swift programming language? I don't need the shopping cart class that is referenced to be converted, just the code in the image.
1 import java.text.NumberFormat; 2 import java.util.Scanner; 4 /IA Java program that illustrates the use of: 5 // various data types, control structures, I/O (scanner), import, arrays, number formatting, 6 // use of multiple classes, etc. 7 8 public class GoShopping2 { 9 10 public static void main (String[] args) 12 Scanner sc; String str; int qty; String name; double pr; Shoppingcart myCart = new Shoppingcart(); // get a new cart object NumberFormat fmt NumberFormat.getCurrencyInstance(); // this shows how to format currency; see below 14 15 16 18 19 20 23 24 25 26 27 28 29 30 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")); System.out.println("Please pay "fmt.format (myCart.getTotalPrice())); // display in the proper currency 32 34Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started