Question

The following Java program must:

1. Print your name and Project 2 followed by a blank line.
2. Prompt the user to enter 3 integers and read the integers.
3. Prompt the user to enter a character and read the character.
4. Print the output according to the following:

If the character read is ____, output
‘a’ - Print the largest integer value read
‘b’ - Print how many of the integers are even
‘c’ - Print how many of the integers have the same value
not ‘a’, ‘b’ or - Print an error message describing the problem

5. Print “Program Complete”

Hint:
To read the character, get the input as a String and then get the first character out of the String.

Requirements:
1. Your program should run through only one time and use one set of input. There are no loops.
2. The character read must be tested the minimum number of times. This means that if the value is ‘a’, then it should not be tested for ‘b’, ‘c’, etc.
3. Do not use String comparison. You must test for a single character.
4. Format your output for readability. Include text, blanks, etc.
5. Use meaningful variables names. Avoid n1, n2, etc.
6. Put blanks around the variables and operators in the code just like words in a sentence.
7. Document your program at the beginning of the file with your name and a description of the problem.
8. Test your program with different inputs to make sure it works correctly.
9. If you are using an IDE other than TextPad, do not use a package. Comment it out if required.

Restrictions:
1. Use only the following type of statements.
a. sequence statements (declaration, assignment, input, output)
b. if-else statements
2. Do not use any other types of statements. Do not use the Math class.

Solution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

import java.util.Scanner;

public class Project2 {

public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
int one, two, three;
char in;
System.out.println("Name Project2\n");
System.out.print("Please enter in 3 integers: ");
one = input.nextInt();
two = input.nextInt();
three = input.nextInt();

System.out.print("Please enter in 1 character");
in = input.next().charAt(0);

if(in == 'a')
{
if(one > two && one > three)
System.out.println("Greatest integer = " + one);
else if(two > one && two > three)
System.out.println("Greatest integer = " + two);
else if(three >= two && three >= one)
System.out.println("Greatest integer = " + three);
}
else if(in == 'b')
{...

This is only a preview of the solution. Please use the purchase button to see the entire solution

Related Homework Solutions

Acme Corporation Problems Using Java
Homework Solution
$30.00
Java
Programming
Computer Science
Acme Corporation
Employees
Hourly Rate
Salaries
Algorithms
Volunteers
Classes
Inheritance
Source Files
Diagrams
Java Programming Problems
Homework Solution
$13.00
Computer Science
Java Programming
Numbers
Methods
Boolean Type
Input
Output
Multiples
Statements
Variables
Algorithms
Java Programming Problems
Homework Solution
$75.00
Computer Science
Java Programming
Integers
Strings
Algorithms
Codes
Constructor
Sensors
Parameters
Scaling
Critical Evaluation
Compile-Time Errors
Class Money in Java
Homework Solution
$20.00
Java
Programming
Coding
Money
UML Diagram
Computer Science
Dollars
Cents
Parameters
Statements
Methods
Strings
Integers
Finance
Arithmetic Operations
Java Programming Problems
Homework Solution
$15.00
Java
Computer Science
Programming
Algorithms
Coding
Prime Factors
Run Length Encoding
Strings
Decimals
Flag Characters
Conversions
Simple & Compound Interest Using Java
Homework Solution
$65.00
Java
Programming
Codes
Algorithms
Computer Science
Statements
Variables
Loops
Input
Output
Integers
Strings
Simple Interest
Compound Interest
Money
Finance
Annual Rates
Calculations
Functions
Screen Messages
Get help from a qualified tutor
Live Chats