Sunteți pe pagina 1din 9

FACULTY OF COMPUTER & MATHEMATICAL SCIENCES

CS240
BACHELOR OF INFORMATION TECHNOLOGY (HONS)

CSC435 (OBJECT ORIENTED PROGRAMMING )

LAB ASSIGNMENT 1

STUDENT NAME : AHMAD ASYRAF BIN ISKANDAR SHAH


STUDENT ID : 2016552401
STUDENT GROUP : RCS2402A
LECTURER NAME : MOHD NIZAM BIN OSMAN
Question 1.1

SOURCE CODE

import java.util.*;
public class Score {

public static void main (String [] args)


{
Scanner input = new Scanner (System.in);
Scanner input1 = new Scanner (System.in);

int score1 = 0,score2 = 0, score3 = 0, score4 = 0, score5 = 0;


int response;
int respondent = 0;

System.out.println("Please Insert Your Score Scale From 1 to 5 and 0 to stop");

do
{
respondent += 1 ;
System.out.print("Score for respondent " +respondent +" : ");
int num = input1.nextInt();

while (num < 0 || num > 5 )


{
System.out.println("INVALID SCORE");
System.out.print("Please insert again for respondent " +respondent +":
");
num = input1.nextInt();
}
if ( num == 1)
score1 += 1;
else if ( num == 2)
score2 += 1;
else if ( num == 3)
score3 += 1;
else if ( num == 4)
score4 += 1;
else if ( num == 5)
score5 += 1;

response = num;

}while (response != 0);

{
System.out.println ("Score\t" +"Total Number Of Respondent");
System.out.println ("-----------------------------------");
System.out.println ("1\t\t\t\t\t" +score1);
System.out.println ("2\t\t\t\t\t" +score2);
System.out.println ("3\t\t\t\t\t" +score3);
System.out.println ("4\t\t\t\t\t" +score4);
System.out.println ("5\t\t\t\t\t" +score5);
int total = score1 + score2 + score3 + score4 + score5;
int average = ((score1 * 1)+(score2 * 2)+(score3 * 3)+(score4 *
4)+(score5 * 5))/ total;
System.out.println ();
System.out.println ("Total overall respondent: " +total);
System.out.println ("Average score result: " +average);
}
}
}
SAMPLE INPUT

SAMPLE OUTPUT
QUESTION 1.2

SOURCE CODE

import java.util.*;
import java.text.*;
public class Bill {

public static void main (String [] args)


{
Scanner input1 = new Scanner(System.in);
Scanner input2 = new Scanner(System.in);

DecimalFormat precision2 = new DecimalFormat("#.00");

final double HomeRent = 25.00;


final double CommercialRent = 50.00;
final double IndustrialRent = 100.00;
int totalcust1 =0;
int totalcust2 =0;
int totalcust3 =0;
double totalCollection1 =0.00;
double totalCollection2 =0.00;
double totalCollection3 =0.00;
double total = 0.00;
double bill = 0.00;
double grandTotal = 0.00;
char Feedback;

do
{
System.out.print("Enter your Name: ");
String name = input1.nextLine();
System.out.print("Enter your Address: ");
String address = input1.nextLine();

System.out.print("Enter your Category [1-Home 2-Commercial 3-


Industrial]: ");
int category = input2.nextInt();

while (category < 1 || category > 3)


{
System.out.print("Re-Enter your Category [1-Home 2-
Commercial 3-Industrial]: ");
category = input2.nextInt();
}

System.out.print("Enter your Units Used: ");


int units = input2.nextInt();

if ( category == 1)
{
if (units > 1 && units <= 100)
total = units * 0.1;
else if ( units <= 300)
total = (units - 100)* 0.17 + 10;
else
total = (units - 300)*0.2 + 10 + 34;

totalcust1 += 1;
bill = total + HomeRent;
totalCollection1 += bill;
}

else if ( category == 2)
{
if (units > 1 && units <= 200)
total = units * 0.3;
else if ( units <= 600)
total = (units - 200)* 0.27 + 60;
else
total = (units - 600)* 0.2 + 60 + 108 ;

totalcust2 += 1;
bill = total + CommercialRent;
totalCollection2 += bill;

else if( category == 3)


{
if (units > 1 && units <= 100)
total = units * 0.1;
else if ( units >= 200)
total = (units - 100)* 0.20 + 10 ;

totalcust3 += 1;
bill = total + IndustrialRent;
totalCollection3 += bill;

System.out.println("\ncustomer name: " +name);


System.out.println("customer address: " +address);
System.out.println ("customer category: "
+category);
System.out.println ("units used: " +units);
System.out.println("Bill(RM): "
+precision2.format(bill));

System.out.println ( "Add New Customer? [y or n]"


);
String response = input2.next();

Feedback =
response.toUpperCase().charAt(0);
System.out.println("\n");

}while (Feedback != 'N');


{
grandTotal = totalCollection1 +totalCollection2 +
totalCollection3;

System.out.println ( "\t\t\t\t Total customer\t Total Collection");


System.out.println ( "----------------------------------------------------------
----");
System.out.println ( "Home \t \t |\t\t\t" +totalcust1 +"\t\t\t\t"
+precision2.format(totalCollection1));
System.out.println ( "Commercial \t |\t\t\t" +totalcust2 +"\t\t\t\t"
+precision2.format(totalCollection2));
System.out.println ( "Industiral \t |\t\t\t" +totalcust3 +"\t\t\t\t"
+precision2.format(totalCollection3));
System.out.println ( "----------------------------------------------------------
----");
System.out.println ( "Total collection for the CityPhone
Telephone Company: " +precision2.format(grandTotal));
}
}
}
SAMPLE INPUT

SAMPLE OUTPUT

S-ar putea să vă placă și