WHAT'S NEW?
Loading...
Showing posts with label java programs. Show all posts
Showing posts with label java programs. Show all posts

FUNCTIONS BASED PROGRAM

class a
{
    public static void main(String args[])
    {
        five ob1=new five();   //syntax: class_name objectname= new classname();
        five ob2= new five();
       
        ob1.func(100);
        ob2.func(300);
    }
}
class five
{
    void func(int mins)
    {
        int hours=mins/60;
        int minutes=mins%60;
       
        System.out.println("The time in hours and minutes is = " +hours + " hours and " +minutes + " minutes");
    }
}

FUNCTIONS BASED PROGRAM - convert inches & feet into cm

class distance
{
    double distinches, distfeet;   
    void func(double inches, double feet)
    {
        distinches=inches;
        distfeet=feet;
    }
   
    void compute()
    {
        double cm;
        cm=2.54*distinches + 30.48*distfeet; //1 INCH=2.54 cm &1 feet=30.48 cm
       
        System.out.println("The total distance in centimetres is = " +cm);
    }
}
    

FUNCTIONS BASED PROGRAM - convert celcius into fahrenheit

class display
{
    public static void main(String args[])
    {
        temperature ob= new temperature();
        double temp=ob.convert(25.0);
        System.out.println("The temperature in fahrenheit is = "+temp);
    }
}
class temperature
{
    double convert(double celcius)
    {
        double far=1.8*celcius+32.0;
        return far;
    }
}

FUNCTIONS BASED PROGRAM - void function & function with a return type

class aman
{
    public static void main(String args[])
    {
        func ob=new func();
        int ans=ob.sum(10,20); //function call
        System.out.println("the answer is = " +ans);
       
        ob.product(20,50);  //function call
       
       
    }
}
      

class func
{
    int sum(int a, int b)            //function with return type
    {
        int c=a+b;
        return c;
       
       
    }
    void product(int a, int b)     // function with no return type
    {
          int c=a*b;
          System.out.println("the product is = " +c);
    }
}

ICSE BOARD QUESTION 2008 - program to input a string and print out the text with the uppercase and lowercase letters reversed , but all other characters should remain the same as before.

/**ICSE BOARD QUESTION 2008
 * Write a program to input a string and print out the text 
 * with the uppercase and lowercase letters reversed ,
 * but all other characters should remain the
 * same as before. 
 * EXAMPLE: INPUT:  WelComE TO School
 *          OUTPUT: wELcOMe to sCHOOL
 * 
 */
import java.io.*;
public class questionFIVE2008
{
    public static void main(String args[]) throws IOException
    {
        int ch;
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        System.out.println("ENTER THE STRING ");
        String input=br.readLine();
        int len=input.length();
        int i;
        for(i=0; i<len; i++)
        {
            ch=input.charAt(i);
            if(ch>=65 && ch<=90)
            {
                ch=ch+32;
                System.out.print((char)ch);
            }
            else if(ch>=97 && ch<=122)
            {
                ch=ch-32;
                System.out.print((char)ch);
            }
            else
            {
                System.out.print((char)ch);
            }
        }
    }
}

OUTPUT:
ENTER THE STRING 
WelComE TO School

wELcOMe to sCHOOL

USE OF FUNCTIONS & CONSTRUCTORS_ROBIN

import java.io.*;
class usesales
{
    public static void main(String args[]) throws IOException
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        sales ob=new sales();
        sales ob1=new sales(001, "Robin", 3, 1000);
        System.out.println("Enter sales ID");
        int s=Integer.parseInt(br.readLine());
        System.out.println("Enter NAME");
        String n=br.readLine();
        System.out.println("Enter Quantity");
        int q=Integer.parseInt(br.readLine());
        System.out.println("Enter Price");
        int p=Integer.parseInt(br.readLine());
        ob.morning();
        ob.new_sales(s,n,q,p);
        ob.calcbill();
        int billret=ob.returnbill();
        String nameret=ob.returnname();
        System.out.println("The bill on your NAME: " +nameret+ " is =  " +billret);

        //now using the object created for parametrized constructor
        ob1.calcbill();
        billret=ob1.returnbill();
        nameret=ob1.returnname();
        System.out.println("The bill on your NAME: " +nameret+ " is =  " +billret);
    }
}
    
   

class sales
{
    int salesid;
    String name;
    int qty;
    int price;
    int bill;
   
    sales()
    {
        salesid=0;
        name="";
        qty=0;
        price=0;
    }
     sales(int sid, String n, int q, int p)
     {
        salesid=sid;
        name=n;
        qty=q;
        price=p;
    }
    void morning()
    {
        for(int i=1;i<=5;i++)
        {
            System.out.println("GOOD MORNING");
        }
    }
    void new_sales(int id, String nm, int qt, int pr)
    {
        salesid=id;
        name=nm;
        qty=qt;
        price=pr;
    }
    void calcbill()
    {
        bill=qty*price;
    }
    int returnbill()
    {
        return bill;
    }
    String returnname()
    {
        return name;
    }
}


OUTPUT:
Enter sales ID
007
Enter NAME
AMAN
Enter Quantity
10
Enter Price
500
GOOD MORNING
GOOD MORNING
GOOD MORNING
GOOD MORNING
GOOD MORNING
The bill on your NAME: AMAN is =  5000
The bill on your NAME: Robin is =  3000

Passing object as parameter: Calculate distance between two points Coordinate Geometry

class sukhman
{
    public static void main(String args[])
    {
       point conobj=new point(1,1);  //parametrized constructor will get invoked
       point ob=new point();         //object 1   
       point ob1=new point();        //object 2
       ob.translator(-2,-3);
       ob1.translator(-4,4);
       double ans=ob.distance(ob1);   //passing object as parameter
       System.out.println("The distance between two points is = "+ans);
    }
}


class point
{
    int x,y;
    point()
    {
        x=0;
        y=0;
    }
    point(int a,int b)
    {
        x=a;
        y=b;
    }
    void translator(int xp, int yp)
    {
        x=xp;
        y=yp;
    }
    double distance(point obj)
    {
        double xs=Math.pow((obj.x-x),2);
        double ys=Math.pow((obj.y-y),2);
        double d=Math.sqrt(xs+ys);   //formula in coordinate geometry
        return d;
    }
}

OUTPUT:
The distance between two points is = 7.280109889280518

Program to accept 5 strings on Terminal window

/*
 * Program to accept 5 strings on Terminal window
 */

import java.io.*;
public class yps1
{
    public static void main(String args[]) throws IOException
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        String name[]=new String[5];
        int i,j;
        System.out.println("Enter five names");
        for(i=0; i<5; i++)
        {
           
            name[i]=br.readLine();
           
        }
        for(j=0; j<5; j++)
        {
           
            System.out.println("NAME  "+ (j+1) + " :"+ name[j]);           
        }
       
    }
}

To accept 10 decimal values from the user on Terminal Window

import java.io.*;
public class yps
{
    public static void main(String args[]) throws IOException
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        double num[]=new double[10];
        int i;
        System.out.println("Enter 10 decimal values");
        for(i=0; i<10; i++)
        {
            num[i]=Double.parseDouble(br.readLine());
        }
        System.out.println("The 10 decimal values entered are:");
       for(i=0; i<10; i++)
        {
            System.out.println(num[i]);
        }
    }
}

To store first 10 prime numbers in an array

public class yps
{
    public static void main(String args[])
    {
       int p[]=new int[10];  //to store 10 prime numbers
       int num, i=0,j, count=0,c=0,a;
       
        for(num=2; num<100; num++)
        {
            for(j=1; j<=num; j++)
            {
                if(num%j==0)
                {
                    c++;
                }
            }
            if(c==2)
            {
                p[i]=num;
                i++;
                count++;
               
            }
            if(count==10)
            {
                break;
            }
            c=0;
        }
            System.out.println("First 10 Prime nums are: ");
         for(a=0;a<10;a++)
         {
             System.out.println(p[a]);
            
        }
       
    }
}

Use of arrays, functions, constructors in JAVA & BLUE J

import java.io.*;
class usecanteen
{
    public static void main(String args[])throws IOException
    {
       canteen ob=new canteen();  //object creation
       
        int itemnumber=2;
        int quantity=3;
        canteen ob1=new canteen(itemnumber, quantity);  //calling parameterised constructor
       
        ob.new_order();
        ob.display_bill();
        int amount=ob.return_bill();
        System.out.println("Kindly pay a total of Rs. "+amount);
    }
}






class canteen
{

        String items[]={"TV", "DVD Player", "Tape recorder", "LG mobile"};  //items array
        int price[]={20000, 5000, 3000, 11000}; //rate array
        int q; //quantity
        int bill;
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); 
        canteen()  //default constructor
        {
            q=0;
            bill=0;
        }
       
        canteen(int itemnum, int quant)  //parameterised constructor
        {
            bill=price[itemnum-1]*quant;
        }
       
        void new_order() throws IOException   //function to place a new order
        {
            System.out.println("************************MENU**********************");
            System.out.println("Enter 1 to order TV @20 000 Rs. ");
            System.out.println("Enter 2 to order DVD player @5000 Rs.");
            System.out.println("Enter 3 to order Tape recorder @3000 Rs.");
            System.out.println("Enter 4 to order LG mobile @11000 Rs.");
            System.out.println("****************************************************");
            int ch,i;
            String ans;
            int count=0;
           
            for(i=1;i<=4;i++)
            {
                count++;
                System.out.println("Please enter your choice of item(1-4)");
                ch=Integer.parseInt(br.readLine());
               
                if(ch>=1 && ch<=4)
                {
                    System.out.println("Please enter the number of " + items[ch-1] + " you want" );                   
                    q=Integer.parseInt(br.readLine());
                }
                else
                {
                    break;
                }
     
                bill=bill + price[ch-1]*q;
                if(count==4)
                {
                   break;
                }
                System.out.println("Do you want to place another order YES or NO?Please note you cannot order more than 4 items");
                ans=br.readLine();
                if(ans.equalsIgnoreCase("NO"))
                {
                    break;
                }
               
        
                           
            }
        }
        void display_bill()
        {
            System.out.println("ITEMISED BILL is of Rs."+bill);
        }
        int return_bill()
        {
            return bill;
        }
         
    }

Use of arrays, functions, constructors in JAVA & BLUE J

import java.io.*;
class usecanteen
{
    public static void main(String args[])throws IOException
    {
       canteen ob=new canteen();  //object creation
       
        int itemnumber=2;
        int quantity=3;
        canteen ob1=new canteen(itemnumber, quantity);  //calling parameterised constructor
       
        ob.new_order();
        ob.display_bill();
        int amount=ob.return_bill();
        System.out.println("Kindly pay a total of Rs. "+amount);
    }
}






class canteen
{

        String items[]={"TV", "DVD Player", "Tape recorder", "LG mobile"};  //items array
        int price[]={20000, 5000, 3000, 11000}; //rate array
        int q; //quantity
        int bill;
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); 
        canteen()  //default constructor
        {
            q=0;
            bill=0;
        }
       
        canteen(int itemnum, int quant)  //parameterised constructor
        {
            bill=price[itemnum-1]*quant;
        }
       
        void new_order() throws IOException   //function to place a new order
        {
            System.out.println("************************MENU**********************");
            System.out.println("Enter 1 to order TV @20 000 Rs. ");
            System.out.println("Enter 2 to order DVD player @5000 Rs.");
            System.out.println("Enter 3 to order Tape recorder @3000 Rs.");
            System.out.println("Enter 4 to order LG mobile @11000 Rs.");
            System.out.println("****************************************************");
            int ch,i;
            String ans;
            int count=0;
           
            for(i=1;i<=4;i++)
            {
                count++;
                System.out.println("Please enter your choice of item(1-4)");
                ch=Integer.parseInt(br.readLine());
               
                if(ch>=1 && ch<=4)
                {
                    System.out.println("Please enter the number of " + items[ch-1] + " you want" );                   
                    q=Integer.parseInt(br.readLine());
                }
                else
                {
                    break;
                }
     
                bill=bill + price[ch-1]*q;
                if(count==4)
                {
                   break;
                }
                System.out.println("Do you want to place another order YES or NO?Please note you cannot order more than 4 items");
                ans=br.readLine();
                if(ans.equalsIgnoreCase("NO"))
                {
                    break;
                }
               
        
                           
            }
        }
        void display_bill()
        {
            System.out.println("ITEMISED BILL is of Rs."+bill);
        }
        int return_bill()
        {
            return bill;
        }
         
    }

Place an order for books using functions & constructors - Java & Blue J program

import java.io.*;
class useorder
{
    public static void main(String args[]) throws IOException
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); 
        System.out.println("Welcome customer. Please enter the number of copies you want to order ! ");
        int copies=Integer.parseInt(br.readLine()); // input of number of copies ordered
       
        order ob=new order();
        order ob2=new order(3089, 9874, 3, 395);  //automatic call to parameterised constructor
       
        ob.fillarray(); //function call
        ob.disparr();   //function call
        ob.new_order(1009, 11, copies, 395); //parameterised function call
        ob.disp_details(); //function call
        ob.calc_bill();    //function call
       
        int numcopies=ob.return_copies(); //function call
        int pr=ob.return_price();         //function call
        int amount=ob.return_bill();      //function call
        System.out.println("The amount of bill to be paid for "+numcopies+ " copies at the price of "+pr+" per copy is equal to "+amount);
    }
}
       
       
  

class order
{
    int bookid, custid, numcopies, price, bill;
    int array[]=new int[5];
   
    order()
    {
        bookid=0;
        custid=0;
        numcopies=0;
        price=0;
        bill=0;
    }
   
    order(int b, int c, int cop, int p)
    {
        bookid=b;
        custid=c;
        numcopies=cop;
        price=p;
        bill=numcopies*price;
    }
   
   
    void fillarray()
    {
        array[0]=2;
        array[1]=3;
        array[2]=5;
        array[3]=7;
        array[4]=11;
      
    }
    void disparr()
    {
        int i;
        System.out.println("The first five prime numbers as elements of the array  are : ");
       
        for(i=0;i<5;i++)
        {
            System.out.println(array[i]);
        }
    }

    void new_order(int bi, int ci, int n, int p)
    {
        bookid=bi;
        custid=ci;
        numcopies=n;
        price=p;
    }
    void disp_details()
    {
        System.out.println("YOUR BOOKING ID IS = "+bookid);
        System.out.println("YOUR CUSTOMER ID IS = "+custid);
        System.out.println("The number of copies as per your order are = "+numcopies);
        System.out.println("The price per copy is = "+price);
    }
    void calc_bill()
    {
        bill=numcopies*price;
    }
    int return_bill()
    {
        return bill;
    }
    int return_copies()
    {
        return numcopies;
    }
    int return_price()
    {
        return price;
    }
}

disease detection using java & blue j

import java.io.*;
class usediagnose1
{
    public static void main(String args[]) throws IOException
    {
        String d1="Hypertension";
        String d2="Diabetes";
        String s1[]={"High BP", "Obesity", "Breathlessness", "Chest pain", "High pulse rate"}; //symptoms
        String s2[]={"Poor vision", "Belly fat", "Unusual thirst", "Fatigue", "Numbness"};
       
        diagnose1 ob=new diagnose1(d1,d2,s1,s2);
        diagnose1 ob2=new diagnose1();
        ob.new_diagnose(100, "Miss. Pooja");
        ob.ask();
        String rd=ob.return_disease();
        String nm=ob.return_name();
        System.out.println("Wish you speedy recovery "+nm+ " from the disease: " +rd);
       
       
    }
}
       


class diagnose1
{
    BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

    int patient_id;
    String patient_name;
    String disease1,disease2;
    String symp1[]=new String[5];
    String symp2[]=new String[5];
    String disease_detected;
    int i;
    diagnose1() //default constructor
    {
        patient_id=0;
        patient_name="";
    }
   
    diagnose1(String dis1, String dis2, String s1[], String s2[])  //parametrised constructor
    {
       
        disease1=dis1;
        disease2=dis2;
       
        for(i=0;i<5;i++)
        {
            symp1[i]=s1[i];
            symp2[i]=s2[i];
        }
       
    }
   
   
    void new_diagnose(int id, String n)
    {
        patient_id=id;
        patient_name=n;
    }
   
    void ask()throws IOException
    {
        System.out.println("Enter any two symptoms of your illness out of the list of symptoms");
        System.out.println(" High BP,Obesity,Breathlessness,Chest pain,High pulse rate,\n Poor vision, Belly fat,Unusual thirst,Fatigue,Numbness");
        String one=br.readLine();
        String two=br.readLine();
        int j,k;
        int c1=0, c2=0;   //counters for symptoms
        for(j=0;j<5;j++)
        {
            if(symp1[j].equalsIgnoreCase(one))
            {
                c1++;
            }
            if(symp1[j].equalsIgnoreCase(two))
            {
                c1++;
            }
        }
        for(k=0;k<5;k++)
        {
            if(symp2[k].equalsIgnoreCase(one))
            {
                c2++;
            }
            if(symp2[k].equalsIgnoreCase(two))
            {
                c2++;
            }
        }
       
        if(c1==2)   //disease detected if any 2 symptoms match
        {
            disease_detected=disease1;
        }
        else if(c2==2)
        {
            disease_detected=disease2;
        }
        else
        {
       
            disease_detected="NONE";
        }
       
        System.out.println("Detected disease : " +disease_detected);
        display_details();
    }
    private void display_details()
    {
             if(disease_detected==disease1)
             {
                 System.out.println("Remedies for Hypertension are: Consume less salt, Lose weight, Exercise daily, Do not take stress");
             }
             else if(disease_detected==disease2)
             {
                 System.out.println("Remedies for Diabetes are: Consume less sugar, Lose excess weight, Brisk walk daily");
             }
             else
            
             {
                 System.out.println("You are fit and fine !");
             }
    } 
    String return_disease()

    {

        return disease_detected;

    }

    String return_name()

    {

        return patient_name;

    }
}

Functions and Arrays for computation of result - JAVA & BLUE J PROGRAM

/*
 * Computer Science Project on result
Class : Result
Member Variables:
rollno, Name, ,avg  ,grade, array of marks in 5 subjects
Functions used :
Default constructor
Parameterized constructor
void new_student( int , String, int, int , int, int, int) // Function to accept rollno, name, eng, maths, science, art, geo marks from user.
void display_details(  )// Function to display the details
void calcavg() // to calculate the average marks and store in avg
void calcgrade()// to calculate the grade using the following formula
    avg         grade
    >90         A
    >70 &<= 90      B
    >60 &  <=70     C
    >40 & <=60      D
    <40         F  
double  return_average( ) // To return the average marks
String return_name()//To return the name
char return_grade( ) // To return the grade
Class Useresult
Write a main method which creates an object of the above class and call all the methods

 */




import java.io.*;
class useresult
{
    public static void main(String args[])throws IOException
    {
        result ob=new result();  //automatically calls default constructor
        int mks[]={89,99,90,88,78};
        result ob1=new result(007,"John",mks); //automatically calls parameterized constructor
       
        ob.new_student(1001, "Robin", 90, 98,95,90,96);
        ob.display_details();
        ob.calcavg();
        ob.calcgrade();
        System.out.println("\n**********FINAL RESULT**********");
        System.out.println("NAME   \t AVERAGE \t GRADE ");
        System.out.println(ob.return_name()+"\t "+ob.return_average()+"\t           "+ob.return_grade());

    }
}



class result
{
      int rollno;
      String name;
      double avg;
      char grade;
      int marks[]=new int[5];
      int i;
     
     
      result()
      {
          rollno=0;
          name="";
          marks[0]=0;
          marks[1]=0;
          marks[2]=0;
          marks[3]=0;
          marks[4]=0;
                }
     
      result(int rn, String n, int m[])
      {
          rollno=rn;
          name=n;
         
        for(i=0;i<5;i++)
        {
            marks[i]=m[i];
        }
      }
     
      void new_student(int r, String stu_name, int eng, int maths, int sci, int arts, int geo)
      {
          rollno=r;
          name=stu_name;
          marks[0]=eng;
          marks[1]=maths;
          marks[2]=sci;
          marks[3]=arts;
          marks[4]=geo;
         
      }
      void display_details()
      {
          System.out.println("ROLL NO\tNAME  \tENG\tMATHS\tSCI\tARTS\tGEO");
          System.out.println(+rollno+"\t"+name+"\t"+marks[0]+"\t "+marks[1]+"\t "+marks[2]+"\t "+marks[3]+"\t "+marks[4]);
        }
      void calcavg()
      {
          int sum=0;
          for(i=0;i<5;i++)
          {
              sum=sum+marks[i];
          }
          avg=sum/5;
      }
      void calcgrade()
      {
          if(avg>90)
          {
              grade='A';
          }
          else if(avg>70 && avg<=90)
          {
              grade='B';
          }
          else if(avg>60 && avg<=70)
          {
              grade='C';
          }
          else if(avg>40 && avg<=60)
          {
              grade='D';
          }
          else
          {
              grade='F';
          }
      }
      double return_average()
      {
          return avg;
      }
      String return_name()
      {
          return name;
      }
      char return_grade()
      {
          return grade;
      }
}

       
         
/*
 *
 *
OUTPUT:
ROLL NO    NAME      ENG    MATHS    SCI    ARTS    GEO
1001    Robin    90     98     95     90     96

**********FINAL RESULT**********
NAME        AVERAGE      GRADE
Robin     93.0               A

 */  
   

SELECTION SORT

import java.io.*;
class selectionsort
{
public static void main(String args[])throws IOException
{
    int x[]=new int[10];
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    System.out.println(" Enter 10 Integer values ");
    for(int i=0;i<10;i++)
    {
          x[i] = Integer.parseInt(br.readLine());      //input array of numbers
     }
     int h,p=0;
    for(int i=0;i<10;i++)
    {
        h=x[i]; 
        for(int j=i+1;j<10;j++)  //loop for comparison with next element
        {
            if(x[j]>h) //descending order
            {
                h=x[j];
                p=j;
            }
        }
        x[p]=x[i];  //swap
        x[i]=h;
    }
System.out.println(" After Sorting");
for(int i =0;i<=x.length-1;i++)
{
System.out.println(x[i]);
}
}
}

            This will enter a sentence and find the vowel

/**
* The class Vowel_Word inputs a sentence and prints words which begin with a vowel
* @author : www.javaforschool.com
* @Program Type : BlueJ Program - Java
*/
import java.io.*;
class Vowel_Word
    {
    public static void main()throws IOException
        {
            BufferedReader br=new BufferedReader (new InputStreamReader(System.in));
            System.out.print("Enter any sentence: ");
            String s=br.readLine();
            s = s+" ";
            int l=s.length();
            int pos=0;
            char ch1, ch2;
            String w;
            for(int i=0; i<l; i++)
            {
                ch1 = s.charAt(i);
                if(ch1 == ' ')
                {
                    w = s.substring(pos,i); // extracting words one by one
                    ch2 = w.charAt(0);
                    if(ch2=='A' || ch2=='E' || ch2=='I' || ch2=='O' || ch2=='U' ||
                    ch2=='a' || ch2=='e' || ch2=='i' || ch2=='o' || ch2=='u')
                    {
                        System.out.println(w);
                    }
                    pos = i+1;
                }
            }
        }
    }


//***************************************************************
//
// Title   : Time
// Author  : Divya H Jain
// Due date: 10-5-14
//
// This Time object provides a number of facilities to keep track
// of time.  When called as a stand alone application, it prompts
// the user for two times and subtracts them.  When used with
// other classes, it provides methods to print time, subtract
// times, create times, and return the number of seconds
// represented by a time.
//
//***************************************************************

import vista.*;

public class Time {
    int hours;
    int minutes;
    int seconds;

    // Time constructor:  Simply assign the state of this object values.
    public Time(int h, int m, int s) {
        hours = h;
        minutes = m;
        seconds = s;
    }

    // Time Constructor: When a Time object is created with no parameters, the
    //    user of the program is prompted for the appropriate info.
    public Time() {
        VInput in = new VInput();

        System.out.print  ("    hours:   ");  // get the hours
        System.out.flush  ();
        hours = in.readInt();

        System.out.print  ("    minutes: ");  // get the minutes
        System.out.flush  ();
        minutes = in.readInt();

        System.out.print  ("    seconds: ");  // get the seconds
        System.out.flush  ();
        seconds = in.readInt();
    }

    // Subtract method:  Subtract the time X from the time "this".  This method
    //    needs to be careful to take into account borrowing of time.
    public Time subtract(Time x) {

        //Do the initial subtraction and create the return Time.
        Time ret = new Time(hours-x.hours, minutes-x.minutes, seconds-x.seconds);

        if (ret.seconds < 0) {   // If we need to borrow for the seconds, do it now
            ret.seconds += 60;   //    60 seconds in a minute
            ret.minutes--;       //    1  minute for 60 seconds
        }


        if (ret.minutes < 0) {   // If we need to borrow for the minutes, do it now.
            ret.minutes += 60;   //    60 seconds to an hour
            ret.hours--;
        }

        return (ret);            // Return the result.
    }

    // println Method: This method prints out the contents of a Time object in a neatly
    //    arranged mannor.  At the end, it finishes with a println();
    public void println() {
        boolean comma = false;

        if (hours != 0) {               // If there are hours....
            System.out.print(hours);    //   print them!
            System.out.print(" hour");
            if (hours != 1)             // If there not only one hour,
              System.out.print("s");    //   print an "s" to make it plural.
            comma = true;               // If there are any more components, mark that we
        }                               //   need to draw a comma.


        if (minutes != 0) {             // If there are minutes...
            if (comma)                  // If there were hours,
              System.out.print(", ");   //   then print a comma to seperate them.
            System.out.print(minutes);
            System.out.print(" minute");
            if (minutes != 1)           // Make it plural if neccesary.
              System.out.print("s");
            comma = true;
        }

        if (seconds != 0) {             // If there are seconds...
            if (comma)                  // If there were either minutes or hours,
              System.out.print(", ");   //   print the seperator.

            System.out.print(seconds);
            System.out.print(" second");
            if (seconds != 1)           // Make it plural.
              System.out.print("s");
        }

        System.out.println();
    }

    // seconds Method: The seconds method returns the number of seconds that the objects
    //    state contains.  This is obtained by taking the seconds + the minutes*60 (60
    //    seconds in a minute) + the hours*3600 (3600 seconds in each hour).
    public int seconds() {
        return(seconds + minutes*60 + hours*60*60);
    }


    // Main Method: This is where the whole thing starts...
    public static void main (String args[]) {

        // Get the start time.
        System.out.println("Please enter the start time:");
        Time StartTime = new Time();
        System.out.println();

        // Get the ending time.
        System.out.println("Please enter the ending time: ");
        Time EndTime   = new Time();

        // Compute the amount of elapsed time.
        Time elapsed = EndTime.subtract(StartTime);
        System.out.println();
        System.out.print("The elapsed time is ");
        elapsed.println();   // Print the amount of elapsed time.


        // Print the amount of elapsed seconds.
        System.out.print("Total elapsed seconds: ");
        System.out.println(elapsed.seconds());

        // Wait for <ENTER> to be pressed.
        VInput in = new VInput();
        in.waitForCR();
    }
}