1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
KatRina [158]
3 years ago
12

Write a simple phonebook program that reads in a series of name-number pairs from the user (that is, name and number on one line

separated by whitespace) and stores them in a Map from Strings to Integers. Then ask the user for a name and return the matching number, or tell the user that the name wasn’t found.
Engineering
1 answer:
Vlad1618 [11]3 years ago
6 0

Answer:

import java.util.HashMap;

import java.util.Map;

import java.util.Scanner;

public class PhoneBook {

   public static void main(String[] args) {

       Scanner in = new Scanner(System.in);

       Map<String, String> map = new HashMap<>();

       String name, number, choice;

       do {

           System.out.print("Enter name: ");

           name = in.next();

           System.out.print("Enter number: ");

           number = in.next();

           map.put(name, number);

           System.out.print("Do you want to try again(y or n): ");

           choice = in.next();

       } while (!choice.equalsIgnoreCase("n"));

       System.out.print("Enter name to search for: ");

       name = in.next();

       if (map.containsKey(name)) {

           System.out.println(map.get(name));

       } else {

           System.out.println(name + " is not in the phone book");

       }

   }

}

You might be interested in
Which of the following color schemes is composed of hues next to eachother on the color wheel ?
Softa [21]
Analogous color schemes are composed of hues next to each other
3 0
3 years ago
Convert mechanical energy into electric energy. What can he use?
Nina [5.8K]

Answer:

<h2>Generator </h2>

Explanation:

A generator converts mechanical energy into electrical energy

7 0
4 years ago
PLEASE ANSWEAR FAST!!! <br> What does it mean if E˂1
Citrus2011 [14]
Scientific notation is another way to write a number. In scientific notation, the letter E is used to mean "10 to the power of." For example, 1.314E+1 means 1.314 * 101 which is 13.14 . Scientific notation is merely a format used for input and output.
5 0
2 years ago
There are two types of cellular phones, handheld phones (H) that you carry and mobile phones (M) that are mounted in vehicles. P
nexus9112 [7]

Answer:

A) P(W) = 0.5

B) P(MF) = 0.3

C) P(H) = 0.6

Explanation:

We are told that there are two types of cellular phones which are handheld phones (H) that you carry and mobile phones (M) that are mounted in vehicles.

Also, Phone calls can be classified by the traveling speed of the user as fast (F) or slow (W).

Thus, the sample space is combination of types and classification we are given and it is written as;

S = {HF, HW, MF, MW}

A) Now, phones can either be fast(F) or slow(W). Thus, we can write;

P(F) + P(W) = 1

We are given P(F) = 0.5

Thus;

0.5 + P(W) = 1

P(W) = 1 - 0.5

P(W) = 0.5

B) Now, from the problem statement, a phone call can either be made with a handheld(H) or mobile(M). Thus the sample space partition is {H, M} and we can express as;

P(H ∩ F) + P(M ∩ F) = P(F)

We are given P[F] = 0.5 and P[HF] = 0.2.

P(H ∩ F) is same as P[HF]

Also, P(M ∩ F) is same as P(MF)

Thus;

0.2 + P(MF) = 0.5

P(MF) = 0.5 - 0.2

P(MF) = 0.3

C) Similarly, mobile Phone calls can either be fast or slow. It means the sample space partition is {F, W}

Thus;

P(M) = P(MW) + P(MF)

P(M) = 0.1 + 0.3

P(M) = 0.4

Now, since cellular phones can either be handheld(H) or Mobile(M), then we can say;

P(H) + P(M) = 1

P(H) + 0.4 = 1

P(H) = 1 - 0.4

P(H) = 0.6

5 0
3 years ago
Do you think for security reasons everything that happens on the internet should be analyzed by the public security services ?
givi [52]

Answer: yes

Explanation: People post bad things that i think should get taken down i was on an app the other day and people were posting bad things

8 0
3 years ago
Other questions:
  • The moisture in hot, humid, stagnant air surrounding a cold-water pipeline continually diffuses to the cold surface where it con
    14·1 answer
  • Mike is involved in developing the model building codes that various states and local authorities in the United States adopt. He
    6·1 answer
  • If the electric field just outside a thin conducting sheet is equal to 1.5 N/C, determine the surface charge density on the cond
    9·1 answer
  • A roller-coaster car is traveling at a speed of 23 m/s when it passes through point B. At that point, it enters a concave down c
    8·1 answer
  • Two parts are to be assembled in a way that if one part fails, the entire assembly fails. Each of the parts have undergone exten
    15·1 answer
  • Which one is dependent variable?
    13·1 answer
  • Steel riverts in aluminium drain gutters leak after two years. is it galvanic corrosion? ​
    5·1 answer
  • Consider the formation of p-nitrophenol from p-nitrophenyl trimethyl acetate. The process is known as enzymatic hydrolysis and i
    7·1 answer
  • A 1.9-mm-diameter tube is inserted into an unknown liquid whose density is 960 kg/m3, and it is observed that the liquid rises 5
    7·1 answer
  • How many shift pulses would be required to serially shift the contents of one five-stage register to another five-stage register
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!