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

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...
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...
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
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....
Programming C: Write a program for a Rolodex of contact information (e.g., name, phone number, email)...
Programming C: Write a program for a Rolodex of contact information (e.g., name, phone number, email) implemented as a linked list. The program will ask the user to enter a new contact information, retrieve/print a person’s contact information, and to delete a person. It will maintain the linked list in alphabetical order by last name. It will also allow the user to search for a person’s contact information by last name. Assume that all last names are unique.
Given the following 7 relations: MIScompany (name, address, phone, email, FedTaxId, StaTaxId) branch (branchId, name, address,...
Given the following 7 relations: MIScompany (name, address, phone, email, FedTaxId, StaTaxId) branch (branchId, name, address, phone, email, FedTaxId, StaTaxId) employee (empId, driverId, ssno, name, branchId) customer (custId, name, address, driverId, ssno, FedTaxId, StaTaxId) equipment (equipId, name, type, upc, purchaseDate, year, manufacturId, cost, rentFee, branchId ) manufacturer (manufacturId, name, FedTaxId, StaTaxId, phone, email) rental (rentalId, equipId, custId, rentDate&time, returnDate&time, empId) Use relational algebra to retrieve every customer that has not rented any equipment in September 2020. The report should contain...
Write a program using C language that -ask the user to enter their name or any...
Write a program using C language that -ask the user to enter their name or any other string (must be able to handle multiple word strings) - capture the epoch time in seconds and the corresponding nanoseconds - ask the user to type in again what they entered previously - capture the epoch time in seconds and the corresponding nanoseconds -perform the appropriate mathematical calculations to see how long it took in seconds and nanoseconds (should show to 9 decimal...
Python Programming Please! #Name: #Date: #Random number, loop while true #ask user for number. Check to...
Python Programming Please! #Name: #Date: #Random number, loop while true #ask user for number. Check to see if the value is a number between 1 and 10 #if number is too high or too low, tell user, if they guessed it break out of loop Display "Welcome to my Guess the number program!" random mynumber count=1 while True try Display "Guess a number between 1 and 10"   Get guess while guess<1 or guess>10 Display "Guess a number between 1 and...
Using (C programming language) Create a health monitoring program, that will ask user for their name,...
Using (C programming language) Create a health monitoring program, that will ask user for their name, age, gender, weight, height and other health related questions like blood pressure and etc. Based on the provided information, program will tell user BMI, blood pressure numbers if they fall in healthy range or not and etc. Suggestions can be made as what should be calorie intake per day and the amount of exercise based on user input data. User should be able to...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT