I need to format the date and time to read out month first then the day then the year but it is not working, what is the correct format? Also my hours are not updating when it runs, why? import java.time.format.DateTimeFormatter; import java.time.LocalDate; import java.util.Scanner; public class Volunteer { private String firstName; private String lastName; private static int startDate; private double volunteerHours; public static final String DEFAULT_FIRST_NAME = "first name not assigned"; public static final String DEFAULT_LAST_NAME = "last name not assigned"; public static final LocalDate DEFAULT_START_DATE = LocalDate.now(); public static final double DEFAULT_HOURS = 0; public Volunteer(String firstName, String lastName, int startDate2, double volunteerHours) { // TODO Auto-generated constructor stub } public String getFirstName() { return firstName; } public void setFirstName(String firstName) { if (firstName != null && firstName.length() >0 ) this.firstName = firstName; }   public String getLastName() { return lastName; }   public void setLastname(String lastName) { if (lastName != null && lastName.length() >0 ) this.lastName = lastName; }   public int getStartDate() { return startDate; }   public void setStartDate(int StartDate) { if (startDate != 0) Volunteer.startDate = StartDate; } public void setStartDate(int newYear, int newMonth, int newDay) { } public double getVolunteerHours(double hours) { return volunteerHours; }   public void setVolunteerHours(double volunteerHours) { this.volunteerHours = volunteerHours; } public void updateVolunteerHours (double hours) { // this.volunteerHours=hours; this.volunteerHours = this.volunteerHours+hours; } public static String getDefaultFirstName() { return DEFAULT_FIRST_NAME; }   public static String getDefaultLastName() { return DEFAULT_LAST_NAME; }   public static LocalDate getDefaultStartDate() { return DEFAULT_START_DATE; }   public static double getDefaultHours() { return DEFAULT_HOURS; } @Override public String toString() { return "Volunteers [firstName=" + firstName + ", lastName=" + lastName + ", startDate=" + startDate + ", volunteerHours=" + volunteerHours + "]"; } public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); System.out.print("Enter First Name: "); String firstName = keyboard.nextLine(); System.out.print("Enter Last Name: "); String lastName = keyboard.nextLine(); System.out.print("Enter the start date: (mm/dd/yyy)"); String userInput = keyboard.nextLine(); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy/d/M"); LocalDate date = LocalDate.parse(userInput, formatter); System.out.println(date); System.out.print("Enter Hours: ");{ double volunteerHours= keyboard.nextDouble(); Volunteer vol = new Volunteer(firstName,lastName,startDate,volunteerHours); System.out.println(vol); keyboard.close(); } } }

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
100%

I need to format the date and time to read out month first then the day then the year but it is not working, what is the correct format? Also my hours are not updating when it runs, why?

import java.time.format.DateTimeFormatter;

import java.time.LocalDate;

import java.util.Scanner;

public class Volunteer {

private String firstName;
private String lastName;
private static int startDate;
private double volunteerHours;

public static final String DEFAULT_FIRST_NAME = "first name not assigned";
public static final String DEFAULT_LAST_NAME = "last name not assigned";
public static final LocalDate DEFAULT_START_DATE = LocalDate.now();
public static final double DEFAULT_HOURS = 0;



public Volunteer(String firstName, String lastName, int startDate2, double volunteerHours) {
// TODO Auto-generated constructor stub
}

public String getFirstName() {
return firstName;
}


public void setFirstName(String firstName) {
if (firstName != null && firstName.length() >0 )
this.firstName = firstName;
}

 

public String getLastName() {
return lastName;
}

 

public void setLastname(String lastName) {
if (lastName != null && lastName.length() >0 )
this.lastName = lastName;
}

 

public int getStartDate() {
return startDate;
}

 

public void setStartDate(int StartDate) {
if (startDate != 0)
Volunteer.startDate = StartDate;
}

public void setStartDate(int newYear, int newMonth, int newDay) {

}


public double getVolunteerHours(double hours) {
return volunteerHours;
}

 

public void setVolunteerHours(double volunteerHours) {
this.volunteerHours = volunteerHours;
}

public void updateVolunteerHours (double hours) {
// this.volunteerHours=hours;
this.volunteerHours = this.volunteerHours+hours;
}

public static String getDefaultFirstName() {
return DEFAULT_FIRST_NAME;
}

 

public static String getDefaultLastName() {
return DEFAULT_LAST_NAME;
}

 

public static LocalDate getDefaultStartDate() {
return DEFAULT_START_DATE;
}

 

public static double getDefaultHours() {
return DEFAULT_HOURS;
}

@Override
public String toString() {
return "Volunteers [firstName=" + firstName + ", lastName=" + lastName + ", startDate=" + startDate
+ ", volunteerHours=" + volunteerHours + "]";
}

public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter First Name: ");
String firstName = keyboard.nextLine();
System.out.print("Enter Last Name: ");
String lastName = keyboard.nextLine();
System.out.print("Enter the start date: (mm/dd/yyy)");
String userInput = keyboard.nextLine();
DateTimeFormatter formatter =
DateTimeFormatter.ofPattern("yyyy/d/M");
LocalDate date = LocalDate.parse(userInput, formatter);
System.out.println(date);


System.out.print("Enter Hours: ");{
double volunteerHours= keyboard.nextDouble();
Volunteer vol = new Volunteer(firstName,lastName,startDate,volunteerHours);
System.out.println(vol);
keyboard.close();

}

}
}

Expert Solution
Step 1

explanation:

you can use the simple date format like this:

SimpleDateFormat sdf = new SimpleDateFormat("mm/dd/yyyy");
Date date = sdf.parse(userInput);
sdf = new SimpleDateFormat("MM/dd/yyyy");
System.out.println(sdf.format(date));

below is modified code with output:
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Random Class and its operations
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
  • SEE MORE 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