code to request customer service request 1. define a fcntion call greeting that
ID: 3831187 • Letter: C
Question
code to request customer service request
1. define a fcntion call greeting that takes one in put parmeter repesenting the name of the customer and prints out greeting in the example below
ex.func call
greeting("Bob") # should print : Hello Bob, How can i help you today.
greeting("Lisa") # should print : Hello Lisa, How can i help you today.
2..define a function called is wierdweather thst takes cloudy and rainy as input parameters and return True when is is rainy but not cloud. the function should return false for all other posibilitie
ex of func calls:
wierdweather (False, true) # should return True
wierdweather (true, true) # return false
wierdweather (true, false) # return false
wierdweather (fals, false) #return false
3. you are writing a digital application for a new restaurant that has built in touch screen on any table.
define a fucntion called alchoholWarningt that receives an input parameter representing the customers age and prints either :"Drink Responsibly or "Sorry you are too young to drink alcohol"
ex. alcoholwarning(18): # should print : sorry, but you are too young to drink alcohol
achoholwarning(32) # should print : Drink responsibly
4. write a function called swap that receives one array and intefers representing the positions of the array to swap. the function should return and array with 2 values swapped.
swap([10, 11, 12,13,14, 15], 1,4) should return [10,14,12,13,11,15]
swap[10,11,12,13,14,15],2,3) should return [10,11,13,12,14,15]
Question 1 (12 points) 2(13 points) DOLLExplanation / Answer
Below is the code in java: -
CustomerService.java
import java.util.Scanner;
public class CustomerService {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);// Taking input from user
System.out.print("Your Name:");
String name = sc.next();// taking name input
greeting(name);// calling greeting funtion
System.out.print("Is it cloudy?: (Y/N): ");
boolean cloudy;
if (sc.next().equals("Y")) {// Checking If cloudy
cloudy = true;
} else {
cloudy = false;
}
System.out.print("Is it Rainy?: (Y/N): ");// Checking if rainy
boolean rainy;
if (sc.next().equals("Y")) {
rainy = true;
} else {
rainy = false;
}
if (wierdWeather(cloudy, rainy)) {// calling wierdweather function
System.out.println("Weather is wierd.");
} else {
System.out.println("Ok!");
}
System.out.println("Your Age Please:");
int age = sc.nextInt();// taking age input
sc.close();
alchoholWarning(age);// calling alcoholWarning method
int[] arr = { 10, 11, 12, 13, 14, 15 };// initializing the array
System.out.println("Initial Array:");
for (int i = 0; i < arr.length; i++) {// printing initial array
System.out.print(arr[i] + " ");
}
System.out.println();
int[] changedArr = swap(arr, 1, 4);// calling swap method
System.out.println("Final Array:");// printing final array
for (int i = 0; i < changedArr.length; i++) {
System.out.print(changedArr[i] + " ");
}
}
public static void greeting(String name) {
System.out.println("Hello " + name + ", How can i help you today.");//printing greeting message
}
public static boolean wierdWeather(boolean cloudy, boolean rainy) {
if (rainy && !cloudy) {//true if rainy but not cloudy
return true;
}
return false;
}
public static void alchoholWarning(int age) {
if (age > 18) {
System.out.println("Drink Responsibly");
} else {
System.out.println("Sorry you are too young to drink alcohol");
}
}
public static int[] swap(int[] arr, int x, int y) {
//swapping elements
int temp = arr[x];
arr[x] = arr[y];
arr[y] = temp;
return arr;
}
}
Sample Run: -
Your Name:Sanjay
Hello Sanjay, How can i help you today.
Is it cloudy?: (Y/N): N
Is it Rainy?: (Y/N): Y
Weather is wierd.
Your Age Please:
18
Sorry you are too young to drink alcohol
Initial Array:
10 11 12 13 14 15
Final Array:
10 14 12 13 11 15
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.