Professional Documents
Culture Documents
Code
Code
Hello World
public class Mico {
System.out.println("Hello World!");
}
}
MESSAGE
import javax.swing.JOptionPane;
System.exit(0);
}
}
public class VariableDeclaration{
public static void main(String args[]) {
char c='M';
byte numberByte = 1;
int numberInteger =1434414344;
short numberShort = 14344;
long numberLong = 1234567890;
System.out.println("Character = " + c );
status = "Passed";
}else {
status = "Failed";
}
1. Create a program that will input the following data: Employee Number, Employee LastName,
Employee FirstName, Rate per hour, Number of Hours Worked. Compute and output the Gross Pay, SSS
Deduction, Tax Withhold, Total Deduction, Net Pay. ( Use JOptionPane)
import javax.swing.JOptionPane;
/* GP = Gross Pay
SD = SSS Deduction
T = Tax Withhold
TD = Total Deduction
EN = Employee Number
NT = Net Pay
*/
float R= float.valueOf(Rph);
float GP = Nw * R;
double SD = GP * .05;
double T = GP * .10;
double TD = SD + T;
double NP = GP - TD;
JOptionPane.ShowMessageDialog(null,
"Employee Number: " + EN + "\nEmployee First Name: " + EFN + "/nEmployee Last Name: " + ELN +
"\nEmployee Rate per hour: " + R + "\nNumber of hours worked: " + Nw + "\nGross Pay: " + GP + "\
nSSS Deduction : " + SD +
}
2. This program computes the interest earned on 17,000 pesos with an interest
rate of .70 a year. The interest and the value of the investment after one year are
printed to standard output.
/* VI = Value of Investment
IR = Interest Rate
I = Interest earned in one year
VIOY = Value of Investment after One Year
*/
int VI = 17000;
double IR = .70;
double I;
I = VI * IR * 1;
double VIOY = VI*(1 + IR);
3. Create a program that will input for the following data: (Using Scanner)
Student Name, Course
Grade in Quiz, Seatwork, Laboratory Exercises and Prelim
Compute and output the Prelim Grade.
Prelim Grade = Quiz * 25% + Seatwork * 20% + Lab. Exercise * 25% + Prelim Exam
* 30%
import java.util.Scanner;
}else{
System.out.println("Sorry " + SN + " you failed.");
}
}
}
}
}
2. Use JOptionPane
import javax.swing.JOptionPane;
public class InputJOptionPane
{
public static void main (String[] args)
{
double pi = 3.151519;
String radius =JOptionPane.showInputDialog ("Enter the Circle's Radius:");
double r = Double.valueOf(radius); //Convets String to Double
double area = pi * r * r;
double circumference = 2 * pi * r;
3. Use Scanner
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner( System.in );
}
}
BufferedReader
package com.runner;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
}
Scanner
package com.runner;
import java.util.Scanner;
public class Eclipse {
Scanner
with decimal
package com.runner;
import java.util.Scanner;
JOptionPane
Message
package com.runner;
import javax.swing.JOptionPane;
JOptionPane
Message (double)
package com.runner;
import javax.swing.JOptionPane;
firstNum =
Double.parseDouble(JOptionPane.showInputDialog("Enter a number"));
secondNum =
Double.parseDouble(JOptionPane.showInputDialog("Enter a number"));
sum = firstNum + secondNum;
JOptionPane.showMessageDialog(null,
"The sum is " + sum);