Concept explainers
Explanation of Solution
a. Declaring string array:
The statement which is used to declare “String” array with the values “Mercury”, “Venus&...
Explanation of Solution
b. Loop to display each element in the array:
//Class definition
public class Sample {
// define main function
public static void main(String[] args) {
// Declaration of string array
String[] scientists = {"Einstein", "Newton", "Copernicus", "Kepler"};
// Loop to read each element in scientists array
for(int i = 0; i<scientists.length; i++)
// Display contents of the scientists array
System...
Explanation of Solution
c. Loop to display total length of the all strings present in the array:
//Class definition
public class Sample {
// define main function
public static void main(String[] args) {
// Declaration of string array
String[] scientists = {"Einstein", "Newton", "Copernicus", "Kepler"};
// Declare and initialize the variable
int total = 0;
// Loop to read each element in scientists array
for(int i = 0; i<scientists.length; i++)
/* Using the length() method read the length of strings present in the array */
total += scientists[i]...
Trending nowThis is a popular solution!
Chapter 7 Solutions
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
- a. Create a 1D array of integers to store 50 integers. b. Store values from 0 to 49 into the array you just created. c. Create a new String Object using no-arg constructor. d. Using for loop append the array elements one by one to the String (one per loop iteration) e. Record and display a run-time it took to append all integers to the String (record run-time of 1.d.)). E.g. "It took nanoseconds to append 50 integers to the Stringarrow_forwardGrade Book A teacher would like to assign a letter grade to a student, based on student's test score. Write a program to help this teacher managing her students' test score. Use the following grading scale to assign a letter grade to a student. Test Score Letter Grade 80 - 100 A 70 - 79 B 60 69 C 50 - 59 0- 49 F Your program must have an array of string objects to hold the student names and an array of int to hold the student scores. Let the teacher determines the number of students and ask the teacher to enter the information for each student. Your program should have the following programmer-defined functions: getInput () - to read the students name and scores from user getGrade () - to determine the letter grade corresponding to the score getReport () - to determine the maximum, minimum, average and standard deviation of the scores Display an error message if the teacher enter mark below 0 or above 100, and keep asking for a valid value. The program should also be capable of…arrow_forwardPart A: Setup your Business 1. Create a new Java file called ITSC1212Lab13.java: a. Make sure you have a main method 2. Start by deciding the following and putting them into your file as comments: a. The name of your food service (if in doubt, just add your name and add something to the end like "Deli" or "Pizza Shack" or "Food Cart" - note that it should be the kind of service that aligns with the food you want to serve... Example: // "Dr. Wilson's Trini Delights" b. 10 products that you'll have on your menu. Example: // 1) chicken roti, 2) doubles, 3) pelau, 4) aloo pie, 5) rum punch ... You can go over 10 if you want, but don't go nuts. 3. Set up your application. Page 1 of 4 a. Include the code to prompt the user for their name and then greet them by their name. You should know how to do this, but if you don't, here's the code. Don't copy it, as that may not work. Type it in. Then test until everything works nicely. I import java.util.*; I Scanner console = new Scanner (System.in);…arrow_forward
- 3. Randomly generate a number in range [1, 12]. Map this number to a season: if the number is 3, 4, or 5, map it to “Spring", if the number is 6, 7, or 8, map it to "Summer", if the number is 9, 10, or 11, map it to "Fall", and if the number 12, 1, or 2, map it to "Winter". Display season namearrow_forwardManhattan skyline def manhattan_skyline(towers):This classic problem in computational geometry (essentially, geometry that can be done using only integer arithmetic; yes, that is an actual thing) is best illustrated by pictures and animations such as those on the page "The Skyline problem", so you can first check that it out to get an idea of what is going on. Given a list of rectangular towers as tuples (s, e, h) where s and e are the start and end x-coordinates (satisfying e>s) and h is the height of that tower, compute and return the total visible area of the towers, being careful not to double count two or more towers that are partially overlapping. All towers share the same flat ground baseline at the height. The classic solution illustrates the important sweep line technique that starts by creating a list of precisely those x-coordinate values where something relevant to the problem takes place. In this problem, the relevant x-coordinates are those where some tower either…arrow_forwardPalindrome Checkercreate a JavaScript program that checks if phrasesentered by the user are palindromes. A palindrome is a word, number, phrase, or other sequence of characters which reads the same backward as forward, such as “SIR”,“raceBIKE”, “Never odd or even”, “20/1/20”. The program should prompt the user to typein a phrase that is at least three characters long, and then tell the user whether the phrasewas a palindrome. Note, the decision should be based solely on letters and numericaldigits, and so it should not consider other characters, such as spaces or exclamationmarks, even though these might be entered by the user. when checking palindromes.A. Select your test data with care. Both palindromes and non-palindromes would be included in this. Provide examples that are text, numeric, and mixed; ignore any additional characters and spaces; andB. Ask the user for the word and then read their input. To verify that their input string has been read correctly, test this by displaying…arrow_forward
- Write a statement that will copy the string “Beethoven” to the array composer.arrow_forward(1) Prompt the user to input five pairs of numbers: A player's jersey number (0 - 99) and the player's rating (1 - 9). Store the jersey numbers in one int array and the ratings in another int array. Output these arrays (i.e., output the roster). (2) Implement a menu of options for a user to modify the roster. Each option is represented by a single character. The program initially outputs the menu, and outputs the menu after a user chooses an option. The program ends when the user chooses the option to Quit. For this step, the other options do nothing (3) Implement the "Output roster" menu option. (4) Implement the "Update player rating" menu option. Prompt the user for a player's jersey number. Prompt again for a new rating for the player, and then change that player's rating. (5) Implement the "Output players above a rating" menu option. Prompt the user for a rating. Print the jersey number and rating for all players with ratings above the entered value. (6) Implement the "Replace…arrow_forwardName format: You must use String object and not StringBuffer or StringBuilder. Many documents use a specific format for a person's name. Write a program that take one Line as an input. Example: Scanner input = new Scanner(System.in); System.out.println(“Enter firstName middleName lastName separated by at least one blank, It may have more than one blank separating firstName middleName lastName."); Input sample : Pat Silly Doe || Note these are separated by at least one blank. String line = input.nextLine() Ex: If the input is: Pat Silly Doe the output is: Doe, P.S. If the input has the form: firstName lastName the output is: lastName, firstInitial. Ex: If the input is: Julia Clark the output is: Clark, J. Please submit the .java source file and the sample run in a text file. Thanksarrow_forward
- I need answer within 20 minutes please please with my best wishesarrow_forwardPlanets = [‘Mercury’, ‘Venus’, ‘Earth’, ‘Mars’, ‘Jupiter’, ‘Saturn’, ‘Uranus’, ‘Neptune’] Use a loop and print out the name of the planet with the shortest amount of characters.arrow_forwardI'm completely confused and don't even know where to begin.arrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTProgramming with Microsoft Visual Basic 2017Computer ScienceISBN:9781337102124Author:Diane ZakPublisher:Cengage LearningMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,
- Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage