Create a Java program that uses methods. In the main method, the program must prompt the user for a Social Security Number in the following format: DDD-DD-DDDD, where D is a digit. The program must call a method called “validate” that must receive the inputted SSN from the main method and decide whether the inputted number is valid and return the decision to the main method. Then, the main method must print the decision.
`Hey,
Note: Brother in case of any queries, just comment in box I would be very happy to assist all your queries
import java.util.Scanner;
public class SSNValidator {
public static boolean validate(String ssn) {
int length = ssn.length();
if(length == 9) {
//all characters must be digits, of the form XXXXXXXXX
for (char s: ssn.toCharArray()) {
if(!Character.isDigit(s)) {
return false;
}
}
} else if(length == 11) {
//should be of the format XXX-XX-XXXX
char chars[] = ssn.toCharArray();
for(int i = 0; i<length; i++) {
if (i==3 || i == 6) {
if(chars[i] != '-') {
return false;
}
} else {
if(!Character.isDigit(chars[i])) {
return false;
}
}
}
} else {
return false;
}
return true;
}
public static void main(String[] args) {
String ssn;
Scanner sc = new Scanner(System.in);
boolean isSSN = false;
System.out.println("Enter SSN to validate or 'quit' to Quit the
program: ");
ssn = sc.next();
isSSN = validate(ssn);
if(isSSN) {
System.out.println(ssn + " is a valid SSN");
} else {
System.out.println(ssn + " is not a valid SSN");
}
}
}
Kindly revert for any queries
Thanks.
Create a Java program that uses methods. In the main method, the program must prompt the...
In Java Main method Your main program will prompt the user for a test name and the number of scores the user will enter. After creating an arraylist to hold the scores, prompt the user for all the scores to hold in the arraylist. After all the scores are entered, then repeat back the score & letter grade. GradeBook Object Create an instance of a GradeBook object and pass the test name and arraylist to set the instance variables. At...
Must use JOPTIONPANE. Using arrays and methods create a JAVA program. Create a java program that holds an array for the integer values 1-10. Pass the array to a method that will calculate the values to the power of 2 of each element in the array. Then return the list of calculated values back to the main method and print the values
Write a Java program that has the following methods: findSum - a method that takes in three integers and returns the sum of these three integers; findAverage - a method that takes in three integers and returns the average of these three integers (as a double value) Within the main method read in 3 integers from the user and call above two methods by passing the three integers. Your program should print the user provided three integers and results of...
using java code Create a program that has a main method and a recursive method: isPalindrome – recursive method that will receive a String and will return a Boolean that will evaluate whether the String is a palindrome or not. The main method will also ask the user for a word/phrase and using the recursive method isPalindrome it will print a message whether the word/phrase is a palindrome or not.
You will create a program with two methods, the main() method of course and another method called printArray(). The main method will define an array of 5 elements. A loop will be used to prompt the user to enter 5 numeric values which will go into the 5 array elements. The main() method will then call the printArray() method passing the array by reference, and the array length by value. The printArray() method will then print the contents of the...
IN JAVA Overview In this project you will implement a Java program that will print several shapes and patterns according to uses input. This program will allow the use to select the type (say, rectangle, triangle, or diamond), the size and the fill character for a shape. All operations will be performed based on the user input which will respond to a dynamic menu that will be presented. Specifically, the menu will guide the user to decide between different forms...
Write a Java program to convert octal (integer) numbers into their decimal number equivalents (exactly the opposite of what you have done in Assignment 4). Make sure that you create a new Project and Java class file for this assignment. Your file should be named “Main.java”. You can read about octal-to-decimal number conversions on wikepedia Assignment 4 is at the bottom Objective Your program should prompt the user to enter a number of no greater than 8 digits. If the...
14.8 Prog 8 Overload methods (find avg) Write a program to find the average of a set numbers (assume that the numbers in the set is less than 20) using overload methods. The program first prompts the user to enter a character; if the character is 'I' or 'i', then invokes the appropriate methods to process integer data set; if the character is 'R' or 'r', then invokes the appropriate methods to process real number data set; if the inputted...
Using Java, please create the program for the following prompt.
MUST CREATE BUTTONS IN A JFRAME, as specified by the prompt! DO NOT
use user input of 1, 2, 3 etc. User input must come from clicking
the buttons. Please be sure to test your program. Thank you!
Write a program that displays three buttons with the names or images of three candidates for public of office. Imagine that a person votes by clicking the button that shows the candidate...
I need to create a code for this prompt: In this project we will build a generic UserInput class for getting keyboard input from the user. Implementation: The class UserInput is a 'Methods only' class, and all the methods should be declared static. Look at the TestScanner.java program at the bottom of this page that inputs a string, int and double. It shows you how to use Scanner class to get input from the keyboard. Write FOUR simple methods, one...