Question

Instructions: Refer to the Timel class provided in Figure 8.1 in your Deitel book to complete the exercise. Make sure that yo
// Fig. 8.1: Time1.java 7 Timel class declaration maintains the time in 24-hour format. public class Time1 private int hour;
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here I am providing the answer for the above question:

Code:

Point.java

public class Point
{
   private int x,y;
   //constructors
   public Point()
   {
       this.x=0;
       this.y=0;
   }
   public Point(int x,int y)
   {
       this.x=x;
       this.y=y;
   }
   //getters and setters
   public int getX() {
       return x;
   }
   public void setX(int x) {
       this.x = x;
   }
   public int getY() {
       return y;
   }
   public void setY(int y)
   {
       this.y = y;
   }
   //tostring method
   @Override
   public String toString()
   {
       return "The X coordinate = "+ x + "\nThe Y coordinate = " + y + "\n";
   }
}

//please replace name,lab number,date with you name, lab number , date

PointTest.java


public class PointTest
{
   public static void main(String args[])
   {
       //printing name,lab number,date
       System.out.println("Name : "+"Suji");
       System.out.println("Lab Number : "+10);
       System.out.println("Date : "+"21-01-2020");
      
       Point point1=new Point(); //creating point1 with no arguments
       Point point2=new Point(11,24); //creating point2 with arguments
      
       System.out.println(point1.toString()); //calling to string methods for two objects
       System.out.println(point2.toString());
      
       point1.setX(35); //changing the x value of point1 using setX() method.
   }

}

Screenshot:

package files; public class Point private int x,y; //constructors public Point () this.x=0; this.y=0; public Point (int x, inpublic class Point Test public static void main(String args[]) //printing name, lab number, date System.out.println(Name :

Output:

Name : Suji Lab Number : 10 Date : 21-01-2020 The X coordinate = 0 The Y coordinate = 0 The X coordinate = 11 The Y coordinat

Hoping that the above answers will help you...Thank you...

Add a comment
Know the answer?
Add Answer to:
Instructions: Refer to the Timel class provided in Figure 8.1 in your Deitel book to complete...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • JAVA. Create an application that uses a "PriorityQueue" to perform the following Uses the constructor that rece...

    JAVA. Create an application that uses a "PriorityQueue" to perform the following Uses the constructor that receives a "Comparator" object as an argument Stores 5 "Time1" objects using the "Time1" class shown in Fig. 8.1 on page 331. The class must be modified to implement the "Comparator" interface Displays the "Universal Time" in priority order Note: To determine the ordering when implementing the "Comparator" interface, convert the time into seconds (i.e., hours * 3600 + minutes * 60 + seconds),...

  • Lesson is about Input validation, throwing exceptions, overriding toString Here is what I am supposed to...

    Lesson is about Input validation, throwing exceptions, overriding toString Here is what I am supposed to do in the JAVA Language: Model your code from the Time Class Case Study in Chapter 8 of Java How to Program, Late Objects (11th Edition) by Dietel (except the displayTime method and the toUniversalString method). Use a default constructor. The set method will validate that the hourly employee’s rate of pay is not less than $15.00/hour and not greater than $30.00 and validate...

  • You are to create a class Appointment.java that will have the following: 5 Instance variables: private...

    You are to create a class Appointment.java that will have the following: 5 Instance variables: private String month private int day private int year private int hour private int minute 1 default constructor public Appointment() 1 non-default constructor that accepts arguments for all instance variables, your constructor must call the setter methods below to set the values of the instance variables public Appointment(String monthPassed, int dayPassed, int yearPassed, int hourPassed, int minutePassed) 5 setter methods (one for each instance variable)...

  • Java Programming The program template represents a complete working Java program with one or more key...

    Java Programming The program template represents a complete working Java program with one or more key lines of code replaced with comments. Read the problem description and examine the output, then study the template code. Using the problem-solving tips as a guide, replace the /* */ comments with Java code. Compile and execute the program. Compare your output with the sample output provided. Modify class Time2 to include a tick method that increments the time stored in a Time2 object...

  • Hello. I need help writing the following Java Program. Thank you Develop a class encapsulating the...

    Hello. I need help writing the following Java Program. Thank you Develop a class encapsulating the concept of a college course, assuming that a course has following attributers: code (for instance COSC1337), a description, and a number of credits (for instance 3). Include a constructor, the accessors, mutators and methods ‘toString’, ‘equals’, and ‘finalize’. Write a client class to test the behavior of the class and its methods. The outline of the class is given as follows: public class Course...

  • In this practical task, you need to implement a class called MyTime, which models a time...

    In this practical task, you need to implement a class called MyTime, which models a time instance. The class must contain three private instance variables: hour, with the domain of values between 0 to 23. minute, with the domain of values between 0 to 59. second, with the domain of values between 0 to 59. For the three variables you are required to perform input validation. The class must provide the following public methods to a user: MyTime() Constructor. Initializes...

  • Please help with Java programming! This code is to implement a Clock class. Use my beginning...

    Please help with Java programming! This code is to implement a Clock class. Use my beginning code below to test your implementation. public class Clock { // Declare your fields here /** * The constructor builds a Clock object and sets time to 00:00 * and the alarm to 00:00, also. * */ public Clock() { setHr(0); setMin(0); setAlarmHr(0); setAlarmMin(0); } /** * setHr() will validate and set the value of the hr field * for the clock. * *...

  • Task 3: Main Program Create a main program class that: Creates three or more Nurse instances...

    Task 3: Main Program Create a main program class that: Creates three or more Nurse instances assigned to different shifts. Creates three or more Doctor instances. Creates three or more Patient instances with pre-determined names and manually assigned physicians chosen from the pool of Doctor instances previously created. Generates another 20 Patient instances using randomly generated names and randomly assigns them physicians chosen from the pool of Doctor instances previously created. Prints the toString() values for all employees. Prints the...

  • In a project named 'DogApplication', create a class called 'Dog' 1. declare two instance variables in...

    In a project named 'DogApplication', create a class called 'Dog' 1. declare two instance variables in 'Dog' : name (String type) age (int type) 2. declare the constructor for the 'Dog' class that takes two input parameters and uses these input parameters to initialize the instance variables 3. create another class called 'Driver' and inside the main method, declare two variables of type 'Dog' and call them 'myDog' and 'yourDog', then assign two variables to two instance of 'Dog' with...

  • Java Time Class Class declarations are one of the ways of defining new types in Java....

    Java Time Class Class declarations are one of the ways of defining new types in Java. we will create two classes that both represent time values for a 24 hours period. The valid operations are as follows. int getHours(): returns the number of hours int getMinutes(): returns the number of minutes int getSeconds(): returns the number of seconds String toString(): returns a String representation boolean equals(Time other): returns true if and only if other designates an object that has the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT