Question

In: Computer Science

Optional Assignment 1: Method Man Assignment Description Write some methods and call them from the main....

Optional Assignment 1: Method Man

Assignment Description

Write some methods and call them from the main.

Tasks

  1. Write a method called nickelbackMeme with a void return type, a string parameter, and an int parameter
    1. The method outputs the text “LOOK AT THIS…” plus the string parameter at the end. The method will do this as many times as the int parameter. If 0 or a negative number is entered for the int parameter, output “WHAT THE HELL IS ON JOEY’S HEAD?” instead.
  2. Write a method called evenOrOdd with a string return type and no parameters
    1. In the method, ask the user for a whole number input
    2. The method will return “Odd” if the number is odd, or “Even” if the number is even
  3. Write a method called sevenAteNine that has an int return type and three int parameters
    1. The method will return the value of the parameter that is the smallest number
    2. If there is a tie, pick one of the parameters with the lowest value and return it

Solutions

Expert Solution

Here we have to create 3 method with different parametrs and return type as mentioned in the questien and call them from main

You didnt mentioned a specific language to do this task hence i assume any programming language is fine,here i am taking c++ to implement the above task

If you want to code this in C just change cout and cin all others are correct in C too(comment down if u need that,so i can change it for you :) ) ,If you need to done this in another language please repost it with mentioning the language

Now lets see how to implement this in C++

Please read all comments for better understanding of the program

OUTPUT (Test run)

I am also attching the text version of the code too in case you need to copy paste

#include <iostream> //calling iostream library
#include <string> //calling string library


using namespace std;

void nickelbackMeme(string str ,int x){ //defining function nickelbackMeme with parameters
if (x<=0){ //checking number is 0 or negative
cout<<"WHAT THE HELL IS ON JOEY’S HEAD?"<<endl;
}
else
{
for (int i=0;i<x;i++){ //looping statement to print the statement x times
cout<<"LOOK AT THIS..."<<str<<endl;
}
}
}

string evenOrOdd(){ //defining the function evenOrOdd   
int num;
cout<<"Ente a whole number"<<endl;
cin>>num; //statement to get a number from user
if (num%2==0){ // checkin the reminder of number when it is get
return "Even"; // divided by 2 (even numbers are divisible by 2)
}
else
{
return "Odd";
}
  
}
int sevenAteNine(int x,int y, int z){ //defining the function sevenAteNine with parametrse
  
int small; // a variable to store the smalles t number
  
  
if(x < y && x < z) // checking whether x is less than y and z
   {
       small=x;
   }
   else if(y < z) // if yes checking z is greater than z
   {
       small=y;
   }
   else
   {
       small=z;
   }

return small; //returrning small  
  
  
  
}

int main() //main function starts here
{
nickelbackMeme("Dude",5); // calling methods from main
cout<<evenOrOdd()<<endl; // calling methods from main
cout<<sevenAteNine(5,7,3); // calling methods from main

return 0;
}


Related Solutions

Description: For this assignment, you are required to write 3 recursive methods described below. Create a...
Description: For this assignment, you are required to write 3 recursive methods described below. Create a class named HW06 and implement the following 3 methods . The implementation MUST use recursive calls. - static int multiplyPositiveIntegers(int a, int b) //multiplies two positive integers using recursion (no use of * allowed). Returns the result of multiplication. (30 points) - static void recursiveBubbleSort(int[] arr) //Sorts an array using bubble sort in a recursive manner. Hint: do one pass(which puts the biggest element...
Java Programming II Homework 2-1 In this assignment you are being asked to write some methods...
Java Programming II Homework 2-1 In this assignment you are being asked to write some methods that operate on an array of int values. You will code all the methods and use your main method to test your methods. Your class should be named Array Your class will have the following methods (click on the method signatures for the Javadoc description of the methods): [ https://bit.ly/2GZXGWK ] public static int sum(int[] arr) public static int sum(int[] arr, int firstIndex, int...
Write a program that contains a main method and another method named userName. The main method...
Write a program that contains a main method and another method named userName. The main method should prompt the user to enter a full name. The userName method takes the full name as an argument and prints the name in reverse order and returns the number of characters in the name. See Sample Output (input shown in blue). Sample Output Please enter your FULL name Billy Joe McCallister Here is the name Billy Joe McCallister in reverse: retsillaCcM eoJ ylliB...
Write a public class call CountInts. class CountInts has a main method. CountInts must have two...
Write a public class call CountInts. class CountInts has a main method. CountInts must have two methods: count and displayResults. 1. method count takes an array, aa, of ints and counts how many times each integer appears in aa. The integers can only be from 0 to 100 inclusive. 2. method display results displays the results of the count 3. use the template provided. insert your code in the places indicated and don't change anything else. Examples % java CountInts...
Name the project pa3 [Method 1] In the Main class, write a static void method to...
Name the project pa3 [Method 1] In the Main class, write a static void method to print the following text by making use of a loop. Solutions without a loop will receive no credit. 1: All work and no play makes Jack a dull boy. 2: All work and no play makes Jack a dull boy. 3: All work and no play makes Jack a dull boy. 4: All work and no play makes Jack a dull boy. [Method 2]...
3. [Method 1] In the Main class, write a static void method to print the following...
3. [Method 1] In the Main class, write a static void method to print the following text by making use of a loop. Solutions without a loop will receive no credit. 1: All work and no play makes Jack a dull boy. 2: All work and no play makes Jack a dull boy. 3: All work and no play makes Jack a dull boy. 4: All work and no play makes Jack a dull boy. 4. [Method 2] In the...
Create a static method with the appropriate inputs and outputs. Call each of them in the...
Create a static method with the appropriate inputs and outputs. Call each of them in the main method. Write a method called stringToListOfWords() which takes in a String converts it into a list of words. We assumes that each word in the input string is separated by whitespace.3 2Use the equals() method. 3The split() method of String can split an input up along a provided special string called a regular expression or regex. A regex is much like a code...
Create a static method with the appropriate inputs and outputs. Call each of them in the...
Create a static method with the appropriate inputs and outputs. Call each of them in the main method. Write a method called removeAllInstances() which takes in a List and item4 . The method then proceeds to remove each item in the list that matches the given item. For example, if the method is passed the List [1, 4, 5, 6, 5, 5, 2] and the Integer 5, the method removes all 5’s from the List. The List then becomes [1,...
Create a static method with the appropriate inputs and outputs. Call each of them in the...
Create a static method with the appropriate inputs and outputs. Call each of them in the main method. Write a method called isPermutaion() which takes in two List objects which contain the same types. It returns true if the Lists are permutations of each other and false if not. Two lists are permutations if they contain the same elements, including the same number of duplicates, but they don’t have to contain the elements in the same order. For example, [1,2,...
Create a static method with the appropriate inputs and outputs. Call each of them in the...
Create a static method with the appropriate inputs and outputs. Call each of them in the main method. Write a method named allMultiples() which takes in a List of integers and an int. The method returns a new List of integers which contains all of the numbers from the input list which are multiples of the given int. For example, if the List is [1, 25, 2, 5, 30, 19, 57, 2, 25] and 5 was provided, the new list...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT