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

Hangman Game Using Arrays
Homework Solution
$33.00
Computer Science
Game Development
Arrays
Programming
Java
Words
Codes
Letters
Hangman
Characters
Guessing
Input
Output
Drawing
Explanation For Java Classes
Homework Solution
$30.00
Java
Programming
Computer Science
Codes
Classes
Inheritance
Comparator
Binary Matrix
Labels
Edges
Tree
Strings
LinkedList
Integers
Nodes
Temporary Storage
Statements
Variables
Species
HashSet
Iterator
Java Program For Longest Path in Graph
Homework Solution
$40.00
Java
Programming
Codes
Algorithms
Graph Theory
Classes
Nodes
Edges
Paths
Distances
Loops
Statements
Variables
Input Files
Output Files
HashMap
Array
Integers
Methods
Java Program And UML Diagram For Divers
Homework Solution
$20.00
Java
Programming
Computer Science
Coding
Divers
Testers
UML Diagram
Methods
Loops
Statements
Average Scores
Variables
Input Files
Output Files
Contest
Winner
Records
Data Sets
Maze Problem in Java
Homework Solution
$50.00
Java
Programming
Codes
Algorithms
Maze Problem
Classes
Constructor
Stack
Positions
Points
Push
Pop
Symbols
Statements
Variables
Rows
Columns
Strings
Integers
Commands
Pseudo-Code
Get help from a qualified tutor
Live Chats