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, 22.06.2019 11:00
How does a policy manual an organization? a. it boost productivity. b. it create awareness in employees about the organization’s values. c. it employees achieve targets. d. it safeguards the organization from liabilities.
Answers: 1
question
Computers and Technology, 22.06.2019 15:00
Hyperactive media sales has 10 windows 7 laptop computers used by sales-people in the organization. each laptop computer has several customized applications that are used during the sales process as well as customer relationship management software. all of the applications on the laptops are difficult to configure and have large data files. if all of the laptops have current hardware, what is the easiest way to install windows 10 on them?
Answers: 1
question
Computers and Technology, 22.06.2019 22:40
Least square fit to polynomial write a function leastsquarefit3pol that solves a linear system of equations to find a least squares fit of a third order polynomial to an experimental data set given as two row arrays. the function leastsquarefit3pol must explicitly solve a set of linear equations and cannot use polyfit. there should be no restriction on the size of the problem that can be solved.
Answers: 1
question
Computers and Technology, 25.06.2019 10:30
Tools used in a particular career depend on the tasks performed. true or false
Answers: 1
You know the right answer?
Accumulating Totals in a Loop

Summary

In this lab, you add a loop and the...
Questions
question
Mathematics, 04.09.2020 19:01
question
Health, 04.09.2020 19:01
question
SAT, 04.09.2020 19:01
Questions on the website: 13722359