logo Use CA10RAM to get 10%* Discount.
Order Nowlogo

IF ELSE Create a Driver and an External Class that interacts with the User.

INSTRUCTIONS TO CANDIDATES
ANSWER ALL QUESTIONS

Program 3: IF ELSE Create a Driver and an External Class that interacts with the User. External Class: IfElseExamples Create an external class and name this class: IfElseExamples Instance Data of Class: Declare the following Global variables.

Data Type Variable Name Description String name The name of the User String password The user’s password Create a constructor that will initialize the User's name and password. Set the constructor up using the following chart: Public or Private? Return Value and Data Type Constructor Name Parameters and Data Types with parenthesis Description Public None. Constructors do not have a return data type nor are they void.

IfElseExamples The name of the constructor is the same as the name of the External Class. String userName String userPassword These two variables along with their datatypes go within the parenthesis.

The body of the constructor will initialize the global variables with the User’s name and the User’s password: name = userName; password = userPassword; Create a method that will determine if a number is positive or negative. Set the method up using the following chart: Public or Private?

Return Value and Data Type Method Name Parameters and Data Types with parenthesis Description Public bool isPositive int number This variable along with its datatype goes within the parenthesis. Determines if an integer is negative or positive:

IF the integer is greater than zero return true ELSE return false Create a method that will determine if the User is eligible to vote based on the age of the User. Set the method up using the following chart: Public or Private?

Return Value and Data Type Method Name Parameters and Data Types with parenthesis Description Public bool isEligible int userAge This variable along with its datatype goes within the parenthesis. Determines if the User is eligible to vote: IF the userAge is greater than 18 return true ELSE return false Create a method that will determine whether or not a number is odd or even. Use the following chart to set up the method: Public or Private?

Return Value and Data Type Method Name Parameters and Data Types with parenthesis Description Public bool isEven int value This variable along with its datatype goes within the parenthesis. Determines if the integer is even or odd: IF the integer is divisible by 2 return true ELSE return false Create a method that will return the larger of two numbers. Set the method up according to the following chart: Public or Private?

Return Value and Data Type Method Name Parameters and Data Types with parenthesis Description Public int larger int num1 int num2 These variables along with their datatypes go within the parenthesis. Determines which of two numbers is the largest: IF the num1 is greater than num2 return num1 ELSE return num2 Create a method that will determine if a User’s password is correct or not.

Set the method up according to the following chart. You must use the String methods when comparing strings. Public or Private? Return Value and Data Type Method Name Parameters and Data Types with parenthesis Description Public bool checkPassword String passwordEntered This variables along with their datatypes go within the parenthesis. Determines if the password is correct or not: IF passwordEntered equals password return true ELSE return false **You must use the string methods to compare two strings. Driver: IfElseDriver Create a driver class to test the IfElseExample Class.

Name this IfElseDriver. Declare the following variables in the Data Declaration Section: String myName; String myPassword; int posNegInt; int voteAge; int oddEvenInt; int firstNum; int secondNum; bool isCorrect; bool isNumPos; bool isOldEnough; bool isNumEven; int largest; Create a new object of class IfElseExample. Initialize the object with your name and a password. Name this object: ifElseTester Prompt the User to enter a password and store it in myPassword.

Call the checkPassword method to determine if the password is correct or not. Send the method the password entered by the User through the parameter list. Assign the Boolean value returned by the method to the variable isCorrect. Set up an outer IF/ELSE structure that will NOT allow the User to continue if the password is incorrect. Do the following ONLY if the password entered is correct: Prompt the User to enter a positive or negative number.

Call the isPositive method and send it the number through the parameter list. Assign the call to the Boolean variable isNumPos. If the method returns a true, print out a message stating that the number entered is positive. Otherwise print out that the number is negative. Prompt the User to enter their age. Call the isEligible method and send it the age through the parameter list.

Assign the Boolean value returned to the variable isOldEnough. If the method returns a true then print out that they are eligible to vote. Otherwise compute how many years they must wait to vote and print that out. Prompt the User to enter a positive number.

Call the method isEven and send it the number through the parameter list. Assign the Boolean value returned to the variable isNumEven. If the method returns a true then print out that the number even. Otherwise print out that the number is odd. Prompt the User to enter two numbers.

Call the method larger and send it the two numbers through the parameter list. Assign the integer value returned to the variable largest. Print out the number returned in a message stating that this number is the largest. Logic within Driver main method:

You MUST set up the logic within main like this: Prompt User to enter a password Scan the password and assign it to myPassword: myPassword = string entered by User Send the password to the checkPassword method in ifElseTester: isCorrect = ifElseTester.checkPassword(myPassword) IF isCorrect == false

THEN Display password is incorrect ELSE Prompt User to enter a positive or negative number. Scan the number and assign it to posNegInt: posNegInt = integer entered by User Send the number to the isPositive method in ifElseTester: isNumPos = ifElseTester.isPositive(posNegInt) IF isNumPos == true Display number is positive ELSE Display number is negative END IF Prompt User to enter their age. Scan the age and assign it to voteAge: voteAge = integer entered by User Send the age to the isEligible method in ifElseTester: isOldEnough = ifElseTester.isEligible(voteAge) IF isOldEnough >

18 Display they are eligible to vote ELSE Compute how many years they must wait to vote. Display message with number of years they must wait to vote. END IF Prompt the User to enter a positive number. Scan the number and assign it to oddEvenInt: oddEvenInt = integer entered by User Send the number to the isEven method in

ifElseTester: isNumEven = ifElseTester.isEven(oddEvenInt) IF isNumEven == true Display number is even ELSE Display number is odd END IF Prompt the User to enter first number. Scan the first number and assign it to firstNum: firstNum = first integer entered by User Prompt the User to enter second number. Scan the second number and assign it to secondNum: secondNum = second integer entered by User

Send first and second number to larger method in ifElseTester: largest = ifElseTester.larger(firstNum, secondNum) Display largest is the larger number. END IF NOTES: You will receive a zero if you do not use the above logic. 1. Declare all variables within the data declaration section of each class and method.

2 Do not get input on the same line as a variable declaration.

3. Do not place an equation for computation on the same line as declaring a variable

4. Do not place an equation for computation on the same line as input.

 

Related Questions

. Introgramming & Unix Fall 2018, CRN 44882, Oakland University Homework Assignment 6 - Using Arrays and Functions in C

DescriptionIn this final assignment, the students will demonstrate their ability to apply two ma

. The standard path finding involves finding the (shortest) path from an origin to a destination, typically on a map. This is an

Path finding involves finding a path from A to B. Typically we want the path to have certain properties,such as being the shortest or to avoid going t

. Develop a program to emulate a purchase transaction at a retail store. This program will have two classes, a LineItem class and a Transaction class. The LineItem class will represent an individual

Develop a program to emulate a purchase transaction at a retail store. Thisprogram will have two classes, a LineItem class and a Transaction class. Th

. SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 1 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

. Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

Ask This Question To Be Solved By Our ExpertsGet A+ Grade Solution Guaranteed

expert
Atharva PatilComputer science

877 Answers

Hire Me
expert
Chrisantus MakokhaComputer science

775 Answers

Hire Me
expert
AyooluwaEducation

637 Answers

Hire Me
expert
RIZWANAMathematics

963 Answers

Hire Me

Get Free Quote!

379 Experts Online