Respuesta :
Answer:
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args)
- {
- int areaCode[] = {121, 122, 123, 124, 125};
- double rates [] = {0.2, 0.3, 0.35, 0.15, 0.25};
- Scanner input = new Scanner(System.in);
- System.out.print("Enter area code: ");
- int a = input.nextInt();
- System.out.print("Enter calling time: ");
- int time = input.nextInt();
- double cost = 0;
- for(int i=0; i < areaCode.length; i++){
- if(areaCode[i] == a){
- cost = rates[i] * time;
- }
- }
- System.out.println("Total cost of the call: $" + cost);
- }
- }
Explanation:
The solution code is written in Java.
Firstly create two parallel arrays for area code and calling rate (Line 7-8). Presume the rate is based on call per minute.
Next, user Scanner object to prompt user to input area code and calling time (Line 10 - 14).
Create a for loop to identify the index where the input area code can be found in the array and then calculate the cost by using the same index i to get the corresponding rate (Line 17 - 20).
Print the cost to console (Line 22).