Computers and Technology

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.

answer
Answers: 3

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 05:30, xbeatdroperzx
Gerard is currently working as an entry-level customer support technician, but he would like to someday become a software developer. what is the best first step to understand what he should do? ask his manager for a new job or at least a job recommendation study graphic design in order to obtain the necessary skills use career resources to investigate what skills and education are required work part-time as an entry-level web developer question 13 (true/false worth 6 points) (08.03 lc) career resources are used to explore career options and find career information. true false question 14(multiple choice worth 6 points) (08.01 mc) classify the following skills: writing html code, evaluating color theory, using design principles. hard skills interpersonal skills people skills soft skills question 15 (true/false worth 6 points) (08.03 lc) a mentor is a person who is advised, trained, or counseled by a trusted mentee. true false
Answers: 2
image
Computers and Technology, 23.06.2019 03:50, nakeytrag
Iam a bacterium. i cause stomach cramps and diarrhea. i am caused by eating rotten foodssuch as chicken, fish, or eggs. sometimes turtles carry my bacteria. what am i?
Answers: 2
image
Computers and Technology, 23.06.2019 04:10, cvbnkifdfg
2pointswho was mikhail gorbachev? oa. a russian leader who opposed a coupob. a polish leader who founded the labor union "solidarityoc. a soviet leader who called for a closer relationship with the unitedstates, economic reform, and a more open societyd. a soviet leader who called for more oppression in the soviet union
Answers: 3
image
Computers and Technology, 23.06.2019 04:31, manlyman31
Selling a product through an electronic medium is
Answers: 1
Do you know the correct answer?
Accumulating Totals in a Loop

Summary

In this lab, you add a loop and the...

Questions in other subjects:

Konu
Mathematics, 17.04.2020 00:07