/**************************************** * Name: Rahul N. * Date: Oct 16th, 2023 * Description: To write a program that makes appointment * and to see if the two appointments overlap each other ****************************************/ import java.util.Scanner; public class Appointment { private int day; private int month; private String description; public Appointment(int day, int month, String description) { this.day = day; this.month = month; this.description = description; } public boolean hasTheSameDate(Appointment other) { return this.day == other.day && this.month == other.month; } public String toString() { return month + "/ " + day + ": " + description; } // Main Method public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.println("Enter the details for the first appointment"); System.out.print("Day: "); int day1 = scanner.nextInt(); System.out.print("Month: "); int month1 = scanner.nextInt(); scanner.nextLine(); // consume the newline character System.out.print("Description: "); String description1 = scanner.nextLine(); Appointment appointment1 = new Appointment(day1, month1, description1); System.out.println("Enter the details for the second appointment"); System.out.print("Day: "); int day2 = scanner.nextInt(); System.out.print("Month: "); int month2 = scanner.nextInt(); scanner.nextLine(); // consume the newline character System.out.print("Description: "); String description2 = scanner.nextLine(); Appointment appointment2 = new Appointment(day2, month2, description2); System.out.println("Appointment 1: " + appointment1); System.out.println("Appointment 2: " + appointment2); if (appointment1.hasTheSameDate(appointment2)) { System.out.println("The appointments have the same date."); } else { System.out.println("The appointments do not have the same date."); } } }   My results has been: Enter the details for the first appointment Day: 23 Month: 7 Description: hair Enter the details for the second appointment Day: 23 Month: 7 Description: car Appointment 1: 7/  23: hair Appointment 2: 7/  23: car The appointments have the same date. Process finished with exit code 0   My question: How can I change my code so that it converts 7/ 23 to 7/23?

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
/****************************************
* Name: Rahul N.
* Date: Oct 16th, 2023
* Description: To write a program that makes appointment
* and to see if the two appointments overlap each other
****************************************/

import java.util.Scanner;

public class Appointment {
private int day;
private int month;
private String description;

public Appointment(int day, int month, String description) {
this.day = day;
this.month = month;
this.description = description;
}

public boolean hasTheSameDate(Appointment other) {
return this.day == other.day && this.month == other.month;
}

public String toString() {
return month + "/ " + day + ": " + description;
}
// Main Method
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

System.out.println("Enter the details for the first appointment");
System.out.print("Day: ");
int day1 = scanner.nextInt();
System.out.print("Month: ");
int month1 = scanner.nextInt();
scanner.nextLine(); // consume the newline character
System.out.print("Description: ");
String description1 = scanner.nextLine();

Appointment appointment1 = new Appointment(day1, month1, description1);

System.out.println("Enter the details for the second appointment");
System.out.print("Day: ");
int day2 = scanner.nextInt();
System.out.print("Month: ");
int month2 = scanner.nextInt();
scanner.nextLine(); // consume the newline character
System.out.print("Description: ");
String description2 = scanner.nextLine();

Appointment appointment2 = new Appointment(day2, month2, description2);

System.out.println("Appointment 1: " + appointment1);
System.out.println("Appointment 2: " + appointment2);

if (appointment1.hasTheSameDate(appointment2)) {
System.out.println("The appointments have the same date.");
} else {
System.out.println("The appointments do not have the same date.");
}
}
}
 
My results has been:

Enter the details for the first appointment
Day: 23
Month: 7
Description: hair
Enter the details for the second appointment
Day: 23
Month: 7
Description: car
Appointment 1: 7/  23: hair
Appointment 2: 7/  23: car
The appointments have the same date.

Process finished with exit code 0

 

My question: How can I change my code so that it converts 7/ 23 to 7/23?

 

Expert Solution
Step 1: Introduction on the given question

In the provided code, the objective is to create a Java program that allows users to make appointments and check whether two appointments overlap in terms of date. The program includes an Appointment class with attributes for day, month, and description. It also provides functionality to compare and determine whether two appointments share the same date. The user interacts with the program by inputting the details of two appointments, including the day, month, and a description. The program then evaluates whether these appointments fall on the same date and provides an informative response. An important modification was made to ensure that the date is displayed without an extra space, resulting in a cleaner and more readable output. This code serves as a practical example for managing appointments and comparing dates within a Java program.

trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 5 steps with 2 images

Blurred answer
Knowledge Booster
Declaring and Defining the Function
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education