PRG420 Week 2 Individual Assignment Coding a Program Containing if-then and switch

Availability: In stock

Regular Price: $10.00

Special Price: $7.00

OR

PRG420 Week 2 Individual Assignment Coding a Program Containing if-then and switch Java Source

Double click on above image to view full picture

Zoom Out
Zoom In

More Views

Quick Overview

PRG420 Week 2 Individual Assignment Coding a Program Containing if-then and switch


Individual: Coding a Program Containing if-then and switch


Includes Working Java Build and Program File and Explanation of Code
Resources:  Week Two Coding Assignment Zip File (starter code for this assignment that includes placeholders), and Week Two Recommended Activity Zip File (examples of how to code a switch statement, an if-then-else statement, and how to construct a string to display text onscreen).
For this assignment, you will apply what you learned in analyzing Java™ code so far in this course by writing your own Java™ program.
The Java™ program you write should do the following:
• Accept user input that represents the number of sides in a polygon. Note: The code to do this is already written for you.
• If input value is not between 3 and 5, display an informative error message
• If input value is between 3 and 5, use a switch statement to display a message that identifies the correct polygon based on the number of sides matching the input number (e.g., triangle, rectangle, or polygon)
Complete this assignment by doing the following:
1. Download and unzip the linked Week Two Coding Assignment Zip File.
2. Read the file carefully, especially the explanatory comments of what the existing code does.
3. Add your name and the date in the multi-line comment header.
4. Refer to the following linked Week Two Recommended Activity Zip File to see examples of how to code all of the Java™ statements (i.e., switch, println(), and if-then-else) you will need to write to complete this assignment.
5. Replace the following lines with Java code as directed in the file:
• LINE 1
• LINE 2
6. Comment each line of code you add to explain what you intend the code to do.
7. Test and modify your Java™ program until it runs without errors and produces the results as described above.
Note: Refer to this week's analyzing code assignment if you need help.
Submit your Java source (.java) code file using the Assignment Files tab.


/**********************************************************************
* Program: PRG/420 Week 2
* Purpose: Week 2 Coding Assignment
* Programmer: Iam A. Student
* Class: PRG/420 PRG420 PRG 420
* Creation Date: 10/18/17
*********************************************************************
*
**********************************************************************
* Program Summary: This program demonstrates these basic Java concepts:
* - defining variables of different types
* - if-then and if-then-else logic
* - constructing a string to display onscreen
* - switch logic
*
* To finish assignment, you will add code where indicated. The
* behavior of your completed assignment should be to accept an input
* value for the number of sides of a two-dimensional figure. Based on that value,
* your code should display the type of figure that corresponds to the number of polygon angles
* indicated (3=triangle, 4=rectangle, etc.)
*
* Here are the specific requirements:
*
* After the user types in a value from 3 to 5 inclusive (i.e., 3, 4, or 5):
*
* 1. Your code determines whether the input value is out of range (less than 3 or more than 5)
* and, if so, displays a meaningful error message on the screen and ends the program.
*
* 2. Because you will be comparing a single expression (the input value) to multiple constants (3, 4, and 5),
* your code should use a switch statement to display the following message onscreen:
*
* If user inputs 3, onscreen message should say "A triangle has 3 sides."
* If user inputs 4, onscreen message should say "A rectangle has 4 sides."
* If user inputs 5, onscreen message should see "A pentagon has 5 sides."
*
* 3. Be sure to test your program. This means running your program multiple
* times with test values 3, 4, 5, as well as at least two values that fall outside that range
* (one lower than the lowest and one higher than the highest) and making sure
* that the correct message displays for each value you input. Also be sure
* that running your program does not cause any compiler errors.
***********************************************************************/


package week2codingassignment;


import java.util.Scanner;


public class PRG420Week2_CodingAssignment {
public static void main(String[] args) {
String userInputStringOfAngles; // Declare a variable of type String to capture user input
int numberOfAngles; // Declare a variable of type int to hold the converted user input
Scanner myInputScannerInstance = new Scanner(System.in); // Recognize the keyboard
System.out.print("Please type the integer 3, 4, or 5 and then press Enter: "); // Prompt the user
userInputStringOfAngles= myInputScannerInstance.next(); // Capture user input as string
numberOfAngles = Integer.parseInt(userInputStringOfAngles); // Convert the string to a number in case this will be useful later
// LINE 1. CODE TO DETERMINE WHETHER USER INPUT IS OUT OF BOUNDS GOES HERE
// LINE 2. SWITCH CODE TO PRINT CORRECT "SHAPE" MESSAGE BASED ON USER INPUT GOES HERE
}
}

Regular Price: $10.00

Special Price: $7.00

Details

PRG420 Week 2 Individual Assignment Coding a Program Containing if-then and switch

Individual: Coding a Program Containing if-then and switch

Includes Working Java Build and Program File and Explanation of Code
Resources:  Week Two Coding Assignment Zip File (starter code for this assignment that includes placeholders), and Week Two Recommended Activity Zip File (examples of how to code a switch statement, an if-then-else statement, and how to construct a string to display text onscreen).
For this assignment, you will apply what you learned in analyzing Java™ code so far in this course by writing your own Java™ program.
The Java™ program you write should do the following:
• Accept user input that represents the number of sides in a polygon. Note: The code to do this is already written for you.
• If input value is not between 3 and 5, display an informative error message
• If input value is between 3 and 5, use a switch statement to display a message that identifies the correct polygon based on the number of sides matching the input number (e.g., triangle, rectangle, or polygon)
Complete this assignment by doing the following:
1. Download and unzip the linked Week Two Coding Assignment Zip File.
2. Read the file carefully, especially the explanatory comments of what the existing code does.
3. Add your name and the date in the multi-line comment header.
4. Refer to the following linked Week Two Recommended Activity Zip File to see examples of how to code all of the Java™ statements (i.e., switch, println(), and if-then-else) you will need to write to complete this assignment.
5. Replace the following lines with Java code as directed in the file:
• LINE 1
• LINE 2
6. Comment each line of code you add to explain what you intend the code to do.
7. Test and modify your Java™ program until it runs without errors and produces the results as described above.
Note: Refer to this week's analyzing code assignment if you need help.
Submit your Java source (.java) code file using the Assignment Files tab.

/**********************************************************************
* Program: PRG/420 Week 2
* Purpose: Week 2 Coding Assignment
* Programmer: Iam A. Student
* Class: PRG/420 PRG420 PRG 420
* Creation Date: 10/18/17
*********************************************************************
*
**********************************************************************
* Program Summary: This program demonstrates these basic Java concepts:
* - defining variables of different types
* - if-then and if-then-else logic
* - constructing a string to display onscreen
* - switch logic
*
* To finish assignment, you will add code where indicated. The
* behavior of your completed assignment should be to accept an input
* value for the number of sides of a two-dimensional figure. Based on that value,
* your code should display the type of figure that corresponds to the number of polygon angles
* indicated (3=triangle, 4=rectangle, etc.)
*
* Here are the specific requirements:
*
* After the user types in a value from 3 to 5 inclusive (i.e., 3, 4, or 5):
*
* 1. Your code determines whether the input value is out of range (less than 3 or more than 5)
* and, if so, displays a meaningful error message on the screen and ends the program.
*
* 2. Because you will be comparing a single expression (the input value) to multiple constants (3, 4, and 5),
* your code should use a switch statement to display the following message onscreen:
*
* If user inputs 3, onscreen message should say "A triangle has 3 sides."
* If user inputs 4, onscreen message should say "A rectangle has 4 sides."
* If user inputs 5, onscreen message should see "A pentagon has 5 sides."
*
* 3. Be sure to test your program. This means running your program multiple
* times with test values 3, 4, 5, as well as at least two values that fall outside that range
* (one lower than the lowest and one higher than the highest) and making sure
* that the correct message displays for each value you input. Also be sure
* that running your program does not cause any compiler errors.
***********************************************************************/

package week2codingassignment;

import java.util.Scanner;

public class PRG420Week2_CodingAssignment {
public static void main(String[] args) {
String userInputStringOfAngles; // Declare a variable of type String to capture user input
int numberOfAngles; // Declare a variable of type int to hold the converted user input
Scanner myInputScannerInstance = new Scanner(System.in); // Recognize the keyboard
System.out.print("Please type the integer 3, 4, or 5 and then press Enter: "); // Prompt the user
userInputStringOfAngles= myInputScannerInstance.next(); // Capture user input as string
numberOfAngles = Integer.parseInt(userInputStringOfAngles); // Convert the string to a number in case this will be useful later
// LINE 1. CODE TO DETERMINE WHETHER USER INPUT IS OUT OF BOUNDS GOES HERE
// LINE 2. SWITCH CODE TO PRINT CORRECT "SHAPE" MESSAGE BASED ON USER INPUT GOES HERE
}
}

Product Tags

Use spaces to separate tags. Use single quotes (') for phrases.