Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can you rewrite this Java code in the Swift programming language? 1 import java.text.NumberFormat; 2 import java.util.Scanner; 4 /IA Java program that illustrates the use

Can you rewrite this Java code in the Swift programming language?

image text in transcribed

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 34

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions