Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello, i am taking a into java programming class and i am having trouble with this HW. I am having trouble with the count how

Hello, i am taking a into java programming class and i am having trouble with this HW. I am having trouble with the count how many even and odd numbers are entered part. My code so far is down below. If anyone could help me that would be great. I have been trying to figure this out for over 2 hours and nothing is working. Thank you in advance.

Math Tool

As a software developer, you have received a new requirement from an Elementary School to develop a software to help kids to learn about whole number concepts, such as odd numbers, even numbers, find the greatest number and compute the average.

The Elementary School wants you to build a program that prompts the user to enter his/her name (Student name) and to enter a series of whole numbers.

Thus, your program will receive the following information:

Student name Whole numbers entered at the keyboard.

Note: The Student will enter 99 to finish entries and exit the program.

The program then outputs the following information:

Student name

A count of how many numbers were entered

A count of how many even numbers were entered

A count of how many odd numbers were entered.

The sum of the numbers entered.

The average of the numbers entered.

The sum of the odd numbers entered.

The average of the odd numbers.

The sum of the even numbers entered.

The average of the even numbers entered.

The largest odd number entered.

The largest even number entered. Please refer to the Sample Output file for full details of what the program should look like when it runs.

import java.util.Scanner; public class WholeNumbers {

/** * @param args the command line arguments */ public static void main(String[] args) { final int SENTINEL = 99; int nNum; int nSum = 0; int nCount = 0; int nEven = 0; int nOdd = 0; int nSumE = 0; int nSumO = 0; double dAverage = 0; Scanner input = new Scanner(System.in); System.out.print("Enter your name: "); String name = input.nextLine(); System.out.print("Please enter a series of whole number integers. " + "Enter 99 to finish. "); nNum = input.nextInt(); while (nNum !=SENTINEL){ if(nNum >0){ nSum = nSum + nNum; nCount = nCount + 1; } else System.out.println("You entered an invalid number "); System.out.print("Re-enter an integer: "); nNum = input.nextInt(); } dAverage = (double)nSum/nCount; System.out.println("Student name: " + name); System.out.println("Amount of integers entered: " + nCount); System.out.println("Amount of even integers entered: " + nEven); System.out.println("Amount of odd integers entered: " + nOdd); System.out.println("Sum of integers entered: " + nSum); System.out.println("Average of integers entered: " + dAverage); System.out.println("Sum of odd numbers: " + nSumO); // TODO code application logic here } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems For Advanced Applications 15th International Conference Dasfaa 2010 International Workshops Gdm Benchmarx Mcis Snsmw Diew Udm Tsukuba Japan April 2010 Revised Selected Papers Lncs 6193

Authors: Masatoshi Yoshikawa ,Xiaofeng Meng ,Takayuki Yumoto ,Qiang Ma ,Lifeng Sun ,Chiemi Watanabe

2010th Edition

3642145884, 978-3642145889

More Books

Students also viewed these Databases questions