a.
Explanation of Solution
Program:
File name: “CountSpaces.java”
//Define a class named CountSpaces
public class CountSpaces
{
//Define main method
public static void main(String[] args)
{
//Read a String that holds an inspirational quote
String aString =
"The best and most beautiful things in the world " +
"cannot be seen or even touched - they must be felt with the heart.";
//Declare the variables and initialize the value
int numSpaces = 0;
int stringLength = aString...
b.
Explanation of Solution
Program:
File name: “CountSpaces2.java”
//Import necessary header files
import java.util.*;
//Define a class named CountSpaces2
public class CountSpaces2
{
//Define main method
public static void main(String[] args)
{
//Create an object for the Scanner class
Scanner in = new Scanner(System.in);
//Declare the variables and initialize the value
String aString;
int stringLength;
int numSpaces = 0;
//Prompt the user to enter an inspirational quote
System.out.print("Enter an inspirational quote >> ");
aString = in.nextLine();
//Read the length of the string
stringLength = aString...
Want to see the full answer?
Check out a sample textbook solution- Each of the following files in the Chapter.06 folder of your downloadable student files has syntax and/or logical errors. In each case, determine the problem, and fix the program. After you correct the errors, save each file using the same filename preceded with Fixed. For example, DebugSix01.cs will become FixedDebugSix01.cs. a. DebugSix01.cs b. DebugSix02.cs c. DebugSix03.cs d. DebugSix04.csarrow_forwardEach of the following files in the Chapter.01 folder of your downloadable student files has syntax and/or logical errors. In each case, determine the problem and fix the program. After you correct the errors, save each file using the same filename preceded with Fixed. For example, DebugOne1.cs will become FixedDebugOne1 .cs. a. DebugOne1.cs b. DebugOne2.cs c. DebugOne3.cs d. DebugOne4.csarrow_forwardEach of the following files in the Chapter.05 folder of your downloadable student files has syntax and/or logical errors. In each case, determine the problem, and fix the program. After you correct the errors, save each file using the same filename preceded with Fixed. For example, save DebugFive1.cs as FixedDebugFive1 .cs. a. DebugFive1.cs b. DebugFive2.cs c. DebugFive3.cs d. DebugFive4.csarrow_forward
- Each of the following files in the Chapter.10 folder of your downloadable student files has syntax and/or logical errors. In each case, determine the problem and fix the program. After you correct the errors, save each file using the same filename preceded with Fixed. For example, DebugTen01.cs will become FixedDebugTen01 .cs. a. DebugTen01.cs b. DebugTen02.cs c. DebugTen03.cs d. DebugTen04.csarrow_forwardEach of the following files in the Chapter.04 folder of your downloadable student files has syntax and/or logical errors. In each case, determine the problem, and fix the program. After you correct the errors, save each file using the same filename preceded with Fixed. For example, save DebugFour1.cs as FixedDebugFour1.cs. a. DebugFour1.cs b. DebugFour2.cs c. DebugFour3.cs d. DebugFour4.csarrow_forwardFind a line with an error in the following code segment: 1: void displayFile(fstream file) {2: string line;3: while (file >> line) 4: cout << line << endl;5: } Group of answer choices 1 2 3 4arrow_forward
- If you have downloaded the source code from this book's companion web site, youwill find the following files in the Chapter 07 folder:• GirlNames.txt--This file contains a list of the 200 most popular names given togirls born in the United States from the year 2000 through 2009.• BoyNames.txt--This file contains a list of the 200 most popular names given toboys born in the United States from the year 2000 through 2009.Write a program that reads the contents of the two files into two separatelists, allows a user to input either a girl's name, a boy's name, orboth, then tells the user whether the name(s) was/were popular between 2000 and2009.First, the program should prompt the user to choose a girl's name, a boy's name,or both by entering either 'girl', 'boy', or 'both.'Once they have chosen, they should be able to input a name. If the name wasa popular name, like Jacob or Sophia, the program should print "Jacob was apopular boy's name between 2000 and 2009." or "Sophia was a popular…arrow_forwardIf you have downloaded the source code from this book's companion web site, youwill find the following files in the Chapter 07 folder:• GirlNames.txt--This file contains a list of the 200 most popular names given togirls born in the United States from the year 2000 through 2009.• BoyNames.txt--This file contains a list of the 200 most popular names given toboys born in the United States from the year 2000 through 2009.Write a program that reads the contents of the two files into two separatelists, allows a user to input either a girl's name, a boy's name, orboth, then tells the user whether the name(s) was/were popular between 2000 and2009.First, the program should prompt the user to choose a girl's name, a boy's name,or both by entering either 'girl', 'boy', or 'both.'Once they have chosen, they should be able to input a name. If the name wasa popular name, like Jacob or Sophia, the program should print "Jacob was apopular boy's name between 2000 and 2009." or "Sophia was a popular…arrow_forwardThe attached text file lists all vehicles entered to the parking lot of a mega shopping centre for one day. Each line of the text file includes a vehicle make, color, plate number and the date of entry to the mall. Based on the content of this text file and the program result in the console, provide a line-by-line description for the below java program. Please provide line by line explaination for the code below. And I don't understand line 16, so detail that a bit.arrow_forward
- Given string userGreeting on one line and string userName on a second line, append a space to userGreeting. Then, append userName to userGreeting. Lastly, append a period to userGreeting. Ex: If the input is: Hey Wilma Lee then the output is: Hey Wilma Lee. #include <iostream>#include <string>using namespace std; int main() { string userGreeting; string userName; getline(cin, userGreeting); getline(cin, userName); /* Your code goes here */ cout << userGreeting << endl; return 0;}arrow_forwardProblem: Write a program that prompts the user to enter 10 names, each with maximum of 30 characters. Output the names that start with letter A and its corresponding length. This is my C++ Codes but it has errors when I run it. Can you fix the errors? Please still use header files iostream and cstring. //Start of program#include <iostream>#include <cstring> using namespace std; int main(){//Declare arraychar name[10]; //Prompt the user to enter 10 namescout << "Enter 10 names: " << endl; //For loopfor (int i = 0; i < 10; i++){//Store each name in the arraycin >> name[i]; if (strlen(name) > 30){i--;}} //Display the names that start with A or acout << "Names starting with 'A' and their corresponding length: " << endl; //Iterate the value of i from 0 to 9 by using for loopfor (int i = 0; i < 10; i++){//Checking condition if name starts with A or aif (name[i][0] == 'A' || name[i][0] == 'a'){cout << name[i] << ": " <<…arrow_forwardCan I please get help for this question. There are three files required. 1). Main.cpp #include <iostream>using namespace std; #include "ItemToPurchase.h" int main() { /* Type your code here */ return 0;} 2) ItemToPurchase.cpp #include <iostream>using namespace std; #include "ItemToPurchase.h" /* Type your code here */ 3) ItemToPurchase.h #ifndef ITEM_TO_PURCHASE_H#define ITEM_TO_PURCHASE_H #include <string>using namespace std; /* Type your code here */ #endifarrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,