-
Notifications
You must be signed in to change notification settings - Fork 0
/
Exam1.java
77 lines (56 loc) · 1.64 KB
/
Exam1.java
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
class ReadingGlasses {
private double magnification;
private String frameStyle;
private String lensType;
public ReadingGlasses(String fs) {
frameStyle = fs;
}
public ReadingGlasses(String fs, String lt, double m) {
frameStyle = fs;
lensType = lt;
setMagnification(m);
}
public void setLensType(String lt) {
lensType = lt;
}
public void setMagnification(double m) {
if (m < .75) m = .75;
if (m > 4) m = 4;
m *= 4;
int temp = (int)m;
m = temp * .25;
magnification = m;
}
public String getFrameStyle() {return frameStyle;}
public String getLensType() {return lensType;}
public double getMagnification() {return magnification;}
public String toString() {
return frameStyle + " glasses with " + magnification
+ " power " + lensType + " lenses.";
}
}
//number 25
import java.util.Scanner;
class number2 {
public static void main(String[] args) {
Scanner kb = new Scanner(System.in);
int input, total = 0, count = 0;
double average;
System.out.print("Enter a number: ");
input = kb.nextInt();
while(input>= 0) {
total += input;
count++;
System.out.print("Enter another number: ");
input = kb.nextInt();
}
average = (double)total/count;
System.out.println("Total: " + total + "\nNumber of values entered: "
+count + "\nAverage: " + average;)
}
}
//1: int: 32-bit signed integer type.
//2: javac: program to compile Java source code into Java bytecode
//3: public: access modifier granting universal access to the modified item
//4: private: access modifier restricting access to methods in the same class
//5: .class: file extension of compiled Java files (bytecode)