CHALLENGE 3.17.1: Conditional expression: Print negative or positive. ACTIVITY Create a conditional expression that evaluates to string "negative" if userVal is less than 0, and "non-negative" otherwise. Ex: If userVal is -9, output is: -9 is negative 1 #include 2 #include 1 test 3 using namespace std; passed 4 5 int main ) { string condStr; int userVal; 6 All tests 7 passed 8 cin userVal; 9 10 /* Your solution goes here */; condStr 11 12
Q: Write declarations to declare each variable to have the specified type and initial value: Problem:…
A: Variable declaration: A variable is a name that is the name given to a memory location in computer…
Q: Jump to level 1 Find and fix the error in the if-else statement. 1 import java.util.Scanner; 2 3…
A: Given Code: import java.util.Scanner; public class NumberChecker { public static void main(String[]…
Q: What will be output to the screen when the following code is executed: def PrintMe(x): try: return…
A: The problem is based on the basics of functions in python programming language.
Q: Write multiple if statements:If carYear is before 1967, print "Probably has few safety features."…
A: Multiple if-statement includes many if-statements. In multiple if-statement, one or more…
Q: Write code in JavaScript by following the instructions given below: • A confirmation dialog box…
A: required: to create a javascript application according to instructions. all the code with…
Q: CHALLENGE ACTIVITY 422784.2543518.qx3zqy? Jump to level 1 Write an if-else statement for the…
A: If user Tickets is less than 8, execute award Points = 1. Else, execute award Points = User Tickets.
Q: Question 3: (20 marks) Given the following pieces of code, give their exact output with the tracing…
A: Steps Involved: a) Initializes static variable value = 102 Prints 102 Initializes num = 103 Prints…
Q: tenuse (a, b) sqrt (a*a + b*
A: Solution - In the given question, we have to find the correct answer among the given options.
Q: eate a class named as Integer by using a logical NOT operation that converts the positive number in…
A: import java.util.*;public class Main{ public static void main(String[] args) { Scanner sc=new…
Q: ex5-2.c Exercise 5.2 1 #define TRUE 1 #define FALSE O Collapse 3 short IsHoopy (int x) { short…
A: The output of the given program will be: 1 1 ping! pong!
Q: Use the class provided, TestOverloadCall printMax to print the highest of 33 and 89Call printMax to…
A: Program:public class TestOverload{ public static void main(String[] args) {…
Q: Write a Java program that prompts the user to enter a security code that matches a specific pattern.…
A: Thw java code is an given below : Java Code: import java.util.*;import java.io.*;import…
Q: Trace through the following code by sight (not putting it into a program). What would be displayed…
A: In this question, A piece of code is given of C# That code follows the recursion Given: private int…
Q: CHALLENGE ACTIVITY 422784.2543518.qx3zq7 Jump to level 1 Write an if-else statement for the…
A: The answer for the above question is given in the below steps.
Q: Create a JavaFX application that lets the user play the game of rock, paper, scissors against the…
A: Actually, Java is a high level programming language... And also object oriented .It. Is a platform…
Q: 18.14 Define a method named coinFlip that takes a Random object and returns "Heads" or "Tails"…
A: import java.util.Scanner;import java.util.Random; public class LabProgram { /* Define your method…
Q: Program10.java 1. Write a Java program that prompts the user to enter a security code that matches…
A: I provide the code along with output and code screenshot in Java
Q: Basic if-else expression. Jump to level 1 Write an expression that will cause the following code…
A: Solution: Algorithm Step 1: Input age from the user. Step 2: If the age is less than or equal to…
Q: 1. Assume x is an int which has been declared and assigned a valid value. x guaranteed to change…
A: The given code is used the multiple if statement, in which control is evaluate both if statement…
Q: CHALLENGE 2.1.3: Basic if-else. ACTIVITY 422784.2543518.qx3zqy7 Jump to level 1 Write an if-else…
A: The code implementation in Java is given below. Algorithm: Begin. Prompt the user to input the…
Q: After following statements have executed, what will be appear on the output window int i=10, a=0;…
A: Please find the answer below :
Q: Lab 9 C balance the same, y, n, why? class CheckingAct { . . . . private int…
A: There is only call by value in java, not call by reference. Thus if we try to change value of formal…
Q: Write multiple if statements: If carYear is before 1967, print "Probably has few safety features."…
A: According to the information given:- We have to follow the instruction mentioned in order to get…
Q: Write an if-else statement for the following: If userTickets is less than 8, execute awardPoints =…
A: The main advantages of high-level languages are:- - human-friendly - machine-independent - easy to…
Q: Write code in JavaScript by following the instructions given below: • A confirmation dialog box…
A: Coding is done in JAVASCRIPT programming language Firstly, onload method is used to call the…
Q: IO class provides input and output through _________
A: Question. IO class provides input and output through _________
Q: 12,13,14, 15 public static void m { int c = 12; while( { System.out.
A: Below the output of the following program
Q: de to show a dialog box which says “Wlcome to Deptartment of CSE, Leading Universit
A: I have given code to print statement in dialogBox.
Q: the second cout statement executed? int x; void summer (int&, int); void fall(int, int&); int main()…
A: The correct option is option b which is -58
Q: Use a Bootstrap class to center the following text: Hello World!
A: Ans : Use a Bootstrap class to center the following text: <p class="text-center">Hello…
Q: Task 3 Implement the design of the Passenger class so that the following output is produced: The…
A: Given:
Q: Consider the following code: public class Banker { private BankAccount[] accounts; public…
A: Consider the following code:public class Banker {private BankAccount[] accounts; public…
Q: ation error. 2. Determine the output if that statement is removed. class A { public void test() {…
A: The statement that causes the compilation error. Determine the output if that statement is…
Q: CHALLENGE ACTIVITY 422784.2543518.qx3zqy7 Jump to level 1 Write an if-else statement for the…
A: #include <iostream>using namespace std; int main(){ int awardPoints; int userTickets;…
Q: Write a console application that prints the next 20 leap years. A leap year is a year in which an…
A: Programming is a way to instruct the computer devices to operate. Every computer needs a set of…
Q: 1. Design a class, CipherDriver, that uses a repeating key to encode and decode a message read from…
A: import java.io.BufferedReader;import java.io.InputStreamReader;import java.util.ArrayDeque;import…
Q: char xusername[10]; char xbankname[10]; int xaccountnum[4]; int xcardnum[14]; int…
A: Flow chart is a step by step process of the program which is represented using different symbols and…
Q: The result of the following lines: const int myNumber = 10; myNumber = 13;…
A: The given C# code has: One constant variable "myNumber" which initializes as 10. The value of…
Q: Write multiple if statements: If carYear is before 1967, print "Probably has few safety features."…
A: 1. Taking User input for the carYear variable. 2. Writing multiple if statements as per given…
Q: Task - 3 Write the CheckingAccount class so that the following code generates the output below:…
A: 1) Below is program that includes CheckingAccount class to generate the output It defines Account…
Q: #include using namespace std; class A { private: int x; public: A(int _x) { x = _x; } int…
A: According to the question below the solution:
Q: Activity 3: Using the scanner class create a java code segment that will enable user interactions…
A: In this question, we are asked to write the java code using scanner class for the user input Syntax:…
Q: Q1. A script that can be used as a calculator with four major operations, i.e. “+-/*”. The script…
A: Algorithm: 1. Peruse Two Numbers2. Input Choice (1-Addition, 2-Subtraction, 3-Multiplication,…
Q: Predict the output? #include using namespace std; class ClassA { public:…
A: Question 3. Predict the output? #include<iostream> using namespace std; class ClassA {…
Q: CHALLENGE 2.1.3: Basic if-else. ACTIVITY 4227842543518.37 Jump to level 1 Write an if-else statement…
A: The answer is given below. Algorithm: Input value of userTickets. If userTickets less than 8 print…
Q: c++ A FastCritter moves twice as fast as a regular critter. When asked to move by n steps, it…
A: /////////////////////// criter.h file given in question ///////////////////////////////#ifndef…
Q: What is the output of the following code: #include class A { public: A() {} ~A()…
A: Here in this program throw is used which will always call terminate() to terminate the program. A…
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images
- 2.1.2: Basic if-else expression. Jump to level 1 Write an expression that will cause the following code to print "I am an adult" if the value of userAge is greater than 19. import java.util.Scanner; public class AgeChecker { public static void main (String [] args) { int userAge; Scanner scnr = new Scanner(System.in); userAge = scnr.nextInt(); // Program will be tested with values: 18, 19, 20, 21. if (userAge > 17) { System.out.println("I am a teenager"); } else { System.out.println("I am an adult"); } }}1. Replace the (????) with relevant code to make th eprogram function. Details about the code are given below:(Java as been used) a) This program creates a reference to a file in main() and passes the reference to countWords() countWords(), not main(), reads the file and displays Total lines Total words Average words per line */ package finalexamtakehome1; import java.io.*; /** * * @author sweetkim */ public class Finalexamtakehome1 { // public static void countWords(????) { int lineCount = 0; int wordCount = 0; while (????()) { String line = input.nextLine(); lineCount++; Scanner lineScan = new Scanner(line); while (????()) { String next = lineScan.next(); wordCount++; } } double averageWords = (double) wordCount / lineCount; System.out.println("Total lines = " + lineCount); System.out.println("Total words = " + wordCount); System.out.printf("Average words per line =…char xusername[10]; char xbankname[10]; int xaccountnum[4]; int xcardnum[14]; int xpass[4]; int xwalletnum[11]; int xOTP[4]; printf("Enjoy a range of our banking services including cash withdrawals and deposits, card and loan installment payments, bill payments, smart wallet recharge, and card-less services.\n\n\n"); printf("If you are bank staff press 1. \t\t\t If you are a customer press 2.\n"); int num;label0: scanf_s("%d", &num); if (num == 1) {//bank staff char bank_staff[10] = { "mahmoud" }; char xbank_staff[10]; int bank_pass[4] = { 5,5,5,5 }; int xbank_pass[4]; int doha = 0; labelinf1: printf("Enter your name.\n"); scanf_s("%s", xbank_staff, 10); if (strcmp(xbank_staff, bank_staff) == 0) { printf("Enter your password.\n"); scan_array(xbank_pass, 4); for (int i = 0; i < 4; i++) { if (xbank_pass[i] == bank_pass[i]) {…
- Write code that uses a std::map to create a food inventory. We will use a food's name as the key to store the corresponding quantity. Add the following information to the map: 1 Apple, 5 bananas, and 3 milk. Ask the user for the updated number of bananas in the inventory and update the map accordingly. Use the map to display the quantities of each item. #include <iostream> #include <map> int main() { int new_banana_count = 0; // TODO: Instantiate a std::map using its default constructor to represent a food inventory. // TODO: Add 1 Apple, 5 Bananas, and 3 Milk to the food inventory. std::cout << "Updated amount of bananas: "; std::cin >> new_banana_count; // TODO: Update banana count std::cout << "Number of apples: "; // TODO: Display number of apples std::cout << "\nNumber of bananas: "; // TODO: Display number of bananas std::cout << "\nNumber of milk: "; // TODO: Display number of milk return 0; }### welcome_assignment_answers### Input - All nine questions given in the assignment.### Output - The right answer for the specific question. def welcome_assignment_answers(question): #Students do not have to follow the skeleton for this assignment. #Another way to implement is using a "case" statements similar to C. if question == "Are encoding and encryption the same? - Yes/No": answer = "The student should type the answer here" elif question == "Is it possible to decrypt a message without a key? - Yes/No": answer = "The student should type the answer here" else: ### you should understand why this else case should be included ### what happens if there is a typo in one of the questions? ### maybe put something here to flag an issue and catch errors answer = "This is not my beautiful wife! This is not my beautiful car! How did I get here?" return(answer)# Complete all the questions. if __name__ == "__main__": #use this…### welcome_assignment_answers### Input - All nine questions given in the assignment.### Output - The right answer for the specific question. def welcome_assignment_answers(question): #Students do not have to follow the skeleton for this assignment. #Another way to implement is using a "case" statements similar to C. if question == "Are encoding and encryption the same? - Yes/No": answer = "The student should type the answer here" elif question == "Is it possible to decrypt a message without a key? - Yes/No": answer = "The student should type the answer here" else: ### you should understand why this else case should be included ### what happens if there is a typo in one of the questions? ### maybe put something here to flag an issue and catch errors answer = "This is not my beautiful wife! This is not my beautiful car! How did I get here?" return(answer)# Complete all the questions. if __name__ == "__main__": #use this…
- ### welcome_assignment_answers### Input - All nine questions given in the assignment.### Output - The right answer for the specific question. def welcome_assignment_answers(question): #Students do not have to follow the skeleton for this assignment. #Another way to implement is using a "case" statements similar to C. if question == "Are encoding and encryption the same? - Yes/No": answer = "The student should type the answer here" elif question == "Is it possible to decrypt a message without a key? - Yes/No": answer = "The student should type the answer here" else: ### you should understand why this else case should be included ### what happens if there is a typo in one of the questions? ### maybe put something here to flag an issue and catch errors answer = "This is not my beautiful wife! This is not my beautiful car! How did I get here?" return(answer)# Complete all the questions. if __name__ == "__main__": #use this…Program10.java 1. Write a Java program that prompts the user to enter a security code that matches a specific pattern. Your program must approve the user's entry. The pattern consists of these characters in this sequence: A lower case character, two upper case characters, two or three digits, two lower case characters, an upper case character, 2 or 3 lower case characters, 2 digits.Refer to Appendix H beginning on pages 1176. Example Run Enter the code patternbHT482haQmo82Yes, bHT482haQmo82 matches the pattern Recheck the requirements before you submit!class Line:'''write your codes below (don't forget to change the doc strings)'''def __init__(self, k, b):'''write your codes below (don't forget to change the doc strings)'''def __repr__(self):'''printable representation of the line by equation y = k*x+b'''return 'line y = %r*x + %r' % (self.k, self.b) def __add__(self,other):'''write your codes below (don't forget to change the doc strings)'''def intersect(self,other):'''write your codes below (don't forget to change the doc strings)'''
- Program10.java 1. Write a Java program that prompts the user to enter a security code that matches a specific pattern. Your program must approve the user's entry. The pattern consists of these characters in this sequence: 1 lower case character, 2 upper case characters, 2 or 3 digits, 2 lower case characters, 1 upper case character, 2 or 3 lower case characters, 2 digits.Refer to Appendix H beginning on pages 1176.Example Run Enter the code patternbHT482haQmo82Yes, bHT482haQmo82 matches the pattern Recheck the requirements before you submit!Java Questions - (Has 2 Parts). Based on each code, which answer out of the choices "A, B, C, D, E" is correct. Each question has one correct answer. Thank you. Part 1 - The following code will cause a(n) ___ exception. class Sample{public static void main(String[] args) { int x = 0; int y = 10; int z = y/x; } } A. ArithmeticExceptionB. ArrayIndexOutOfBoundsExceptionC. StringIndexOutOfBoundsExceptionD. NullPointerExceptionE. ClassNotFoundException Part 2 - A programmer carelessly assigned a negative value as an index of an array. Which type of exception will be raised during execution? A. An IndexOutOfBoundsException is thrown.B. A NumberFormatException is thrown.C. The first slot of the array is used.D. This is an Error, so the program immediately terminates no matter what.E. The last slot of the array is used.1-Convert the code below to OOP (Class) 2-give a detail explanation of the code #include <iostream> #include <cmath> #define boardSize 15 #define boardWidth 50 // put into grid the count no of # from x,y void putBlock(char grid[boardSize][boardWidth], int x, int y, int count) { for (int i = 0; i < count; i++) grid[x][y + i] = '#'; } // put into grid the count no of space from x,y void putSpace(char grid[boardSize][boardWidth], int x, int y, int count) { for (int i = 0; i < count; i++) if (grid[x][y + i] != '#') grid[x][y + i] = ' '; } void putCircle(char grid[boardSize][boardWidth], int x, int y) { // line 1 putSpace(grid, x, y, 3); putBlock(grid, x, y + 3, 5); // line 2 putSpace(grid, x + 1, y, 1); putBlock(grid, x + 1, y + 1, 2); putSpace(grid, x + 1, y + 3, 5); putBlock(grid, x + 1, y + 8, 2); // line 3 putBlock(grid, x + 2, y, 1); putSpace(grid, x + 2, y + 1, 9);…