Вы находитесь на странице: 1из 17

SKJ2413

OBJECT-ORIENTED PROGRAMMING
(LAB 5 SHEET)

LECTURER NAME :
DR MUHD ZALISHAM BIN JALI

STUDENT NAME:
SITI FARHHANAH ZAKARIA
1121778

LAB SESSION :
MQB2

QUES
CODING
4.5
/*
* 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 pkg4.pkg5;
/**
*
* @author USER
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic
// Display the table heading
System.out.println( "
conversion Table");

" + "Kilos & Pounds

RESULT
run:
Kilos & Pounds conversion Table
Kilograms
Pounds
|
Pounds
1.0
2.2
1.0
2.0
4.4
2.0
3.0
6.6
3.0
4.0
8.8
4.0
5.0
11.0
5.0
6.0
13.2
6.0
7.0
15.4
7.0
8.0
17.6
8.0
9.0
19.8
9.0
10.0
22.0
10.0
11.0
24.2
11.0
12.0
26.4
12.0
13.0
28.6
13.0
14.0
30.8
14.0
15.0
33.0
15.0
16.0
35.2
16.0
17.0
37.4
17.0
18.0
39.6
18.0
19.0
41.8
19.0
20.0
44.0
20.0
21.0
46.2
21.0
22.0
48.4
22.0
23.0
50.6
23.0
24.0
52.8
24.0
25.0
55.0
25.0

Kilograms
0.5
0.9
1.4
1.8
2.3
2.7
3.2
3.6
4.1
4.5
5.0
5.4
5.9
6.3
6.8
7.2
7.7
8.2
8.6
9.1
9.5
10.0
10.4
10.9
11.3

System.out.println("Kilograms\tPounds\t\t|\tPounds\t
\tKilograms");

for (double k = 1; k <= 199; k++) {


double pound=0;
double kilos=0;
pound =(k * 2.2);
kilos = (k * 0.453);
System.out.printf( k + "\t\t" + "%.1f" , pound );
System.out.printf( "\t\t\t"+k + "\t\t" + "%.1f" ,
kilos );
System.out.println();
}
}
}

26.0
27.0
28.0
29.0
30.0
31.0
32.0
33.0
34.0
35.0
36.0
37.0
38.0
39.0
40.0
41.0
42.0
43.0
44.0
45.0
46.0
47.0
48.0
49.0
50.0
51.0
52.0
53.0
54.0
55.0

57.2
59.4
61.6
63.8
66.0
68.2
70.4
72.6
74.8
77.0
79.2
81.4
83.6
85.8
88.0
90.2
92.4
94.6
96.8
99.0
101.2
103.4
105.6
107.8
110.0
112.2
114.4
116.6
118.8
121.0

26.0
27.0
28.0
29.0
30.0
31.0
32.0
33.0
34.0
35.0
36.0
37.0
38.0
39.0
40.0
41.0
42.0
43.0
44.0
45.0
46.0
47.0
48.0
49.0
50.0
51.0
52.0
53.0
54.0
55.0

11.8
12.2
12.7
13.1
13.6
14.0
14.5
14.9
15.4
15.9
16.3
16.8
17.2
17.7
18.1
18.6
19.0
19.5
19.9
20.4
20.8
21.3
21.7
22.2
22.7
23.1
23.6
24.0
24.5
24.9

56.0
57.0
58.0
59.0
60.0
61.0
62.0
63.0
64.0
65.0
66.0
67.0
68.0
69.0
70.0
71.0
72.0
73.0
74.0
75.0
76.0
77.0
78.0
79.0
80.0
81.0
82.0
83.0
84.0
85.0

123.2
125.4
127.6
129.8
132.0
134.2
136.4
138.6
140.8
143.0
145.2
147.4
149.6
151.8
154.0
156.2
158.4
160.6
162.8
165.0
167.2
169.4
171.6
173.8
176.0
178.2
180.4
182.6
184.8
187.0

56.0
57.0
58.0
59.0
60.0
61.0
62.0
63.0
64.0
65.0
66.0
67.0
68.0
69.0
70.0
71.0
72.0
73.0
74.0
75.0
76.0
77.0
78.0
79.0
80.0
81.0
82.0
83.0
84.0
85.0

25.4
25.8
26.3
26.7
27.2
27.6
28.1
28.5
29.0
29.4
29.9
30.4
30.8
31.3
31.7
32.2
32.6
33.1
33.5
34.0
34.4
34.9
35.3
35.8
36.2
36.7
37.1
37.6
38.1
38.5

86.0
87.0
88.0
89.0
90.0
91.0
92.0
93.0
94.0
95.0
96.0
97.0
98.0
99.0
100.0
101.0
102.0
103.0
104.0
105.0
106.0
107.0
108.0
109.0
110.0
111.0
112.0
113.0
114.0
115.0

189.2
191.4
193.6
195.8
198.0
200.2
202.4
204.6
206.8
209.0
211.2
213.4
215.6
217.8
220.0
222.2
224.4
226.6
228.8
231.0
233.2
235.4
237.6
239.8
242.0
244.2
246.4
248.6
250.8
253.0

86.0
87.0
88.0
89.0
90.0
91.0
92.0
93.0
94.0
95.0
96.0
97.0
98.0
99.0
100.0
101.0
102.0
103.0
104.0
105.0
106.0
107.0
108.0
109.0
110.0
111.0
112.0
113.0
114.0
115.0

39.0
39.4
39.9
40.3
40.8
41.2
41.7
42.1
42.6
43.0
43.5
43.9
44.4
44.8
45.3
45.8
46.2
46.7
47.1
47.6
48.0
48.5
48.9
49.4
49.8
50.3
50.7
51.2
51.6
52.1

116.0
117.0
118.0
119.0
120.0
121.0
122.0
123.0
124.0
125.0
126.0
127.0
128.0
129.0
130.0
131.0
132.0
133.0
134.0
135.0
136.0
137.0
138.0
139.0
140.0
141.0
142.0
143.0
144.0
145.0

255.2
257.4
259.6
261.8
264.0
266.2
268.4
270.6
272.8
275.0
277.2
279.4
281.6
283.8
286.0
288.2
290.4
292.6
294.8
297.0
299.2
301.4
303.6
305.8
308.0
310.2
312.4
314.6
316.8
319.0

116.0
117.0
118.0
119.0
120.0
121.0
122.0
123.0
124.0
125.0
126.0
127.0
128.0
129.0
130.0
131.0
132.0
133.0
134.0
135.0
136.0
137.0
138.0
139.0
140.0
141.0
142.0
143.0
144.0
145.0

52.5
53.0
53.5
53.9
54.4
54.8
55.3
55.7
56.2
56.6
57.1
57.5
58.0
58.4
58.9
59.3
59.8
60.2
60.7
61.2
61.6
62.1
62.5
63.0
63.4
63.9
64.3
64.8
65.2
65.7

146.0
147.0
148.0
149.0
150.0
151.0
152.0
153.0
154.0
155.0
156.0
157.0
158.0
159.0
160.0
161.0
162.0
163.0
164.0
165.0
166.0
167.0
168.0
169.0
170.0
171.0
172.0
173.0
174.0
175.0

321.2
323.4
325.6
327.8
330.0
332.2
334.4
336.6
338.8
341.0
343.2
345.4
347.6
349.8
352.0
354.2
356.4
358.6
360.8
363.0
365.2
367.4
369.6
371.8
374.0
376.2
378.4
380.6
382.8
385.0

146.0
147.0
148.0
149.0
150.0
151.0
152.0
153.0
154.0
155.0
156.0
157.0
158.0
159.0
160.0
161.0
162.0
163.0
164.0
165.0
166.0
167.0
168.0
169.0
170.0
171.0
172.0
173.0
174.0
175.0

66.1
66.6
67.0
67.5
68.0
68.4
68.9
69.3
69.8
70.2
70.7
71.1
71.6
72.0
72.5
72.9
73.4
73.8
74.3
74.7
75.2
75.7
76.1
76.6
77.0
77.5
77.9
78.4
78.8
79.3

4.7

/*
* To change this license header, choose License
Headers in Project Properties.
* To change this template file, choose Tools |
Templates

176.0
387.2
176.0
177.0
389.4
177.0
178.0
391.6
178.0
179.0
393.8
179.0
180.0
396.0
180.0
181.0
398.2
181.0
182.0
400.4
182.0
183.0
402.6
183.0
184.0
404.8
184.0
185.0
407.0
185.0
186.0
409.2
186.0
187.0
411.4
187.0
188.0
413.6
188.0
189.0
415.8
189.0
190.0
418.0
190.0
191.0
420.2
191.0
192.0
422.4
192.0
193.0
424.6
193.0
194.0
426.8
194.0
195.0
429.0
195.0
196.0
431.2
196.0
197.0
433.4
197.0
198.0
435.6
198.0
199.0
437.8
199.0
BUILD SUCCESSFUL (total time: 2 seconds)
run:
The tuition in ten years is: 16288.946267774414
The total cost of 4 years is: 83717.76425901077
BUILD SUCCESSFUL (total time: 1 second)

79.7
80.2
80.6
81.1
81.5
82.0
82.4
82.9
83.4
83.8
84.3
84.7
85.2
85.6
86.1
86.5
87.0
87.4
87.9
88.3
88.8
89.2
89.7
90.1

* and open the template in the editor.


*/
package pkg4.pkg7;
/**
*
* @author USER
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
double tuition = 10000;
int year = 1;
double tuitiontotal = tuition;
//Loop
while (year <= 10){
tuition = ((tuition * .05) + tuition);
year++;
}
System.out.println("The tuition in ten years is: " +
tuition);

while (year <= 14){


tuition = tuition * 1.05;
tuitiontotal = tuitiontotal + tuition;
year++;
}

4.9

System.out.println("The total cost of 4 years is: " +


tuitiontotal);
}
}
/*
* 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 highest.score;
import java.util.Scanner;
/**
*
* @author USER
*/
public class HighestScore {
/**
* @param args the command line arguments

run:
Enter the number of students: 4
Enter the student's name: FARHANA
Enter the student's score: 90
Enter the student's name: DAIM
Enter the student's score: 80
Enter the student's name: UWAIS
Enter the student's score: 70
Enter the student's name: SYAH
Enter the student's score: 78
FARHANA's score is 90
DAIM's score is 80
BUILD SUCCESSFUL (total time: 36 seconds)

*/
private static String Student2;
private static int Score2;
public static void main(String[] args) {
// TODO code application logic here
{
Scanner input = new Scanner(System.in);
System.out.print("Enter the number of students: ");

int numStudents = input.nextInt();


System.out.print("Enter the student's name: ");

String Student1 = input.next();


System.out.print("Enter the student's score: ");
int Score1 = input.nextInt();
for (int i = 0; i < numStudents - 1; i++)
{
System.out.print("Enter the student's name: ");
String Student = input.next();
System.out.print("Enter the student's score: ");
int Score = input.nextInt();
if (Score > Score1)
{

Student2 = Student1;
Score2 = Score1;
Student1 = Student;
Score1 = Score;
}
else if (Score > Score2)
{
Student2 = Student;
Score2 = Score;
}
}
System.out.println(Student1 + "'s score is " + Score1);
System.out.println(Student2 + "'s score is " + Score2);

}
}
}
4.17

/*
* 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.
*/

run:
Enter a number between 1 and 15:
7

package displaying.pyramid;
7

6
7

5
6
7

4
5
6
7

3
4
5
6
7

2
3
4
5
6
7

1
2
3
4
5
6
7

2
3
4
5
6
7

3
4
5
6
7

4
5
6
7

5
6
7

6
7

import java.util.Scanner;
BUILD SUCCESSFUL (total time: 3 seconds)
/**
*
* @author USER
*/
public class DisplayingPyramid {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Scanner s = new Scanner(System.in);
//Input
System.out.println("Enter a number between 1 and
15: ");
int numLines = s.nextInt();
for (int row = 1; row <= numLines; row++){
//print out n-row # of spaces
for (int col = 1; col <= numLines-row; col++){
System.out.print(" \t");
}
//print out digits = 2*row-1 # of digits printed
for (int dig= 1; dig <= 2*row-1; dig++){
System.out.print(row + "\t");
}
System.out.println();
}

}
}

4.41

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package mypkg;
import java.util.Scanner;
/**
*
* @author USER
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
long a = 0, b = 0, c = 0, d = 0;
System.out.println("Enter numbers!");
Scanner sc = new Scanner(System.in);

run:
Enter numbers!
3525550
info:
highest:5
iterations:7
overrides:2
BUILD SUCCESSFUL (total time: 19 seconds)

String in = sc.nextLine();
Scanner ln = new Scanner(in);
while (ln.hasNextLong()) {
a = ln.nextLong();
if (a > b) {
b = a;
++d;
}
++c;
}
System.out.println("\n info:");
System.out.println(" highest:" + b);
System.out.println(" iterations:" + c);
System.out.println("

overrides:" + d);

}
}

4.43

/*
* 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.

run:
Enter the number of seconds: 3
3 seconds remaining
2 seconds remaining
1 second remaining
stop

*/
package last;
import java.util.Scanner;
/**
*
* @author USER
*/
public class Last {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Scanner scan = new java.util.Scanner(System.in);
System.out.print("Enter the number of seconds: ");
int seconds = scan.nextInt();
for (int i =seconds;i>0;i--)
{
if (i != 1)
System.out.println(i + " seconds remaining");
else
System.out.println(i + " second remaining");

}
System.out.println(" stop");

BUILD SUCCESSFUL (total time: 8 seconds)

}
}

Вам также может понравиться