-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFillInFunction.java
More file actions
123 lines (90 loc) · 2.54 KB
/
Copy pathFillInFunction.java
File metadata and controls
123 lines (90 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package assignment_10528808;
/**
*
* @author Mawutor
*/
// Fill-In Functions - Fix the broken functions and function calls.
import java.util.Random;
public class FillInFunction
{
public static void main( String[] args )
{
// Fill in the function calls where appropriate.
System.out.println("Watch as we demonstrate functions.");
System.out.println();
System.out.println("I'm going to get a random character from A-Z");
char c = '!';
randchar();
System.out.println("The character is: " + c );
System.out.println();
System.out.println("Now let's count from -10 to 10");
int begin, end;
begin = -10;
end = 10;
counter(-10,10);
System.out.println("How was that?");
System.out.println();
System.out.println("Now we take the absolute value of a number.");
int x, y = 10;
x = -10;
abso(-10);
System.out.println("|" + x + "| = " + y );
System.out.println();
System.out.println("That's all. This program has been brought to you by:");
credits();
}
public static void credits( )
// No parameters.
{
// displays some boilerplate text saying who wrote this program, etc.
System.out.println();
System.out.println("programmed by Graham Mitchell");
System.out.println("modified by [your name here]");
System.out.print("This code is distributed under the terms of the standard ");
System.out.println("BSD license. Do with it as you wish.");
}
public static void randchar()
// No parameters.
{
// chooses a random character in the range "A" to "Z"
int numval;
char charval;
// pick a random number from 0 to 25
numval = (int)(Math.random()*26);
// now add that offset to the value of the letter 'A'
charval = (char) ('A' + numval);
return ;
}
public static int counter( int start , int stop )
// Parameters are:
// int start;
// int stop;
{
// counts from start to stop by ones
int ctr;
ctr = start;
while ( ctr <= stop )
{
System.out.print(ctr + " ");
ctr = ctr+1;
}
return ctr;
}
public static int abso(int value )
// Parameters are:
// int value;
{
// finds the absolute value of the parameter
int absval;
if ( value < 0 )
absval = -value;
else
absval = value;
return absval;
}
}