Follow the examples, could you please help me create methods with contracts? Cre
ID: 643893 • Letter: F
Question
Follow the examples, could you please help me create methods with contracts?
Create methods with contracts for the following: 1) Methods with 0 parameters, 0 returns: Ex: A method that prints hello a. A method that prints 3 lines of your address b. A method that uses input to get a string and prints the string c. A method that uses input to get two numbers and prints their total 2) Methods with 1 parameter. 0 returns (careful with parameter var types): Ex: A method that prints Mr. and your name (receive name as parameter a. A method that adds 10 to a number (receive number as parameter) b. A method that prints feet when given miles (receive miles as a parameter)
Explanation / Answer
public static void printaddr() {
System.out.println(" address line 1 ");
System.out.println("adress line 2 ");
System.out.println("adress line 3 ");
public static void printstrg() {
System.out.println("Enter the string to be printed");
BufferedReader bufferRead = new BufferedReader(new InputStreamReader(System.in));
String s = bufferRead.readLine();
System.out.println(s);
}
----- method to accept 2 numbers and prints their total
public static void addnums(){
int i,j;
System.out.println("Please enter the first number");
System.out.println(" Please enter the second number");
int j = Integer.parseInt(System.console().readLine());
int tot;
tot = i + j;
System.out.println(" The total of the two entered numbers is " + tot);
}
A method that adds 10 to a number
public static void addten(int n){
n = n + 10;
}
A method that prints feet when given miles
1 mile = 5280 feet
public static void ftconvt( float mil){
double ft;
ft = mil * 5280;
System.out.println("The feet value for the given miles is " + ft);
}