Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA PROGRAMMING The following code is give me a user error. I have also attached the EXACT output that needs to be produced (which changes

JAVA PROGRAMMING

The following code is give me a user error. I have also attached the EXACT output that needs to be produced (which changes only if I select a different initial date or final date), as well as the error message received. Note that there are two classes, Date and Client, as per the assignment requirements. Please fix my code to where it will run properly. Thank you.

Output

Enter day of first date:19

Enter month of first date:1

Enter year of first date:2197

Enter day of second date:16

Enter month of second date:2

Enter year of second date:2397

There are 73075 days between 19/1/2197 and 16/2/2397

Code (Class)

public class Date { int day; int month; int year; LocalDate date; /* Constructor to construct a Date object*/  public Date(int day, int month, int year){ //Creates a new Date object  this.day = day; this.month = month; this.year = year; // Contruct LocalDate object for this object  LocalDate date = LocalDate.of(year,month,day); System.out.println(date); this.date = date; } /* Return the day of the Date object*/  public int getDay(){ return this.day; } /* Return the month of the Date object*/  public int getMonth(){ return this.month; } /* Return the year of the Date object*/  public int getYear(){ return this.year; } /* Add the days to current Date object*/  public void addDays(int days){ this.date.plusDays(days); } /* Returns days between current Date object and other date*/  public int daysTo(LocalDate other){ long daysB = DAYS.between(this.date, other); System.out.println(""); int daysBetween = (int)daysB; return daysBetween; } /* Checks if the Date object is leap year or not*/  public boolean isLeapYear(){ LocalDate date = LocalDate.of(this.year, this.month, this.day); return date.isLeapYear(); } /* Convert Date object to String */  public String toString(){ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy"); String formattedString = this.date.format(formatter); return formattedString ; } } 

Code (Client Class)

import.java.util.Scanner; public class Client { public static void main(String[] args) { Scanner s = new Scanner(System.in); // Take input data for dates from user  System.out.println("Enter day of first date:"); int day1 = s.nextInt(); System.out.println("Enter Month of first date:"); int month1 = s.nextInt(); System.out.println("Enter Year of first date:"); int year1 = s.nextInt(); System.out.println("Enter day of second date:"); int day2 = s.nextInt(); System.out.println("Enter Month of second date:"); int month2 = s.nextInt(); System.out.println("Enter year of second date:"); int year2 = s.nextInt(); // Create Date objects with input values  Date date1 = new Date(day1,month1,year1); Date date2 = new Date(day2,month2,year2); // Calculate Days between the two dates  int days = date1.daysTo(date2.date); System.out.println("There are "+days+" days between "+date1.toString()+" and "+date1.toString()); } } 

image text in transcribed

File Edit View Navigate Cce Analyz Refator Build R ols s Wina Help DaysBetweeClent Frcject Clientjve inportjava.utii.8cane out Client Cate // 2k- inPut dac. fr datsz en was r >l Extemal Libranes 8vstea..out.printin!"Enter Month of til t date :"1; iall aucuLlal-2.usx.11t(); Syatw.out.printla("Eates Yuar of fiat datas:"y econd date: "); yster. out, printin{"Enter int day2-.cextint dny ot int aant.h2-2.nux 1nt[]; 1nt yer2-5.nex tnt(l ; // Casate Dute jw!ch -iiput vuauw Date datl w(dayl,nonthl.ra 24 Mcszages Buld . Information: java: Errors occurred while compiling module 'DaysBetween. fation: jaac 9.0.1 was used to pile java scurces >> e information: /16/2018 1002 AM Compilation completed with 1 emor ard 0wamings in 973ms Error:C1,7 java: ": identifier:-expected | 0: Messages 6: TO DO Identther expected. Unexpected token Torminal Event Lag 10113 AM O Type here to search 3F16y2018

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Big Data, Mining, And Analytics Components Of Strategic Decision Making

Authors: Stephan Kudyba

1st Edition

1466568704, 9781466568709

More Books

Students also viewed these Databases questions

Question

3. How would you address the problems that make up the situation?

Answered: 1 week ago

Question

2. What recommendations will you make to the city council?

Answered: 1 week ago