CLASS CAR //tapi sayapunya ni namanya :lab_dip_6_car
import javax.swing.JOptionPane;
class lab_dip_6_car
{
String make;
String type;
double cc;
String color;
lab_dip_6_car(String carmake, String cartype,double num, String kaler)
{
make=carmake;
type=cartype;
cc=num;
color=kaler;
}
void print()
{
System.out.println("Make : "+make);
System.out.println("Type : "+type);
System.out.println("CC : "+cc);
System.out.println("Colour : "+color);
System.out.println();
}
}
THE MAIN CLASS
import javax.swing.JOptionPane;
public class lab_dip_6_soalan1
{
public static void main(String args[])
{
lab_dip_6_car mycar=new lab_dip_6_car("Perodua","Kelisa",1.7,"Red");
mycar.print();
System.exit(0);
}
}
Friday, February 17, 2006
Tuesday, February 07, 2006
acres
korang nakpi mana? acres? hecters? macres? (^,^) o...sesapa yg ada namanya tu, jalan bebaik.
ok chow, selamat menyambut Thaipusam kepada sesapa yg menyambutnye.
ok chow, selamat menyambut Thaipusam kepada sesapa yg menyambutnye.
JAWABAN LAB5
Soalan1
import javax.swing.*;
public class lab_dip_5_soalan1
{
public static void main(String args[])
{
int num;
String hasilproses;
num=input();
hasilproses=process( num);
output(num,hasilproses);
System.exit(0);
}
public static int input()
{
int no;
no=Integer.parseInt(JOptionPane.showInputDialog(null,"Enter an integer : "));
return no;
}
public static String process(int no)
{
int baki;
String hasil;
baki=no%2;
if(baki==0)
hasil="even";
else
hasil="odd";
return hasil;
}
public static void output(int no,String hasil)
{
JOptionPane.showMessageDialog(null,no+" is an "+hasil+" integer", "Output",JOptionPane.INFORMATION_MESSAGE);
}
}
Soalan2
import javax.swing.*;
public class lab_dip_5_soalan2
{
public static void main(String args[])
{
double weight, height;
String result;
weight=inputWeight();
height=inputHeight();
result=analyze( height, weight);
output( height, weight, result);
System.exit(0);
}
public static double inputWeight()
{
double weight;
weight=Integer.parseInt(JOptionPane.showInputDialog(null,"Enter weight : "));
return weight;
}
public static double inputHeight()
{
double height;
height=Integer.parseInt(JOptionPane.showInputDialog(null,"Enter height : "));
return height;
}
public static String analyze(double height,double weight)
{
double bmi=weight/((height/100)*(height/100));
String result;
if (bmi<=25)
result="Normal";
else if(bmi>25&&bmi<30)
result="Fat";
else
result="Obese";
return result;
}
public static void output(double height,double weight,String result)
{
JOptionPane.showMessageDialog(null,"Weight : "+weight+"\nHeight : "+height+"\n\nFrom my BMI
>> "+result,"Output",JOptionPane.INFORMATION_MESSAGE);
}
}
import javax.swing.*;
public class lab_dip_5_soalan1
{
public static void main(String args[])
{
int num;
String hasilproses;
num=input();
hasilproses=process( num);
output(num,hasilproses);
System.exit(0);
}
public static int input()
{
int no;
no=Integer.parseInt(JOptionPane.showInputDialog(null,"Enter an integer : "));
return no;
}
public static String process(int no)
{
int baki;
String hasil;
baki=no%2;
if(baki==0)
hasil="even";
else
hasil="odd";
return hasil;
}
public static void output(int no,String hasil)
{
JOptionPane.showMessageDialog(null,no+" is an "+hasil+" integer", "Output",JOptionPane.INFORMATION_MESSAGE);
}
}
Soalan2
import javax.swing.*;
public class lab_dip_5_soalan2
{
public static void main(String args[])
{
double weight, height;
String result;
weight=inputWeight();
height=inputHeight();
result=analyze( height, weight);
output( height, weight, result);
System.exit(0);
}
public static double inputWeight()
{
double weight;
weight=Integer.parseInt(JOptionPane.showInputDialog(null,"Enter weight : "));
return weight;
}
public static double inputHeight()
{
double height;
height=Integer.parseInt(JOptionPane.showInputDialog(null,"Enter height : "));
return height;
}
public static String analyze(double height,double weight)
{
double bmi=weight/((height/100)*(height/100));
String result;
if (bmi<=25)
result="Normal";
else if(bmi>25&&bmi<30)
result="Fat";
else
result="Obese";
return result;
}
public static void output(double height,double weight,String result)
{
JOptionPane.showMessageDialog(null,"Weight : "+weight+"\nHeight : "+height+"\n\nFrom my BMI
>> "+result,"Output",JOptionPane.INFORMATION_MESSAGE);
}
}
Thursday, February 02, 2006
testing power for the 1st time
assalamualaikum ya korang....
good luck 4 ur test a...
pastikan betul2 paham pasal suma loop statement yang ada:if/while/do-while/switch/for
tgk syntax betul2...pastikan paham aper yg ditulis....
gambatte!!! p(^o^)q
chow...
good luck 4 ur test a...
pastikan betul2 paham pasal suma loop statement yang ada:if/while/do-while/switch/for
tgk syntax betul2...pastikan paham aper yg ditulis....
gambatte!!! p(^o^)q
chow...
JAWABAN LAB4
soalan1
import javax.swing.*;
import java.text.*;
public class lab_dip_4_soalan1
{
public static void main(String args[])
{
int input;
String output="";
input=Integer.parseInt(JOptionPane.showInputDialog(null,"Enter a value : "));
while(input!=0)
{
output+=input+"\t ";
input--;
}
JOptionPane.showMessageDialog(null,output,"USING WHILE",JOptionPane.INFORMATION_MESSAGE); System.exit(0);
}
}
soalan2
import javax.swing.*;
import java.text.*;
public class lab_dip_4_soalan2
{
public static void main(String args[])
{
int sum=0;
int input;
do
{
input=Integer.parseInt(JOptionPane.showInputDialog(null,"Enter an integer value\nProgram exit if input is 0\n"));
sum+=input;
}while(input!=0);
JOptionPane.showMessageDialog(null,"Sum : "+sum,"USING DO-WHILE",JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
}
}
soalan3
import javax.swing.*;
import java.text.*;
public class lab_dip_4_soalan3
{
public static void main(String args[])
{
int item;
String deli;
int bil_item;
double item_price,price;
DecimalFormat p=new DecimalFormat("0.00");
item=Integer.parseInt(JOptionPane.showInputDialog(null,"My Favourite Bakery\n\nCODE BREAD\n210 Mexican Bun\n122 Chocolate Donut\n768 Sausage Bun\n234 Cheese Stick \n\n[Enter Code] \nI want to buy :"));
bil_item=Integer.parseInt(JOptionPane.showInputDialog(null,"How many do you want to buy?"));
switch(item)
{
case 210: item_price=1.90;
deli="Mexican Bun";
break;
case 122: item_price=1.80;
deli="Chocolate Donut";
break;
case 768: item_price=1.50;
deli="Sausage Bun";
break;
case 234: item_price=1.00;
deli="Cheese Stick";
break;
default: item_price=0.00;
bil_item=0;
deli="No such thing at our bakery...";
}
price=item_price*bil_item;
JOptionPane.showMessageDialog(null,deli+"\n\nBuy = "+bil_item+"\n\nPrice = RM "+p.format(price),"USING SWITCH STATEMENT",JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
}
}
import javax.swing.*;
import java.text.*;
public class lab_dip_4_soalan1
{
public static void main(String args[])
{
int input;
String output="";
input=Integer.parseInt(JOptionPane.showInputDialog(null,"Enter a value : "));
while(input!=0)
{
output+=input+"\t ";
input--;
}
JOptionPane.showMessageDialog(null,output,"USING WHILE",JOptionPane.INFORMATION_MESSAGE); System.exit(0);
}
}
soalan2
import javax.swing.*;
import java.text.*;
public class lab_dip_4_soalan2
{
public static void main(String args[])
{
int sum=0;
int input;
do
{
input=Integer.parseInt(JOptionPane.showInputDialog(null,"Enter an integer value\nProgram exit if input is 0\n"));
sum+=input;
}while(input!=0);
JOptionPane.showMessageDialog(null,"Sum : "+sum,"USING DO-WHILE",JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
}
}
soalan3
import javax.swing.*;
import java.text.*;
public class lab_dip_4_soalan3
{
public static void main(String args[])
{
int item;
String deli;
int bil_item;
double item_price,price;
DecimalFormat p=new DecimalFormat("0.00");
item=Integer.parseInt(JOptionPane.showInputDialog(null,"My Favourite Bakery\n\nCODE BREAD\n210 Mexican Bun\n122 Chocolate Donut\n768 Sausage Bun\n234 Cheese Stick \n\n[Enter Code] \nI want to buy :"));
bil_item=Integer.parseInt(JOptionPane.showInputDialog(null,"How many do you want to buy?"));
switch(item)
{
case 210: item_price=1.90;
deli="Mexican Bun";
break;
case 122: item_price=1.80;
deli="Chocolate Donut";
break;
case 768: item_price=1.50;
deli="Sausage Bun";
break;
case 234: item_price=1.00;
deli="Cheese Stick";
break;
default: item_price=0.00;
bil_item=0;
deli="No such thing at our bakery...";
}
price=item_price*bil_item;
JOptionPane.showMessageDialog(null,deli+"\n\nBuy = "+bil_item+"\n\nPrice = RM "+p.format(price),"USING SWITCH STATEMENT",JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
}
}
JAWABAN LAB3
satu soalan sahaja....
import javax.swing.*;
public class lab_dip_3_soalan1
{
public static void main(String args[])
{
String name;
double income_tax,kwsp,travel_allowance,grosspay,salary;
int employee_id,days_work;
name=JOptionPane.showInputDialog(null,"Enter your name:","INPUT NAME",JOptionPane.QUESTION_MESSAGE);
employee_id=Integer.parseInt(JOptionPane.showInputDialog(null,"Enter your employee identification number :","INPUT ID",JOptionPane.QUESTION_MESSAGE));
days_work=Integer.parseInt(JOptionPane.showInputDialog(null,"Enter number of days work :","INPUT DAYS WORKED",JOptionPane.QUESTION_MESSAGE));
grosspay=days_work*200;
travel_allowance=0.04*grosspay;
income_tax=0.03*grosspay;
kwsp=0.02*grosspay;
salary=grosspay+travel_allowance-income_tax-kwsp;
JOptionPane.showMessageDialog(null,"Employee ID : "+employee_id+"\nEmployee name : "+name+"\n\nGrosspay = RM "+grosspay+"\nTravel allowance = RM "+travel_allowance+"\nIncome tax = RM "+income_tax+"\nKWSP = RM "+kwsp+"\n\nSalary = RM "+salary,"RESULT",JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
}
}
import javax.swing.*;
public class lab_dip_3_soalan1
{
public static void main(String args[])
{
String name;
double income_tax,kwsp,travel_allowance,grosspay,salary;
int employee_id,days_work;
name=JOptionPane.showInputDialog(null,"Enter your name:","INPUT NAME",JOptionPane.QUESTION_MESSAGE);
employee_id=Integer.parseInt(JOptionPane.showInputDialog(null,"Enter your employee identification number :","INPUT ID",JOptionPane.QUESTION_MESSAGE));
days_work=Integer.parseInt(JOptionPane.showInputDialog(null,"Enter number of days work :","INPUT DAYS WORKED",JOptionPane.QUESTION_MESSAGE));
grosspay=days_work*200;
travel_allowance=0.04*grosspay;
income_tax=0.03*grosspay;
kwsp=0.02*grosspay;
salary=grosspay+travel_allowance-income_tax-kwsp;
JOptionPane.showMessageDialog(null,"Employee ID : "+employee_id+"\nEmployee name : "+name+"\n\nGrosspay = RM "+grosspay+"\nTravel allowance = RM "+travel_allowance+"\nIncome tax = RM "+income_tax+"\nKWSP = RM "+kwsp+"\n\nSalary = RM "+salary,"RESULT",JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
}
}
JAWABAN LAB2
soalan1
// JAWAPAN MENGGUNAKAN S.O.P
import java.text.*;
public class lab_dip_2_soalan1
{
public static void main(String args[])
{
double Celcius; double Fahrenheit;
System.out.print("Celcius =");
Celcius=MyInput.readDouble();
Fahrenheit=((Celcius*9)/5)+32;
System.out.println("Fahrenheit ="+Fahrenheit);
}
}
//JAWAPAN MENGGUNAKAN J.O.P
import javax.swing.JOptionPane;
public class lab_dip_2_soalan1
{
public static void main(String args[])
{
double Celcius; double Fahrenheit;
Celcius=Double.parseDouble(JOptionPane.showInputDialog(null,"Celcius =","INPUT CELCIUS",JOptionPane.QUESTION_MESSAGE));
Fahrenheit=((Celcius*9)/5)+32;
JOptionPane.showMessageDialog(null,"Fahrenheit ="+Fahrenheit,"THE OUTPUT",JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
}
}
soalan2
//MENGGUNAKAN S.O.P
import java.text.*;
public class lab_dip_2_soalan2
{
public static void main(String args[])
{
double a; double b; double sum,diff,pro,div;
System.out.print("Enter the first value :");
a=MyInput.readDouble();
System.out.print("Enter the second value :");
b=MyInput.readDouble();
sum=a+b;
diff=a-b;
pro=a*b;
div=a/b;
System.out.println("Sum ="+sum+"\n"+"Difference ="+diff+"\n"+"Product ="+pro+"\n"+"Division ="+div);
}
}
//MENGGUNAKAN J.O.P
import javax.swing.JOptionPane;
public class lab_dip_2_soalan2
{
public static void main(String args[])
{
double a;
double b;
double sum,diff,pro,div;
String output="";
a=Double.parseDouble(JOptionPane.showInputDialog(null,"First Value =","INPUT VALUE",JOptionPane.QUESTION_MESSAGE));
b=Double.parseDouble(JOptionPane.showInputDialog(null,"First Value =","INPUT VALUE",JOptionPane.QUESTION_MESSAGE));
sum=a+b;
diff=a-b;
pro=a*b;
div=a/b;
output+="Sum ="+sum+"\n"+"Difference ="+diff+"\n"+"Product ="+pro+"\n"+"Division ="+div;
JOptionPane.showMessageDialog(null,output,"RESULT",JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
}
}
// JAWAPAN MENGGUNAKAN S.O.P
import java.text.*;
public class lab_dip_2_soalan1
{
public static void main(String args[])
{
double Celcius; double Fahrenheit;
System.out.print("Celcius =");
Celcius=MyInput.readDouble();
Fahrenheit=((Celcius*9)/5)+32;
System.out.println("Fahrenheit ="+Fahrenheit);
}
}
//JAWAPAN MENGGUNAKAN J.O.P
import javax.swing.JOptionPane;
public class lab_dip_2_soalan1
{
public static void main(String args[])
{
double Celcius; double Fahrenheit;
Celcius=Double.parseDouble(JOptionPane.showInputDialog(null,"Celcius =","INPUT CELCIUS",JOptionPane.QUESTION_MESSAGE));
Fahrenheit=((Celcius*9)/5)+32;
JOptionPane.showMessageDialog(null,"Fahrenheit ="+Fahrenheit,"THE OUTPUT",JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
}
}
soalan2
//MENGGUNAKAN S.O.P
import java.text.*;
public class lab_dip_2_soalan2
{
public static void main(String args[])
{
double a; double b; double sum,diff,pro,div;
System.out.print("Enter the first value :");
a=MyInput.readDouble();
System.out.print("Enter the second value :");
b=MyInput.readDouble();
sum=a+b;
diff=a-b;
pro=a*b;
div=a/b;
System.out.println("Sum ="+sum+"\n"+"Difference ="+diff+"\n"+"Product ="+pro+"\n"+"Division ="+div);
}
}
//MENGGUNAKAN J.O.P
import javax.swing.JOptionPane;
public class lab_dip_2_soalan2
{
public static void main(String args[])
{
double a;
double b;
double sum,diff,pro,div;
String output="";
a=Double.parseDouble(JOptionPane.showInputDialog(null,"First Value =","INPUT VALUE",JOptionPane.QUESTION_MESSAGE));
b=Double.parseDouble(JOptionPane.showInputDialog(null,"First Value =","INPUT VALUE",JOptionPane.QUESTION_MESSAGE));
sum=a+b;
diff=a-b;
pro=a*b;
div=a/b;
output+="Sum ="+sum+"\n"+"Difference ="+diff+"\n"+"Product ="+pro+"\n"+"Division ="+div;
JOptionPane.showMessageDialog(null,output,"RESULT",JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
}
}
JAWABAN LAB1
jawapan untuk lab1, specially made by me (^,^)
soalan1
public class lab_dip_1_soalan1
{
public static void main(String args[])
{
System.out.println(" * * * * * * * * * * * * * *");
System.out.println(" * *");
System.out.println(" * *");
System.out.println(" * *");
System.out.println(" * Welcome to JAVA!!! *");
System.out.println(" * *");
System.out.println(" * *");
System.out.println(" * *");
System.out.println(" * * * * * * * * * * * * * *");
System.out.println();
}
}
soalan2
import javax.swing.JOptionPane;
public class lab_dip_1_soalan2
{
public static void main(String args[])
{
JOptionPane.showMessageDialog(null,"Fantastique J A V A !!!",
"Lab 1.2 Using JOptionPane",JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
}
}
soalan3
import javax.swing.JOptionPane;
public class lab_dip_1_soalan3
{
public static void main(String args[])
{
JOptionPane.showMessageDialog(null,"112233\nMuhammad Arif",
"MAKLUMAT DIRI",JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
}
}
soalan1
public class lab_dip_1_soalan1
{
public static void main(String args[])
{
System.out.println(" * * * * * * * * * * * * * *");
System.out.println(" * *");
System.out.println(" * *");
System.out.println(" * *");
System.out.println(" * Welcome to JAVA!!! *");
System.out.println(" * *");
System.out.println(" * *");
System.out.println(" * *");
System.out.println(" * * * * * * * * * * * * * *");
System.out.println();
}
}
soalan2
import javax.swing.JOptionPane;
public class lab_dip_1_soalan2
{
public static void main(String args[])
{
JOptionPane.showMessageDialog(null,"Fantastique J A V A !!!",
"Lab 1.2 Using JOptionPane",JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
}
}
soalan3
import javax.swing.JOptionPane;
public class lab_dip_1_soalan3
{
public static void main(String args[])
{
JOptionPane.showMessageDialog(null,"112233\nMuhammad Arif",
"MAKLUMAT DIRI",JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
}
}
Subscribe to:
Comments (Atom)
