Concept explainers
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...
Trending nowThis is a popular solution!
Chapter 7 Solutions
Mindtap Programming, 1 Term (6 Months) Printed Access Card For Farrell's Java Programming, 9th
- The following is code for a disc golf program written in C++: // player.h #ifndef PLAYER_H #define PLAYER_H #include <string> #include <iostream> class Player { private: std::string courses[20]; // Array of course names int scores[20]; // Array of scores int gameCount; // Number of games played public: Player(); // Constructor void CheckGame(int playerId, const std::string& courseName, int gameScore); void ReportPlayer(int playerId) const; }; #endif // PLAYER_H // player.cpp #include "player.h" #include <iomanip> Player::Player() : gameCount(0) {} void Player::CheckGame(int playerId, const std::string& courseName, int gameScore) { for (int i = 0; i < gameCount; ++i) { if (courses[i] == courseName) { // If course has been played, then check for minimum score if (gameScore < scores[i]) { scores[i] = gameScore; // Update to new minimum…arrow_forwardIn this assignment, you will implement a multi-threaded program (using C/C++) that will check for Prime Numbers and Palindrome Numbers in a range of numbers. Palindrome numbers are numbers that their decimal representation can be read from left to right and from right to left (e.g. 12321, 5995, 1234321). The program will create T worker threads to check for prime and palindrome numbers in the given range (T will be passed to the program with the Linux command line). Each of the threads works on a part of the numbers within the range. Your program should have some global shared variables: • numOfPrimes: which will track the total number of prime numbers found by all threads. numOfPalindroms: which will track the total number of palindrome numbers found by all threads. numOfPalindromic Primes: which will count the numbers that are BOTH prime and palindrome found by all threads. TotalNums: which will count all the processed numbers in the range. In addition, you need to have arrays…arrow_forwardHow do you distinguish between hardware and a software problem? Discuss theprocedure for troubleshooting any hardware or software problem. give one reference with your answer.arrow_forward
- You are asked to explain what a computer virus is and if it can affect computer’shardware or software. How do you protect your computer against virus? give one reference with your answer.arrow_forwardDistributed Systems: Consistency Models fer to page 45 for problems on data consistency. structions: Compare different consistency models (e.g., strong, eventual, causal) for distributed databases. Evaluate the trade-offs between availability and consistency in a given use case. Propose the most appropriate model for the scenario and explain your reasoning. Link: [https://drive.google.com/file/d/1wKSrun-GlxirS31Z9qoHazb9tC440AZF/view?usp=sharing]arrow_forwardOperating Systems: Deadlock Detection fer to page 25 for problems on deadlock concepts. structions: • Given a system resource allocation graph, determine if a deadlock exists. If a deadlock exists, identify the processes and resources involved. Suggest strategies to prevent or resolve the deadlock and explain their trade-offs. Link: [https://drive.google.com/file/d/1wKSrun-GlxirS31Z9qoHazb9tC440 AZF/view?usp=sharing]arrow_forward
- Artificial Intelligence: Heuristic Evaluation fer to page 55 for problems on Al search algorithms. tructions: Given a search problem, propose and evaluate a heuristic function. Compare its performance to other heuristics based on search cost and solution quality. Justify why the chosen heuristic is admissible and/or consistent. Link: [https://drive.google.com/file/d/1wKSrun-GlxirS31Z9qoHazb9tC440 AZF/view?usp=sharing]arrow_forwardRefer to page 75 for graph-related problems. Instructions: • Implement a greedy graph coloring algorithm for the given graph. • Demonstrate the steps to assign colors while minimizing the chromatic number. • Analyze the time complexity and limitations of the approach. Link [https://drive.google.com/file/d/1wKSrun-GlxirS3IZ9qoHazb9tC440 AZF/view?usp=sharing]arrow_forwardRefer to page 150 for problems on socket programming. Instructions: • Develop a client-server application using sockets to exchange messages. • Implement both TCP and UDP communication and highlight their differences. • Test the program under different network conditions and analyze results. Link: [https://drive.google.com/file/d/1wKSrun-GlxirS31Z9qo Hazb9tC440AZF/view?usp=sharing]arrow_forward
- Refer to page 80 for problems on white-box testing. Instructions: • Perform control flow testing for the given program, drawing the control flow graph (CFG). • Design test cases to achieve statement, branch, and path coverage. • Justify the adequacy of your test cases using the CFG. Link: [https://drive.google.com/file/d/1wKSrun-GlxirS3IZ9qo Hazb9tC440 AZF/view?usp=sharing]arrow_forwardRefer to page 10 for problems on parsing. Instructions: • Design a top-down parser for the given grammar (e.g., recursive descent or LL(1)). • Compute the FIRST and FOLLOW sets and construct the parsing table if applicable. • Parse a sample input string and explain the derivation step-by-step. Link: [https://drive.google.com/file/d/1wKSrun-GlxirS31Z9qoHazb9tC440 AZF/view?usp=sharing]arrow_forwardRefer to page 20 for problems related to finite automata. Instructions: • Design a deterministic finite automaton (DFA) or nondeterministic finite automaton (NFA) for the given language. • Minimize the DFA and show all steps, including state merging. • Verify that the automaton accepts the correct language by testing with sample strings. Link: [https://drive.google.com/file/d/1wKSrun-GlxirS31Z9qo Hazb9tC440AZF/view?usp=sharing]arrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTEBK JAVA PROGRAMMINGComputer ScienceISBN:9781305480537Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,