subject

Accumulating Totals in a Loop

Summary

In this lab, you add a loop and the statements that make up the loop body to a Java program that is provided. When completed, the program should calculate two totals: the number of left-handed people and the number of right-handed people in your class. Your loop should execute until the user enters the character X instead of L for left-handed or R for right-handed.

The inputs for this program are as follows: R, R, R, L, L, L, R, L, R, R, L, X

Variables have been declared for you, and the input and output statements have been written.

Instructions:

Ensure the file named LeftOrRight. java is open.

Write a loop and a loop body that allows you to calculate a total of left-handed and right-handed people in your class.

Execute the program by clicking Run and using the data listed above and verify that the output is correct.

// LeftOrRight. java - This program calculates the total number of left-handed and right-handed

// students in a class.

// Input: L for left-handed; R for right handed; X to quit.

// Output: Prints the number of left-handed students and the number of right-handed students.

import java. util. Scanner;

public class LeftOrRight

{

public static void main(String args[])

{

Scanner s = new Scanner(System. in);

String leftOrRight = ""; // L or R for one student.

int rightTotal = 0; // Number of right-handed students.

int leftTotal = 0; // Number of left-handed students.

// This is the work done in the housekeeping() method

System. out. println("Enter L if you are left-handed, R if you are right-handed or X to quit.");

leftOrRight = s. nextLine();

// This is the work done in the detailLoop() method

// Write your loop here.

// This is the work done in the endOfJob() method

// Output number of left or right-handed students.

System. out. println("Number of left-handed students: " + leftTotal);

System. out. println("Number of right-handed students: " + rightTotal);

System. exit(0);

} // End of main() method.

} // End of LeftOrRight class.

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 21.06.2019 22:00
Which of the following statements correctly identifies a problem with sanitization methods? a. methods are not available to remove data ensuring that unauthorized personnel cannot retrieve data.b. even fully incinerated media can offer extractable data.c. personnel can perform sanitization steps improperly.d. stored data is physically etched into the media.
Answers: 1
question
Computers and Technology, 22.06.2019 23:30
What are some ways to use a range name in a formula? check all that apply. in the defined names group, click use in formula, and then select the desired name. begin typing the name in the formula, select a name from the autocomplete list, and use the arrow keys and tab key to enter the name in the formula. begin typing the formula, and then click and drag with the mouse to select the cells to include in the formula. right-click one of the cells in the range. click formula options, and use the dialog box to add the name.
Answers: 1
question
Computers and Technology, 23.06.2019 18:40
Johnson enterprises uses a computer to handle its sales invoices. lately, business has been so good that it takes an extra 3 hours per night, plus every third saturday, to keep up with the volume of sales invoices. management is considering updating its computer with a faster model that would eliminate all of the overtime processing.
Answers: 2
question
Computers and Technology, 23.06.2019 22:00
Take a critical look at three gui applications you have used—for example, a spreadsheet, a word-processing program, and a game. describe how well each conforms to the gui design guidelines listed in this chapter.
Answers: 3
You know the right answer?
Accumulating Totals in a Loop

Summary

In this lab, you add a loop and the...
Questions
question
Mathematics, 17.09.2019 20:30
Questions on the website: 13722363