-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCLASSdemo.java
More file actions
74 lines (48 loc) · 1.82 KB
/
CLASSdemo.java
File metadata and controls
74 lines (48 loc) · 1.82 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
public class CLASSdemo // this is a CLASS (no public static void main)
{
private String n = "";
private int a = 0;
private char i = ' ';
// these are INSTANCE VARIABLES
////////////////////////////////////////////////////////////////////////////////
public void displayHi() // this is a METHOD...
{ // used to accomplish a task
System.out.println("Welcome.\n\n");
}
//////////////////////////////////////////////////////////////////////////////
public void displayByeBye() // this is another METHOD...
{ // used to accomplish a task
System.out.println("See ya.\n\n");
}
//////////////////////////////////////////////////////////////////////////////
public void setInfo() // mutator method
{
System.out.print("What is your name? ");
n = SavitchIn.readLine();
System.out.print("\n\nWhat is your age? ");
a = SavitchIn.readLineInt();
while(a<0)
{
System.out.println ("Try again.");
a = SavitchIn.readLineInt();
}
System.out.print("\n\nWhat is your middle initial? ");
i = SavitchIn.readLineNonwhiteChar();
}
///////////////////////////////////////////////////////////////////////////////
public String getName() // an accessor method....this is the first one that actually returns something to the CLIENT
{
return n;
} // "public String" because this method returns a String
//////////////////////////////////////////////////////////////////////////////
public int getAge() // another accessor method
{
return a;
}
//////////////////////////////////////////////////////////////////////////////
public char getInitial() // another accessor method
{
return i;
}
///////////////////////////////////////////////////////////////////////
}