Extra Exercises on Objects - | Extra Exercises on Objects and Array of Objects | Question#1 Write a Java a class called Time The Time class has three

Extra Exercises on Objects - | Extra Exercises on Objects...

This preview shows page 1 - 3 out of 6 pages.

| Extra Exercises on Objects and Array of Objects | Question#1: Write a Java a class called Time. The Time class has three private data members: hours, minutes, and seconds (each is int). This class provides a constructor that initialize each data and verify the values of hours to be integer more than or equal 0 and less than 24 (otherwise it will set the value to be zero). Minutes and seconds to be more than or equal 0 and less than 60 (otherwise it will set the value to be zero). This class contains public methods as follow: Get total time in sec (return int). Get total time in minutes (return double). Create a class named TestTime with a main method to test your Time class. Your program should: Create three Time objects, and set their values. Display the total time in seconds of the first and second objects, and the total time in minutes for the third object. s){
Image of page 1
import java.util.*; public class TestTime{ public static void main(String args[]){ Scanner read= new Scanner(System.in); Time t1,t2,t3; int temp1,temp2,temp3; System.out.println( "Enter first time" ); System.out.println( "Enter hours" ); temp1=read.nextInt(); System.out.println( "Enter Minutes" ); temp2=read.nextInt(); System.out.println( "Enter Seconds" );temp3=read.nextInt(); t1= new Time(temp1,temp2,temp3); ////////////////// System.out.println( "Enter 2nd time" ); System.out.println(
Image of page 2
Image of page 3

You've reached the end of your free preview.

Want to read all 6 pages?

  • Fall '10
  • ZuhairShentuf
  • Java Programming, Final Prep, Subroutine, System.out.println, public Circle

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture