EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
9th Edition
ISBN: 9781337671385
Author: FARRELL
Publisher: CENGAGE LEARNING - CONSIGNMENT
bartleby

Concept explainers

bartleby

Videos

Expert Solution & Answer
Book Icon
Chapter 7, Problem 12PE

Explanation of Solution

Program:

File name: “PrepareTax.java

//Import necessary header files

import javax.swing.*;

//Define a class named PrepareTax

public class PrepareTax

{

    //Define a main method

    public static void main(String[] args)

    {

        //Declare a string of values

        String entry = "", ssn, last, first, address, city, state, zip;

        //Declare the variables

        char status;

        int x;

        double income = 0;

        boolean isGood = false;

        /*Prompt the user for data as long as the

        Social Security number is not in the correct format,

        with digits and dashes in the appropriate positions*/

        while(!isGood)

        {

            isGood = true;

            //Prompt the user to enter SSN

            entry = JOptionPane.showInputDialog(null,

            "Enter your Social Security number");

/*If SSN is not in the correct format, with digits and dashes in the appropriate positions*/

            if(entry.length() != 11)

            isGood = false;

            /*If SSN is in the correct format, with digits and

            dashes in the appropriate positions*/

            else

            {

                //For loop to be executed until x exceeds 3

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

                    if(!Character.isDigit(entry.charAt(x)))

                        isGood = false;

                //For loop to be executed until x exceeds 6

                for(x = 4; x < 6; ++x)

                    if(!Character.isDigit(entry.charAt(x)))

                        isGood = false;

                //For loop to be executed until x exceeds 11

                for(x = 8; x < entry.length(); ++x)

                    if(!Character.isDigit(entry.charAt(x)))

                        isGood = false;

                //If third and sixth character is a dash

if(!(entry.charAt(3) == '-') || !(entry.charAt(6) == '-'))

                  isGood = false;

            }

        }

        //Assign the value

        ssn = entry;

        //Prompt the user to eter the first name

        first = JOptionPane.showInputDialog(null,

        "Enter your first name");

        //Prompt the user to eter the last name

        last = JOptionPane.showInputDialog(null,

        "Enter your last name");

        //Prompt the user to eter the address

        address = JOptionPane.showInputDialog(null,

         "Enter your address");

        //Prompt the user to eter the city

        city = JOptionPane.showInputDialog(null,

         "Enter your city");

        //Prompt the user to eter the state

        state = JOptionPane.showInputDialog(null,

         "Enter your state");

        isGood = false;

        /*Prompt the user for data as long as the

        zip code is not five digits*/

        while(!isGood)

        {

            isGood = true;

            //Prompt the user to enter the zip code

            entry = JOptionPane.showInputDialog(null,

            "Enter your Zip code");

            //If zip code is not five digits

            if(entry.length() != 5)

                isGood = false;

            //Else zip code is five digits

            else

                //For loop to be executed until x exceeds 5

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

                    if(!Character.isDigit(entry.charAt(x)))

                        isGood = false;

        }

        zip = entry;

        isGood = false;

        /*Prompt the user for data as long as the

        marital status does not begin with one of

        the following: S, s, M, or m*/

        while(!isGood)

        {

            isGood = true;

            //Prompt the user to enter the marital status

            entry = JOptionPane...

Blurred answer
Students have asked these similar questions
Create an Investment class that contains fields to hold the initial value of an investment, the current value, the profit (calculated as the difference between current value and initial value), and the percent profit (the profit divided by the initial value). Include a constructor with two arguments: initial, and current values and then calculate profit, and percent profit, and a display function that displays all fields. Create a House class that includes fields for street address and square feet, a constructor that requires values for both fields, and a display function. Create a HouseThatIsAnInvestment class that inherits from Investment and House. It includes a constructor (in order to pass arguments to its parent constructors) and a display function that calls the display functions of the parents. Write a main() function that declares a HouseThatIsAnInvestment and displays its values.
An artist's discography includes several albums. Each album includes several songs. We want to model the Discography, Album and Song classes as follows • a discography has a single artist attribute and a total_time method that returns the total minutes corresponding to the artist's entire discography • an album has a single name attribute and a total_time method that returns the total minutes for the songs on the album a song has two attributes: title and duration and a duration method that returns the duration in minutes of the song • we want to take advantage of the composite pattern so that the duration method delivers the total number of minutes of a song, album or the entire discography of the artist depending on the object in question a) Draw a UML class diagram showing the solution b) Write the Ruby code that implements it
Create a class named Ship that has two private fields one for the name (string)of the ship, and the other for the year (string) the ship was built. The classcontains a parameterized constructor to set the values of each field get methods for each of the fields display method to display ship’s information.Create a class named CruiseShip that extends Ship class. CruiseShip class should have a private field for the maximum number of passengers (int).The class contains- a parameterized constructor to set the value of the field- get and set method for the field- a display method that overrides ship class display method anddisplay CruiseShip information.Create an application/class named CruiseShipDemo that allows a user toenter values to create 5 CruiseShip objects and save them in the array. Display the records.The CruiseShipDemo class should have a method named update to updatethe CruiseShips information. The method prompts the user for the ship name, if the requested record does not…
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
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
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Introduction to Classes and Objects - Part 1 (Data Structures & Algorithms #3); Author: CS Dojo;https://www.youtube.com/watch?v=8yjkWGRlUmY;License: Standard YouTube License, CC-BY