Concept explainers
a.
Explanation of Solution
Program:
File name: “StringSort.java”
//Import necessary header files
import java.util.*;
import javax.swing.*;
//Define a class named StringSort
public class StringSort
{
//Define main method
public static void main(String[] args)
{
//Create an array of 15 string values
String[] values = {"mouse", "dog", "cat", "horse", "cow",
"moose", "tiger", "lion", "elephant", "bird", "hamster",
"guina pig", "leopard", "aardvark", "hummingbird"};
//Declare the variable
...
b.
Explanation of Solution
Program:
File name: “StringSort2.java”
//Import necessary header files
import java.util.*;
import javax.swing.*;
//Define a class named StringSort2
public class StringSort2
{
//Define main method
public static void main(String[] args)
{
//Create an array of 15 string values
String[] values = new String[15];
//Declare the variables and initialize the values
int x = 0;
int count = 0;
String word;
final String QUIT = "zzz";
//Declare a Boolean variable and initialize the value
boolean didUserQuit = false;
/*For loop is executed until x exceeds the length of the given values*/
for(x = 0; x < values.length; ++x)
values[x] = QUIT;
//Assign value 0 to x
x = 0;
//While x is less than the length of the given values
while(x < values.length)
{
//Prompt the user to enter a word
word = JOptionPane.showInputDialog(null, "Enter a word or " +
QUIT + " to quit");
//If the user enters zzz
if(word.equals(QUIT))
{
count = x;
x = values...
Trending nowThis is a popular solution!
- Create an application that reads a sequence of up to 25 names and postal (ZIP) codes for persons. Put the data in an object that can have a first name (string), last name (string), and postal code (integer). Assume that each line of input will have two strings separated by a tab character, followed by an integer value. After the input has been read in, print the list to the screen in the appropriate manner.arrow_forward2. Create a Java project named clsProject2 Create a method called public static String [][] get_years_quarters(String strFile), which accepts one parameter (loanamounts.txt), and returns a 2-D array (24 rows X 2 columns). The first columns should contain the years, and the second column should contain the quarters of the processed text file.arrow_forwardMake an application that displays a series of at least five student ID numbers (that you have stored in an array) and asks the user to enter a numeric test score for the student. Make a ScoreException class, and throw a ScoreException for the class if the user does not enter a valid score (less than or equal to 100). Catch the ScoreException, display the message Score over 100, and then store a 0 for the student's score. At the end of the application, display all the student IDs and scores. public class ScoreException extends Exception { public ScoreException(String s) { } } import java.util.*; public class TestScore { public static void main(String args[]) throws Exception { Scanner input = new Scanner(System.in); int[] ids = {1234, 2345, 3456, 4567, 5678}; int[] scores = {0, 0, 0, 0, 0}; String scoreString = new String(); final int HIGHLIMIT = 100; String inString, outString = ""; for (int x = 0; x < ids.length; ++x)…arrow_forward
- can you please write in java.util.scanner form and can you make it so i can copy and past it please In the main() method, create four arrays: String[] tokensFromFile1; int[] countsFromFile1; String[] tokenssFromFile2; int[] countsFromFile2; Use calculateTokenCounts() method to populate these four arrays with data from "GettysburgAddress.txt" file and "SecondInauguralAddress.txt" file. Create one array: int[][] correlation; Its row length and column length should be the same as the length of the totalTokens array. Each row and each column of the correlation array coresponds to the element in the totalTokens array. Create a method: public static void calculateCorrelation(int[][] correlation, String[] totalTokens, String[] tokens) Go through the word pairs in the tokens array. Note 1: How do we get all word pairs from the tokens array? Note 2: How do we…arrow_forwardThis program asks the user to enter 4 names for a team,storing them in an array of Strings.Then the program changes the array, replacing the firstteam member with Craig. Then this modified list ofnames is printed on the screen. You can see sampleoutput at the end of this file. 1) inputTeam: Input and return an array of Strings,with the specified number of elements (one int parameter).2) substitute: Has 3 parameters: an array of Strings,and two String names. Changes the array by replacing theelement containing the nameToRemove with the nameToAdd.3) outputArray: Has 1 parameter: an array of Strings.Outputs all the array elements, separated by spaces. import java.util.Scanner; class Main{ public static void main(String[] args) { String[] team; String nameToRemove, nameToAdd; System.out.println("Please enter 4 names for this team:"); team = inputTeam(4); nameToRemove = team[0]; nameToAdd = "Craig"; System.out.println("Sorry, we need to replace " + nameToRemove…arrow_forwardWrite an application containing three parallel arrays that hold 10 elements each. The first array hold four-digit student ID numbers, the second array holds first names, and the third array holds the students’ grade point averages. Use dialog boxes to accept a student ID number and display the student’s first name and grade point average. If a match is not found, display an error message that includes the invalid ID number and allow the user to search for a new ID number. java programarrow_forward
- Using the two arrays shown below,write a program that prompts the user to enter an integer between 1 and 12 andthen displays the months and its number of days corresponding to the integerentered. Your program should display “wrong number” if the user enters awrong number by catching ArrayIndexOutOfBoundsException. String[] months = {"January", "February", "March", "April","May", "June","July", "August", "September", "October","November", "December"};int[] dom = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};arrow_forwardthe program below is the program that is being referred to in the image, using namespace std; struct varis { string lastName, firstName; int hours, rate; double pay; int major_type[2]; }; void print_Title(); string readName(); int readHours(); int readPayRate(); int readMajor(); double computeAmount(int myMajor, double myPay); void printRecord(varis info[], int size); int main() { print_Title(); int size = 10; int x = 0; varis info[size]; do { cout << "\nEnter first name, last name, numbers of hours worked, and hourly pay\n"; info[x].firstName = readName(); info[x].lastName = readName(); info[x].hours = readHours(); info[x].rate = readPayRate(); info[x].pay = info[x].hours * info[x].rate; cout << "Type 1 if you are a Computer Science major or a 0 if you are not: "; info[x].major_type[0] = readMajor(); cout << "Type 1 if you are a Cyber Security…arrow_forwardIn python The text file “studentMarks.txt” has been provided for you. Each line contains the Last Name, First Name and 8 marks separated by spaces of a single student. For each student in the file, adjust the file to include the average of their top 6 marks, rounded to 1 decimal place, at the end of the line. For example, in the file, the line may say: Mars, Bruno 82 82 85 94 65 79 81 90 Afterwards, it should be updated to say: Mars, Bruno 82 82 85 94 65 79 81 90 Top6Avg: 85.7 Your program must define a function to determine the average of the top 6 marks. You may define more functions as needed for your program.arrow_forward
- In java, without Arrays and using only String methods ( don't use String builder) // Question 17: In MS-DOS, a file name consists of up // to 8 characters (excluding '.', ':', backslask, '?', // and '*'), followed by an optional dot ('.' character) // and extension. The extension may contain zero to three // characters. For example, 1STFILE.TXT is a valid filename. // Filenames are case-blind. // // Write and test a method that takes // in a String, validates it as a valid MS-DOS file // name, appends the extensions ".TXT" if no extension // is given (that is, no '.' appears in FILENAME), converts // the name to uppercase, and returns the resulting string // to the calling method // If fileName ends with a dot, remove that dot and do not // append the default extension. If the name is invalid, // validFileName should return null. public String validFileName(String n) { }arrow_forwardWrite a Java application and use a Two dimensional array to store five Dutch, French and Italian translated words. Use a single array to store the English words.Your program must:Q.2.1Contain a single array to contain the following five English words and a Two dimensional array to store the following Dutch, French and Italian translated words.ENGLISH WORD skyrunstudymusic dogDUTCH WORD hemelrennenstudiemuziek hondFRENCH WORD cielcouriretudemusique chienITALIAN WORD cielocorrerestudiamusica cane Print out each English word with the translated Dutch, French and Italian wordarrow_forwardWrite an application that displays a series of at least five student ID numbers (that you have stored in an array) and asks the user to enter a numeric test score for the student. Create a ScoreException class, and throw a ScoreException for the class if the user does not enter a valid score (less than or equal to 100). Catch the ScoreException and then display an appropriate message. In addition, store a 0 for the student’s score. At the end of the application, display all the student IDs and scores. Save the files as ScoreException.java and TestScore.java.arrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT