Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

Exercise 1

1 import java.util.Scanner;
2 public class CarryMarks {
3 public static void main ( String [] args)
4 {
5 int midsem;
6 int asgm;
7 int quiz;
8
9
10 Scanner input1 = new Scanner(System.in);
11 System.out.print("Please Enter the Midsem (Integer
number Only) : ");
12 midsem=input1.nextInt();
13
14 Scanner input2 = new Scanner(System.in);
15 System.out.printf("\nPlease Enter the Assignment
(Integer number Only : ");
16 asgm=input2.nextInt();
17
18 Scanner input3 = new Scanner(System.in);
19 System.out.printf("\nPlease Enter the Quiz (Integer
number Only : ");
20 quiz=input3.nextInt();
21
22 int carryMarks=midsem+asgm+quiz;
23 System.out.println("The Total Carry Marks is:"
+carryMarks);
24
25 }
26 }
27
Exercise 5
1 import java.util.Scanner;
2 public class AverageScore {
3 public static void main ( String [] args)
4 {
5 int score1;
6 int score2;
7 int score3;
8
9
10 Scanner input1 = new Scanner(System.in);
11 System.out.print("Please Enter the Score 1 (Integer
number Only) : ");
12 score1=input1.nextInt();
13
14 Scanner input2 = new Scanner(System.in);
15 System.out.printf("\nPlease Enter the Score 2 (Integer
number Only : ");
16 score2=input2.nextInt();
17
18 Scanner input3 = new Scanner(System.in);
19 System.out.printf("\nPlease Enter the Score 3 (Integer
number Only : ");
20 score3=input3.nextInt();
21
22 double average=(score1+score2+score3)/3;
23 System.out.printf("The Total Average Score is: %.2f "
,average);
24
25 }
26 }
Exercise 6
1 import java.util.Scanner;
2 public class PriceItems {
3 public static void main ( String [] args)
4 {
5 String item;
6 int quantity;
7 double price ;
8
9
10
11
12 Scanner input1 = new Scanner(System.in);
13 System.out.print("Please Enter the item name: ");
14 item=input1.nextLine();
15
16 Scanner input2 = new Scanner(System.in);
17 System.out.printf("\nPlease Enter the quantity: ");
18 quantity=input2.nextInt();
19
20 Scanner input3 = new Scanner(System.in);
21 System.out.printf("\nPlease Enter the Price of Item
:RM ");
22 price=input3.nextFloat();
23
24 double priceItem=quantity*price;
25 System.out.printf("The Total is:RM %.2f ",priceItem);
26
27 }
28 }
Exercise 8
1 import java.util.Scanner;
2 public class PriceTicket {
3 public static void main ( String [] args)
4 {
5 int adult;
6 int child;
7 final int ADULT_PRICE = 50;
8 final int CHILD_PRICE=30;
9
10
11 Scanner input1 = new Scanner(System.in);
12 System.out.print("Please Enter Total Adults ");
13 adult=input1.nextInt();
14
15 Scanner input2 = new Scanner(System.in);
16 System.out.printf("\nPlease Enter Total Childrens : ");
17 child=input2.nextInt();
18
19
20 double TotalPrice =
(adult*ADULT_PRICE)+(child*CHILD_PRICE);
21 System.out.printf("The Total Price is RM %.2f"
,TotalPrice);
22
23 }
24 }

You might also like