Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

LabTask week06 Write a program that prompts the user to enter the exchange rate from currency in US dollars to Chinese RMB. Prompt the user

LabTask week06 Write a program that prompts the user to enter the exchange rate from currency in US dollars to Chinese RMB. Prompt the user to enter 0 to convert from US dollars to Chinese RMB and 1 to convert from Chinese RMB to US dollars. Prompt the user to enter the amount in US dollars or Chinese RMB to convert it to Chinese RMB or US dollars, respectively. When the user enters "1" (yuans to dollars) the program should extract the dollar amount before the decimal point, and the cents after the decimal amount using the indexOf() and substring() methods.Here are the sample runs, user's input is underlined:

 Enter the exchange rate from dollars to RMB: 6.81 Enter 0 to convert dollars to RMB and 1 vice versa: 0 Enter the dollar amount: 100 $100.0 is 681.0 yuan. Enter the exchange rate from dollars to RMB: 6.81 Enter 0 to convert dollars to RMB and 1 vice versa: 1 Enter the yuan amount: 1000 1000.0 yuan is $146.843 dollar 146 dollars 3 quarters 0 dimes 1 nickel 4 pennies 

I already have some code, which is:

import java.util.Scanner;

public class abc

{

public static void main(String[] args) {

Scanner input = new Scanner(System.in);

System.out.print("Enter the exchange rate from dollars to RMB: ");

double rate = input.nextDouble();

System.out.print("Enter 0 to convert dollars to RMB and 1 vice versa: ");

int option = input.nextInt();

double amount;

switch(option)

{

case 0: System.out.print("Enter the dollar amount: ");

amount = input.nextDouble();

System.out.println("$" + amount + " is " +

(amount*rate) + " yuan"); break;

case 1: System.out.print("Enter the RMB amount: ");

amount = input.nextDouble();

System.out.println(amount + " yuan is $" +

((int)((amount*100)/rate))/100.0); break;

default: System.out.println("Incorrect input");

}

}

}

But I don't know how to show the list:

 146 dollars 3 quarters 0 dimes 1 nickel 4 pennies 

which have to use indexOf() and substring() methods.

plz quickly!

under code is my new code can you find the mistaks?

in this code i have written why the cmd always say 33 line is wrongimage text in transcribed

Simport java.util.Scanner: public clasa abo public atatic void main (String] arga) 10 Scanner input -ncw Scanner(Syatem.in) 12 13 14 15 16 Systen.out.print("Enter the exchange rate from dollara tO RMB: double rate -input.nextDouble ) Syaten.out.print ( Enter D to convert dollars to RNB and 1 vice versa: int option input.nextInt double amount switch (option 19 20 21 case D: Syste.out.print(Enter the dollar arount: amount-input.nexDouble System.out println("arount 18 "+ 23 24 25 26 27 28 29 30 31 32 (amount ate"yuan" brea case 1: Syste.out.print(Enter the RNB amount: amount-input.nexcDouble Syetem.out println (amount " yuan 1s"+ ((int) ((arount*100) /rate))/100.0) default: System.out.printin("Incorrect input break; | String str = Double. toString (amount); int int int dot = str. indexOf(''); dollar Integer.parseInt(str.substring (0, dot)); decimal = Integer.parseInt(str.substring ( (dot + 1), 34 35 36 System.out-println (dollardollars 37 38 39 int quarter = ren / 25; 40 41 (dot + 3))); int ren = decimal ; ren-rem & 25; int dine ren / 10

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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

Recommended Textbook for

Sql All In One For Dummies 7 Books In One

Authors: Allen G Taylor ,Richard Blum

4th Edition

1394242298, 978-1394242290

More Books

Students also viewed these Databases questions