Question

In: Computer Science

Using the given file, ask the user for a name, phone number, and email. Display the...

Using the given file, ask the user for a name, phone number, and email. Display the required information.

These are the Files that I made:

import java.util.Scanner;

public class Demo5
{
    public static void main(String args[])
    {
        Scanner keyboard = new Scanner(System.in);

        System.out.println("New number creation tool");

        System.out.println("Enter name");
        String name = keyboard.nextLine();

        System.out.println("Enter phone number");
        String phoneNumber = keyboard.nextLine();

        System.out.println("Enter email");
        String email = keyboard.nextLine();

        Phone test1 = new SmartPhone(name, phoneNumber, email);

        System.out.print(test1);
        System.out.println("Telephone neighbor: " + ((SmartPhone) test1).getTeleponeNeighbor());
    }
}

And:

public class SmartPhone extends Phone
{
    private String email;
    private String phone;
    private String phone2;

    public SmartPhone()
    {
        super("None",-1);
        phone = "Not set";
        email = "None";
        phone2 = "Not set";
    }

    public SmartPhone(String name, String phone)
    {
        super(name, Long.parseLong(phone));
        this.phone = phone;
        this.email = "None";
    }

    public SmartPhone(String name, String phone, String email)
    {
        super(name, Long.parseLong(phone));
        this.email = email;
        this.phone = phone;
    }

    public boolean hasPhoneNumber()
    {
        return !phone.equals("Not set");
    }

    public String getAreaCode()
    {
        return phone.substring(0,3);
    }

    public String getPrefix()
    {
        return phone.substring(3,6);
    }

    public String getLineNumber()
    {
        return phone.substring(6);
    }

    public String toString()
    {
        return "Name: " + name + "\n" +
                "Phone: " + phone + "\n" +
                "Email: " + email + "\n";
    }

    public String getTeleponeNeighbor()
    {
        if(phone == "Not set")
        {
            return "Cannot calculate phone number neighbor";
        }
        else
            {
            String roundUp = "(";
            roundUp += phone.substring(0,3) + ") ";
            roundUp += phone.substring(3,6) + "-";
            roundUp +=  Integer.parseInt(phone.substring(6,10)) + 1;

            return roundUp;
        }
    }
}

Given Files:

public class Phone
{
    protected String name;
    protected long number;

    public Phone() {
        this("None", -1);
    }

    public Phone(String name) {
        this(name, -1);
    }

    public Phone(String name, long number) {
        this.name = name;
        this.number = number;
    }

    public String getName() {
        return name;
    }

    public long getNumber() {
        return number;
    }
}

//////////////// Input ////////////////

Zed
5552129999
[email protected]

//////////////// Required Output ////////////////

New number creation tool\n
Enter name\n
Enter phone number\n
Enter email\n
Name: Zed\n
Phone: 5552129999\n
Email: [email protected]\n
Telephone neighbor: (555) 213-0000\n

Solutions

Expert Solution

public class SmartPhone extends Phone
{
    private String email;
    private String phone;
    private String phone2;

    public SmartPhone()
    {
        super("None",-1);
        phone = "Not set";
        email = "None";
        phone2 = "Not set";
    }

    public SmartPhone(String name, String phone)
    {
        super(name, Long.parseLong(phone));
        this.phone = phone;
        this.email = "None";
    }

    public SmartPhone(String name, String phone, String email)
    {
        super(name, Long.parseLong(phone));
        this.email = email;
        this.phone = phone;
    }

    public boolean hasPhoneNumber()
    {
        return !phone.equals("Not set");
    }

    public String getAreaCode()
    {
        return phone.substring(0,3);
    }

    public String getPrefix()
    {
        return phone.substring(3,6);
    }

    public String getLineNumber()
    {
        return phone.substring(6);
    }

    public String toString()
    {
        return "Name: " + name + "\n" +
                "Phone: " + phone + "\n" +
                "Email: " + email + "\n";
    }

    public String getTeleponeNeighbor()
    {
        if(phone == "Not set")
        {
            return "Cannot calculate phone number neighbor";
        }
        else
        {
            String roundUp = "(";
            String nextPhone = String.valueOf(Long.parseLong(phone)+1);
            roundUp += nextPhone.substring(0,3) + ") ";
            roundUp += nextPhone.substring(3,6) + "-";
            roundUp += nextPhone.substring(6);
            return roundUp;
        }
    }
}

Related Solutions

First, the Python program prompts user to enter user information (name, email, and phone number). Then...
First, the Python program prompts user to enter user information (name, email, and phone number). Then it displays a menu called “Fish Information” that has the following fish type: 1. Cat Fish 2. Red Fish 3. Any other fish Let user choose the fish type that he/she got and input the length of the fish. Then the program will determine what should be done with this particular fish. Based on the following criteria: Criteria: Length: FISHTYPE - Cat Fish <10:...
Script 3: Ask the user for a file's name If the file exists, ask them if...
Script 3: Ask the user for a file's name If the file exists, ask them if they would like to (C)opy, (M)ove, or (D)elete it by choosing C, M, or D If the user chooses C, ask for the destination directory and move it there If the user chooses M, ask for the destination directory and move it there If the user chooses D, delete the file. Ensure that the user enters only C, M, or D, warning them about...
Ask the user for the name of a car maker. Display the oldest and newest car...
Ask the user for the name of a car maker. Display the oldest and newest car from that maker. Modify your display to include the VIN of the car. Format the output in columns of 15, 25, 5, and 18. Standard Input                 Files in the same directory Toyota car-list.txt Required Output What car make are you looking for?\n Oldest Toyota\n Toyota MR2 1985 WAUFFAFL2CN997894\n Newest Toyota\n Toyota Venza 2013 WAUEH54B01N735764\n Standard Input                 Files in the same directory Chevrolet...
File IO Java question • Ask the user to specify the file name to open for...
File IO Java question • Ask the user to specify the file name to open for reading • Get the number of data M (M<= N) he wants to read from file • Read M numbers from the file and store them in an array • Compute the average and display the numbers and average.
Ask the user for their name Create a file called "daily.dat" within the home directory Ask...
Ask the user for their name Create a file called "daily.dat" within the home directory Ask the user for a line of text that the system should save to the file Add to the file the line of text entered by the user Ask the user for a second line of text that the system should save to the file Append at the end of the file the line of text entered by the user Create a copy of the...
Task 2.5: Write a script that will ask the user for to input a file name...
Task 2.5: Write a script that will ask the user for to input a file name and then create the file and echo to the screen that the file name inputted had been created 1. Open a new file script creafile.sh using vi editor # vi creafile.sh 2. Type the following lines #!/bin/bash echo ‘enter a file name: ‘ read FILENAME touch $FILENAME echo “$FILENAME has been created” 3. Add the execute permission 4. Run the script #./creafile.sh 5. Enter...
c++ In this program ask the user what name they prefer for their file, and make...
c++ In this program ask the user what name they prefer for their file, and make a file, the file name should za file. Get a number from the user and save it into the create file. should be more than 20 number in any order. print out all 20 numbers in a sorted array by using for loop, last print out its total and average. At last create a function in which you will call it from main and...
Write a class named ContactEntry that has fields for a person’s name, phone number and email...
Write a class named ContactEntry that has fields for a person’s name, phone number and email address. The class should have a no-arg constructor and a constructor that takes in all fields, appropriate setter and getter methods. Then write a program that creates at least five ContactEntry objects and stores them in an ArrayList. In the program create a method, that will display each object in the ArrayList. Call the method to demonstrate that it works. I repeat, NO-ARG constructors....
This is to be done using MIPS assembly language. Display the following menus, ask user to...
This is to be done using MIPS assembly language. Display the following menus, ask user to select one item. If 1-3 is selected, display message “item x is selected”, (x is the number of a menu item), display menus again; if 0 is selected, quit from the program. 1. Menu item 1 2. Menu item 2 3. Menu item 3 0. Quit Please select from above menu (1-3) to execute one function. Select 0 to quit
Flowchart + Python. Ask the user for a value. Then, ask the user for the number...
Flowchart + Python. Ask the user for a value. Then, ask the user for the number of expressions of that value. Use While Loops to make a program. So then, it should be so that 5 expressions for the value 9 would be: 9 * 1 = 9 9 * 2 = 18 9 * 3 = 27 9 * 4 = 36 9 * 5 = 45 Flowcharts and Python Code. Not just Python code. I cannot read handwriting....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT