1) Write fhe function definition for a function named outputDottedLine () which
ID: 641491 • Letter: 1
Question
1) Write fhe function definition for a function named outputDottedLine() which has no parameters and returns nothing. When called,outputDottedLine() shall display five consecutive periods ..... on the outupt window followed by a newline. 2) Write a function definition for a function named ouch() that has no parameters and returns nothing. When ouch() is called it displays the string literal "Ouch!" on the output window. 3) add is a function that accepts two int parameters and returns their sum . Two int variables , euroSales and asiaSales , have already been declared and initialized .Another int variable , eurasiaSales , has already beendeclared . Write a statement that calls add to compute the sum of euroSales and asiaSales and store this value in eurasiaSales . Instructor Notes: Remember, there are several things we can do with the return value from a function call. One of those things is to assign the return value to a variable, using this syntax: var = function-name ( list-of-args ) ; 4) Write the definition of a function half , which receives an integer parameter and returns an integer that is half the value of the parameter . (Useinteger division!) So if the parameter 's value is 7, the function returns the value 3. If the parameter 's value happens to be 44, the functions returns the value 22.
Explanation / Answer
package book;
public class eurasiaSales {
int EuroSales;
int AsiaSales;
int param;
int half;
public void OutputDottedLine()
{
System.out.println("..... ");
}
public void Ouch()
{
System.out.println("Ouch!");
}
public int add(int Euro,int Asia)
{ EuroSales=Euro;
AsiaSales=Asia;
int EurasiaSales=EuroSales+AsiaSales;
return EurasiaSales;
}
public int half(int par)
{
param=par;
half=param/2;
return half;
}
public static void main(String[] args)
{
eurasiaSales es=new eurasiaSales();
es.OutputDottedLine();
es.Ouch();
int sum=es.add(23,46);
System.out.println(sum);
int div=es.half(7);
System.out.println(div);
}
}
OUTPUT:
.....
Ouch!
69
3
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.