Friday, March 28, 2008

transcriptStudent using array and method


exercise for test 1

public class Test
{
public static void main()
{
int x = 2;
int y = 3;
System.out.println(++y);
System.out.println(y++);
System.out.println(++x);
System.out.println(x++);
}
}

Thursday, March 6, 2008

Volume.java

public class Volume{

public static void main (String[] args)

{
double radius;
double area;
double volume;
double length;

length = 21;
radius = 7;
area = radius * radius * 3.134;
volume = area * length;

System.out.println("The volume for the cilinder of = " + area + " area = " + volume);
}

}

TestGrades.java

import javax.swing.JOptionPane;

public class TestGrades
{
public static void main (String[] args)
{
String matricNo, grade;
int score;
int studentCount = 0;
int totalA=0;
int totalB=0;
int totalC=0;
int totalD=0;
int totalF=0;

while (studentCount<200)
{
matricNo = JOptionPane.showInputDialog(null, "Enter matric no:", "Test Grades", JOptionPane.QUESTION_MESSAGE);
String inputScore = JOptionPane.showInputDialog(null, "Enter score:", "Test Grades", JOptionPane.QUESTION_MESSAGE);
score = Integer.parseInt(inputScore);

if (score>=90 && score<=100) {
grade = "A";
totalA++;
}
else if (score>=78 && score<90) {
grade = "B";
totalB++;
}
else if (score>=65 && score<78) {
grade = "C";
totalC++;
}
else if (score>=50 && score<65) {
grade = "D";
totalD++;
}
else {
grade = "F";
totalF++;
}
System.out.println("Matric no: " + matricNo);
System.out.println("Score: " + score);
System.out.println("Grade: " + grade);
System.out.println();
studentCount++;
}
//JOptionPane.showMessageDialog(null, "Enter matric no:", "Test Grades", JOptionPane.INFORMATION_MESSAGE);
System.out.println("Total number of As is " + totalA);
System.out.println("Total number of Bs is " + totalB);
System.out.println("Total number of Cs is " + totalC);
System.out.println("Total number of Ds is " + totalD);
System.out.println("Total number of Fs is " + totalF);

System.exit(0);
}
}

salary.java

public class salary{

public static void main (String[] args)

{
double productA;
double productB;
double productC;
double productD;
double weeklyCommission;
double weeklySalary;

productA = 70;
productB = 50;
productC = 325;
productD = 300;
weeklyCommission = 0.05 * (productA + productB + productC + productD);
weeklySalary = 200 + weeklyCommission;

System.out.println("The weekly salary = " + weeklySalary + " which weekly commission = " + weeklyCommission);
}

}

MultiplicationTable.java

// Program to Display Multiplication Table

public class MultiplicationTable
{
public static void main(String [] args)
{
for(int i=1; i<=9 ;i++)
System.out.print(" " + i);
System.out.println();

for(int i=1; i<=9 ;i++)
{
System.out.print(i);
for(int j=1; j<=i;j++)
{
//int product = i*j;
System.out.printf(" %2d ", i*j);
}
System.out.println();
}
}
}

save as gallon.java

public class gallon{

public static void main (String[] args)

{
double lengthRoom;
double widthRoom;
double heigthRoom;
double winA;
double winB;
double room;
double windows;
double area;
double gallon;

lengthRoom = 12;
widthRoom = 10;
heigthRoom = 8;
winA = 5 * 3;
winB = 6 * 2;
room = lengthRoom * widthRoom * heigthRoom;
windows = winA + winB;
area = room - windows;
gallon = area / 100;

System.out.println("Amount of painter need = " + gallon + " gallon paint");
}

}