Write a fragment of code that will test whether an integer variable score contains a valid test score. Valid test scores are in the range 0 to 100.
Program plan:
- • Include necessary header files.
- • Define the class “Fragments”.
- • Define the “main()” function.
- ○ Declare and initialize the necessary variables.
- ○ The “if” statement check the condition.
- ■ True, print the valid statement.
- ○ Otherwise, print the invalid statement.
Program to display the valid test score.
Explanation of Solution
Program:
//Import necessary header files
import java.util.*;
//Define the class
class Fragments
{
//Define the main() method
public static void main(String[] args)
{
//Initialize the variable
int score = 10;
//Check the condition
if( score >= 0 && score <= 100 )
{
//True, print the statement
System.out.println("The score " + score + " is valid.");
}
//Otherwise
else
{
//Print the statement
System.out.println("The score " + score + " is not valid.");
}
}
}
Output:
The score 10 is valid.
Want to see more full solutions like this?
Chapter 3 Solutions
Java: An Introduction to Problem Solving and Programming (7th Edition)
Additional Engineering Textbook Solutions
Web Development and Design Foundations with HTML5 (9th Edition) (What's New in Computer Science)
Starting Out with C++: Early Objects
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Starting Out With Visual Basic (7th Edition)
Database Concepts (8th Edition)
- What will be the value of x after the following code is executed? int x = 0; while (x < 50) { x += 20; } 50 20 40 60arrow_forwardThis assignment is to modify the rock-paper-scissors game f. As before, each of twoplayers enters P, R, or S. The program will announce the winner and the basis for determining thewinner: Paper covers rock, Rock breaks scissors, Scissors cut paper, or Draw, nobody wins.The players must be able to enter either upper-case or lower-case letters.There are two major changes. First, you will need to create an enumeration called choices thathas three values, ROCK, PAPER, and SCISSORS. You should then use the typedef keyword to createa type for this enumeration named Choice. When you read the player's choice in your getThrowfunction, you will need to return a Choice for that player rather than a char as before. This makesit so that the only part of the program that deals with character type variables is the getThrowfunction; the rest of your program should always use variables of the enumerated Choice type. Thismeans that your checkWinner function will take two Choices as parameters…arrow_forwardPrint "user_num1 is negative." if user_num1 is less than 0. End with newline. Assign user_num2 with 1 if user_num2 is greater than 12. Otherwise, print "user_num2 is less than or equal to 12.". End with newline. My code: user_num1 = int(input())user_num2 = int(input()) if user_num1 < 0: print("user_num1 is negative.") if user_num2 > 12: user_num2 == 1 else: print("user_num2 is less than or equal to 12.") print('user_num2 is', user_num2) When the input is 0 and 13 my output for user_num2 is 13 and it should be 1. I don't know what I'm doing wrong.arrow_forward
- options same for each onearrow_forward3. int x =9 ;display the address of the variable x? Answer:arrow_forwardConsider this code: "int s = 20; int t = s++ + --s;". What are the values of s and t? A. s is 19 and t is 38 B. s is 20 and t is 38 C. s is 20 and t cannot be determined D. s is 19 and t is 39 E. s is 20 and t is 39arrow_forward
- Kindly add Comments for this 03 assignmentarrow_forwardA magic date is one when written in the following format, the month times the date equals the year e.g. 6/10/60. Write code that figures out if a user entered date is a magic date. The dates must be between 1 - 31, inclusive and the months between 1 - 12, inclusive. Let the user know whether they entered a magic date. If the input parameters are not valid, return false. examples: magicDate(6, 10, 60) -> truemagicDate(50, 12, 600) -> falsearrow_forwardJAVA:arrow_forward
- Please help me to code this Python It is High/Low Card Game The pyex is example of outputarrow_forwardWrite code that iterates while userNum is less than 12. Each iteration: Put userNum to output. Then, put "/" to output. Then, assign userNum with userNum multiplied by 3.arrow_forwardMethod: sumOdds(value: int): This method will sum all the odd values from 1 upto the value passed by parameter. This will display the sumas an integer value.Method: characterCount(phrase: str): This method will count the number of characters in the phrase that is passed by parameter. You cannot useany built in function ( ie len() ) and must use a looping activity. This should display the number of characters inthe phrase as an integerMethod: multiplicationPractice(): This method is to practice simple multiplication problems. The program should randomly generate twonumbers from 1-10 for the user to multiply. It should display the multiplication problem and allow the user toanswer the problem. It should display if the user got the answer correct or incorrect. The activity shouldcontinue until the user has gotten 3 different practice problems correct.Method: order(value1: int, value2: int, value3: int): This method is to order the 3 passed value from least to greatest. It should display…arrow_forward
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,