import java.util.Scanner;
class TestPerson {
public static void main (String args[]) {
Scanner s = new Scanner(System.in);
String name;
int age,g;
boolean gender;
double salary;
//Person p;
System.out.println("Name\tAge\tGender\tSalary\tNet Pay");
System.out.println("-----------------------------------------");
for (int i=1; i < 3; i++) {
System.out.print("Enter name: ");
name = s.next();
System.out.print("Enter age: ");
age = s.nextInt();
System.out.print("Enter gender: (1-Male, 2-Female): ");
g = s.nextInt();
if (g==1)
gender = true;
else
gender = false;
System.out.print("Enter salary: ");
salary = s.nextDouble();
Person p = new Person(name,age,gender,salary);
System.out.println( p.display() );
} // for
} // main()
} //class
Thursday, 19 February 2009
Method 1: Person
public class Person {
private String name;
private int age;
private boolean gender;
private double salary;
public Person() { // default constructor
setPerson(null,0,false,0.0); //intialize the data for this object
}
public Person(String n, int a, boolean g, double s) { //proper constructor
setPerson(n,a,g,s);
}
private void setPerson(String n, int a, boolean g, double s) { //set method
name = n; age = a; gender = g; salary = s;
}
public String getName() {
return name;
}
public int getAge() {
return age;
}
public String getGender() {
return gender ? "Male" : "Female";
}
public double getSalary() {
return salary;
}
public double getNetSalary() {
return getSalary() - (getSalary()*0.1);
}
public String display() {
return getName()+"\t"+age+"\t"+getGender()+"\t"+salary+"\t"+getNetSalary();
}
}
private String name;
private int age;
private boolean gender;
private double salary;
public Person() { // default constructor
setPerson(null,0,false,0.0); //intialize the data for this object
}
public Person(String n, int a, boolean g, double s) { //proper constructor
setPerson(n,a,g,s);
}
private void setPerson(String n, int a, boolean g, double s) { //set method
name = n; age = a; gender = g; salary = s;
}
public String getName() {
return name;
}
public int getAge() {
return age;
}
public String getGender() {
return gender ? "Male" : "Female";
}
public double getSalary() {
return salary;
}
public double getNetSalary() {
return getSalary() - (getSalary()*0.1);
}
public String display() {
return getName()+"\t"+age+"\t"+getGender()+"\t"+salary+"\t"+getNetSalary();
}
}
Tuesday, 17 February 2009
LAB
// This is program is to calculate the total mark of exam and assignment
#include
void main ()
{
int mark1 ,mark2 ;
float total1,total2,sum;
printf ("Enter the total mark of the assignment \n");
scanf ("%d", &mark1);
printf ("Enter the total exam of the assignment \n");
scanf ("%d", &mark2);
total1=(mark1*40)/100;
if (total1 <16)
printf ("You have to RETAKE the paper \n");
else
printf ("You have pass the paper \n");
total2=(mark2*60)/100;
if (total1 <24)
printf ("You have to RESIT the paper \n");
else
printf ("You have pass the exam \n");
sum=total1=total2;
if (sum >= 70)
printf ("Grade A %f \n",sum);
else if (sum >= 60 && sum <=69)
printf ("Grade B %f \n",sum);
else
printf ("Grade C %f \n",sum);
}
#include
void main ()
{
int mark1 ,mark2 ;
float total1,total2,sum;
printf ("Enter the total mark of the assignment \n");
scanf ("%d", &mark1);
printf ("Enter the total exam of the assignment \n");
scanf ("%d", &mark2);
total1=(mark1*40)/100;
if (total1 <16)
printf ("You have to RETAKE the paper \n");
else
printf ("You have pass the paper \n");
total2=(mark2*60)/100;
if (total1 <24)
printf ("You have to RESIT the paper \n");
else
printf ("You have pass the exam \n");
sum=total1=total2;
if (sum >= 70)
printf ("Grade A %f \n",sum);
else if (sum >= 60 && sum <=69)
printf ("Grade B %f \n",sum);
else
printf ("Grade C %f \n",sum);
}
Monday, 16 February 2009
Counting Grade while repeating
// This program is to display the average in grade
#include
void main ()
{
int x;
int mark=0;
int sum=0;
float average=0;
char ans;
do {
for ( x = 0; x <5 ; x++)
{
printf("Enter 5 mark \n");
scanf ( "%d",&mark);
sum=sum+mark;
average = sum/5;
}
if (average>=70)
printf ("Grade A \n");
else if (average>=60 && average <=69)
printf ("Grade B \n");
else if (average>=50 && average <=59)
printf ("Grade C \n");
else if (average>=40 && average <=49)
printf ("Grade D \n");
else if (average<=40)
printf ("Grade E \n");
mark=0;
sum=0;
average=0;
printf ("Do you wan to continue :D \n");
getchar();
scanf ("%c",&ans);
}while ( ans =='y' || ans == 'Y');
}
#include
void main ()
{
int x;
int mark=0;
int sum=0;
float average=0;
char ans;
do {
for ( x = 0; x <5 ; x++)
{
printf("Enter 5 mark \n");
scanf ( "%d",&mark);
sum=sum+mark;
average = sum/5;
}
if (average>=70)
printf ("Grade A \n");
else if (average>=60 && average <=69)
printf ("Grade B \n");
else if (average>=50 && average <=59)
printf ("Grade C \n");
else if (average>=40 && average <=49)
printf ("Grade D \n");
else if (average<=40)
printf ("Grade E \n");
mark=0;
sum=0;
average=0;
printf ("Do you wan to continue :D \n");
getchar();
scanf ("%c",&ans);
}while ( ans =='y' || ans == 'Y');
}
Monday, 9 February 2009
C program While loop
#include
void main ()
{
int x;
int sum = 0;
printf ("Enter a number \n");
scanf ("%d",&x);
while (x != 0)
{
sum=sum+x;
printf ("Enter a number \n");
scanf ("%d",&x);
}
printf ("%d",sum);
}
void main ()
{
int x;
int sum = 0;
printf ("Enter a number \n");
scanf ("%d",&x);
while (x != 0)
{
sum=sum+x;
printf ("Enter a number \n");
scanf ("%d",&x);
}
printf ("%d",sum);
}
Friday, 6 February 2009
String
import java.util.Scanner;
public class operator {
public static void main (String args[])
{
Scanner s = new Scanner (System.in);
System.out.println (" Enter two number:");
int sum,minus, product, multiple;
float divide;
int x =s.nextInt();
int y =s.nextInt();
System.out.println (" Enter the desire operator | + | - | / | * | % |:");
String operator = s.next();
if (operator.equals( "+"))
{sum = x+y;
System.out.println (" The sum of the 2 number is "+sum);}
else if (operator.equals ("-"))
{minus = x-y;
System.out.println (" The minus of the 2 number is "+minus);}
else if (operator.equals ("/"))
{divide = x/y;
System.out.println (" The divide of the 2 number is "+divide);}
else if (operator.equals ("*"))
{product = x*y;
System.out.println (" The product of the 2 number is "+product);}
else if (operator.equals ("%"))
{multiple = x%y;
System.out.println (" The product of the 2 number is "+multiple);}
}
}
public class operator {
public static void main (String args[])
{
Scanner s = new Scanner (System.in);
System.out.println (" Enter two number:");
int sum,minus, product, multiple;
float divide;
int x =s.nextInt();
int y =s.nextInt();
System.out.println (" Enter the desire operator | + | - | / | * | % |:");
String operator = s.next();
if (operator.equals( "+"))
{sum = x+y;
System.out.println (" The sum of the 2 number is "+sum);}
else if (operator.equals ("-"))
{minus = x-y;
System.out.println (" The minus of the 2 number is "+minus);}
else if (operator.equals ("/"))
{divide = x/y;
System.out.println (" The divide of the 2 number is "+divide);}
else if (operator.equals ("*"))
{product = x*y;
System.out.println (" The product of the 2 number is "+product);}
else if (operator.equals ("%"))
{multiple = x%y;
System.out.println (" The product of the 2 number is "+multiple);}
}
}
Just for the sake of boring ness
import java.util.Scanner;
public class SwitchCase {
public static void main (String args[])
{
Scanner s = new Scanner (System.in);
System.out.println (" Select 1 - 12 to view the month");
int x =s.nextInt();
switch (x){
case 1:
System.out.println ("January");
break;
case 2:
System.out.println ("Febuary");
break;
case 3:
System.out.println ("March");
break;
case 4:
System.out.println ("April");
break;
case 5:
System.out.println ("May");
break;
case 6:
System.out.println ("June");
break;
case 7:
System.out.println ("July");
break;
case 8:
System.out.println ("August");
break;
case 9:
System.out.println ("September");
break;
case 10:
System.out.println ("October");
break;
case 11:
System.out.println ("November");
break;
case 12:
System.out.println ("December");
break;
default:
System.out.println ("-------------------------");
System.out.println ("|**** | ");
System.out.println ("|**** ( )");
System.out.println ("|**** | ");
System.out.println ("|**** / | \\ ");
System.out.println ("|**** / | \\ ");
System.out.println ("|**** | ");
System.out.println ("|**** / \\ ");
System.out.println ("|**** / \\ ");
System.out.println ("|****");
System.out.println ("-------------------------------------------------------------");
System.out.println ("U have select the wrong number");
break;
}
}
}
public class SwitchCase {
public static void main (String args[])
{
Scanner s = new Scanner (System.in);
System.out.println (" Select 1 - 12 to view the month");
int x =s.nextInt();
switch (x){
case 1:
System.out.println ("January");
break;
case 2:
System.out.println ("Febuary");
break;
case 3:
System.out.println ("March");
break;
case 4:
System.out.println ("April");
break;
case 5:
System.out.println ("May");
break;
case 6:
System.out.println ("June");
break;
case 7:
System.out.println ("July");
break;
case 8:
System.out.println ("August");
break;
case 9:
System.out.println ("September");
break;
case 10:
System.out.println ("October");
break;
case 11:
System.out.println ("November");
break;
case 12:
System.out.println ("December");
break;
default:
System.out.println ("-------------------------");
System.out.println ("|**** | ");
System.out.println ("|**** ( )");
System.out.println ("|**** | ");
System.out.println ("|**** / | \\ ");
System.out.println ("|**** / | \\ ");
System.out.println ("|**** | ");
System.out.println ("|**** / \\ ");
System.out.println ("|**** / \\ ");
System.out.println ("|****");
System.out.println ("-------------------------------------------------------------");
System.out.println ("U have select the wrong number");
break;
}
}
}
Tuesday, 3 February 2009
Switch !!
//*Calculate walt
#include
void main ()
{
int x;
printf ("Please enter the light bulb's wattage in the following list.\n");
printf ("|15|25|40|60|75|100|\n");
scanf ("%d",&x);
switch (x){
case 15:
printf ( "The brightness is 125. \n");
break;
case 25:
printf ( "The brightness is 215. \n");
break;
case 40:
printf ( "The brightness is 500. \n");
break;
case 60:
printf ( "The brightness is 880. \n");
break;
case 75:
printf ( "The brightness is 1000. \n");
break;
case 100:
printf ( "The brightness is 1675. \n");
break;
default:
printf ( "The brightness is -1. \n");
break;
}
}
#include
void main ()
{
int x;
printf ("Please enter the light bulb's wattage in the following list.\n");
printf ("|15|25|40|60|75|100|\n");
scanf ("%d",&x);
switch (x){
case 15:
printf ( "The brightness is 125. \n");
break;
case 25:
printf ( "The brightness is 215. \n");
break;
case 40:
printf ( "The brightness is 500. \n");
break;
case 60:
printf ( "The brightness is 880. \n");
break;
case 75:
printf ( "The brightness is 1000. \n");
break;
case 100:
printf ( "The brightness is 1675. \n");
break;
default:
printf ( "The brightness is -1. \n");
break;
}
}
C programming
#include
void main ()
{
float n;
printf ("Please enter the scale of the earthquake.\n");
scanf ("%f",&n);
if (n<5.0)
printf ("Little or no damage. \n");
else if (n >=5.0 && n < 5.5)
printf ( "Some damage. \n");
else if (n >= 5.5 && n < 6.5)
printf ( "Serious damage: walls may crack or fall. \n");
else if (n>=6.5 && n < 7.5)
printf ("Disaster: house and building may collapse. \n");
else if (n>= 7,5)
printf ("Catastrophe: Most building destroyed.\n");
printf ("GG.COM\n");
printf (" * \n");
printf (" ***** \n");
printf (" ***** \n");
printf (" ******* \n");
printf (" ********* \n");
printf (" ************* \n");
printf (" *************** \n");
printf (" ***************** \n");
}
void main ()
{
float n;
printf ("Please enter the scale of the earthquake.\n");
scanf ("%f",&n);
if (n<5.0)
printf ("Little or no damage. \n");
else if (n >=5.0 && n < 5.5)
printf ( "Some damage. \n");
else if (n >= 5.5 && n < 6.5)
printf ( "Serious damage: walls may crack or fall. \n");
else if (n>=6.5 && n < 7.5)
printf ("Disaster: house and building may collapse. \n");
else if (n>= 7,5)
printf ("Catastrophe: Most building destroyed.\n");
printf ("GG.COM\n");
printf (" * \n");
printf (" ***** \n");
printf (" ***** \n");
printf (" ******* \n");
printf (" ********* \n");
printf (" ************* \n");
printf (" *************** \n");
printf (" ***************** \n");
}
Coding q3 *JAVA*
To calculate sum,product,average,smallest,largest
import java.util.Scanner;
public class Application {
public static void main (String args[])
{
Scanner s = new Scanner (System.in);
System.out.println (" Enter your number:");
int sum, product,smallest,largest;
float average;
int x =s.nextInt();
int y =s.nextInt();
int z =s.nextInt();
sum = x+y+z;
average = (x+y+z)/3;
product = x*y*z;
System.out.println ("The sum of the 3 integer is " +sum);
System.out.println ("The average of the 3 integer is " +average);
System.out.println ("The product of the 3 integer is " +product);
if (x>y && x>z)
System.out.println ("The largest integer is " +x);
else if (y>x && y>z)
System.out.println ("The largest integer is " +y);
else
System.out.println ("The largest integer is " +z);
if (x System.out.println ("The smallest integer is " +x);
else if (y System.out.println ("The smallest integer is " +y);
else
System.out.println ("The smallest integer is " +z);
}
}
import java.util.Scanner;
public class Application {
public static void main (String args[])
{
Scanner s = new Scanner (System.in);
System.out.println (" Enter your number:");
int sum, product,smallest,largest;
float average;
int x =s.nextInt();
int y =s.nextInt();
int z =s.nextInt();
sum = x+y+z;
average = (x+y+z)/3;
product = x*y*z;
System.out.println ("The sum of the 3 integer is " +sum);
System.out.println ("The average of the 3 integer is " +average);
System.out.println ("The product of the 3 integer is " +product);
if (x>y && x>z)
System.out.println ("The largest integer is " +x);
else if (y>x && y>z)
System.out.println ("The largest integer is " +y);
else
System.out.println ("The largest integer is " +z);
if (x
else if (y
else
System.out.println ("The smallest integer is " +z);
}
}
WTF CODE
import java.util.Scanner;
public class q4
{
public static void main (String args[])
{
Scanner s = new Scanner (System.in);
System.out.println (" Enter 5 number:");
int pos = 0,neg = 0,zero = 0,x;
int num1 =s.nextInt();
int num2 =s.nextInt();
int num3 =s.nextInt();
int num4 =s.nextInt();
int num5 =s.nextInt();
if (num1 >0)
pos++;
else if (num1<0)
neg++;
else
zero++;
if (num2 >0)
pos++;
else if (num2<0)
neg++;
else
zero++;
if (num3 >0)
pos++;
else if (num3<0)
neg++;
else
zero++;
if (num4 >0)
pos++;
else if (num4<0)
neg++;
else
zero++;
if (num5 >0)
pos++;
else if (num5<0)
neg++;
else
zero++;
System.out.println ( " The number of posittive numbers are " +pos);
System.out.println ( " The number of negative numbers are " +neg);
System.out.println ( " The number of zero numbers are " +zero);
}
}
public class q4
{
public static void main (String args[])
{
Scanner s = new Scanner (System.in);
System.out.println (" Enter 5 number:");
int pos = 0,neg = 0,zero = 0,x;
int num1 =s.nextInt();
int num2 =s.nextInt();
int num3 =s.nextInt();
int num4 =s.nextInt();
int num5 =s.nextInt();
if (num1 >0)
pos++;
else if (num1<0)
neg++;
else
zero++;
if (num2 >0)
pos++;
else if (num2<0)
neg++;
else
zero++;
if (num3 >0)
pos++;
else if (num3<0)
neg++;
else
zero++;
if (num4 >0)
pos++;
else if (num4<0)
neg++;
else
zero++;
if (num5 >0)
pos++;
else if (num5<0)
neg++;
else
zero++;
System.out.println ( " The number of posittive numbers are " +pos);
System.out.println ( " The number of negative numbers are " +neg);
System.out.println ( " The number of zero numbers are " +zero);
}
}
Subscribe to:
Posts (Atom)