Java Programming
Java Programming
8th Edition
ISBN: 9781305981829
Author: Joyce Farrell
Publisher: Cengage Limited
Expert Solution & Answer
Book Icon
Chapter 8, Problem 9PE

Explanation of Solution

Program:

File name: “PhoneNumbers.java

//Import necessary header files

import javax.swing.*;

//Define a class named PhoneNumbers

class PhoneNumbers

{

    //Define a main method

    public static void main(String[] args)

    {

        /*Declare an array to store first names for 30 people*/

        String[] names = new String[30];

        //Assign names for 10 people

        names[0] = "Gina";    names[1] = "Marcia";

        names[2] = "Rita";    names[3] = "Jennifer";

        names[4] = "Fred";    names[5] = "Neil";

        names[6] = "Judy";    names[7] = "Arlene";

        names[8] = "LaWanda"; names[9] = "Deepak";

        /*Declare an array to store numbers for 30 people*/

        String numbers[] = new String[30];

        //Assign numbers for 10 people

        numbers[0] = "(847) 341-0912";

        numbers[1] = "(847) 341-2392";

        numbers[2] = "(847) 354-0654";

        numbers[3] = "(414) 234-0912";

        numbers[4] = "(414) 435-6567";

        numbers[5] = "(608) 123-0904";

        numbers[6] = "(608) 435-0434";

        numbers[7] = "(608) 123-0312";

        numbers[8] = "(920) 787-9813";

        numbers[9] = "(930) 412-0991";

        //Declare the variables and initialize the value

        String entryName, entryPhone;

        int x;

        boolean isFound = false;

        int highest = 10;

        //Prompt the user to enter a name

        entryName = JOptionPane.showInputDialog(null,

           "Enter name to look up. Type 'quit' to quit.");

        /*While the user enters a name until the arrays are full

        and until the user enters quit*/   

        while (highest < 30 && !entryName.equals("quit"))

        {

            //For loop to be executed until x exceeds highest

            for(x = 0; x < highest; ++ x)

                /*If the name is found in the list, display the

                corresponding phone number*/

                if(entryName...

Blurred answer
Students have asked these similar questions
Add a timer in the following code. public class GameGUI extends JPanel {    private final Labyrinth labyrinth;    private final Player player;    private final Dragon dragon;    private Timer timer;    private long elapsedTime;  public GameGUI(Labyrinth labyrinth, Player player, Dragon dragon) {        this.labyrinth = labyrinth;        this.player = player;        this.dragon = dragon;        String playerName = JOptionPane.showInputDialog("Enter your name:");        player.setName(playerName);        elapsedTime = 0;        timer = new Timer(1000, e -> {            elapsedTime++;            repaint();        });        timer.start(); }    @Override    protected void paintComponent(Graphics g) {        super.paintComponent(g);        int cellSize = Math.min(getWidth() / labyrinth.getSize(), getHeight() / labyrinth.getSize());}
Change the following code so that when player wins the game, the game continues by creating new GameGUI with the same player. However the player's starting position is same, everything else should be reseted. public static void main(String[] args) {        Labyrinth labyrinth = new Labyrinth(10);        Player player = new Player(9, 0);        Random rand = new Random();        Dragon dragon = new Dragon(rand.nextInt(10), 9);        JFrame frame = new JFrame("Labyrinth Game");        GameGUI gui = new GameGUI(labyrinth, player, dragon);         frame.setLayout(new BorderLayout());        frame.setSize(600, 600);        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);        frame.add(gui, BorderLayout.CENTER);        frame.pack();        frame.setResizable(false);        frame.setVisible(true);    } public class GameGUI extends JPanel {    private final Labyrinth labyrinth;    private final Player player;    private final Dragon dragon;    private Timer timer;    private long…
Create a menu item which restarts the game. Also add a timer, which counts the elapsed time since the start of the game level. When the restart is pressed, the restarted game should ask the player' name  (in the GameGUI constructor) and set the score of player to 0 (player.setScore(0)), and the timer should restart again. And create a logic so that if the player loses his life (checkGame if the condition is false), then save this number together with his name into two variables. And display two buttons where one quits the game altogether (System.exit(0)) and the other restarts the game. public class GameGUI extends JPanel {    private final Labyrinth labyrinth;    private final Player player;    private final Dragon dragon;     private final ImageIcon playerIcon = new ImageIcon("data/images/player.png");    private final ImageIcon dragonIcon = new ImageIcon("data/images/dragon.png");    private final ImageIcon wallIcon = new ImageIcon("data/images/wall.png");    private final ImageIcon…
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Text book image
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:9781337102124
Author:Diane Zak
Publisher:Cengage Learning