Programming Homework Help

Public Static Void Java Code

 

this is template:

import java.time.LocalDate;
import java.util.List;
import java.util.LinkedList;
import java.util.Scanner;

public class ManageVideoGames {

public static void main(String[] args) {

//2.2.2 Application Class - ManageVideoGames

//create an empty list of VideoGames

//1. display menu

//2. get user choice

//3. take action based on user choice

//4. loop through steps 1, 2, 3 above until user quits

}

//define other methods for modularization, samples are listed below.

//method to display menu
public static void displayMenu() {

}

//method to get user choice
public static int getUserChoice() {
//add your code

return -1;
}


//method to get user input, create and return a video game
public static VideoGame getNewGame() {
//add your code here

return null;
}

//method to add a video game without maintaining sorted order
//add your own code

//method to remove a game based on user input
//add your own code

//method to find the game with latest release date
//add your own code

//OPTIONAL BONUS:
// method to add a video game in alphabetical order of game titles
//add your own code

} //////
/newer Java API for handling date values import java.time.LocalDate; import java.time.format.DateTimeFormatter; public class VideoGame implements Comparable<VideoGame> { //2.2.1 Entity Class - VideoGame private static final int DEFAULT_NUMBER_OF_PLATFORMS = 5; //data fields private String title; private String developer; //lead developer private String platforms[]; private LocalDate releaseDate; @Override public String toString() { //add your code //return a string including all infor. about a game // date value included in format: 9/15/2020 for Sep. 15, 2020 return "NOT Done yet"; } @Override public boolean equals(Object otherObject) { //add your code // comparing two VideoGame objects based only on title return false; } //******The following code don't need to be changed.*****// //You don't need to change this method. //This method is used in addVideoGameIn. @Override public int compareTo(VideoGame other) { return this.title.compareTo(other.title); } //no-argument constructor public VideoGame() { platforms = new String[DEFAULT_NUMBER_OF_PLATFORMS]; } //constructor taking in values for all data fields public VideoGame(String title, String developer, String[] platforms, LocalDate releaseDate) { this.title = title; this.developer = developer; this.platforms = platforms; this.releaseDate = releaseDate; } //getters return the values public String getTitle() { return title; } public String getDeveloper() { return developer; } public String[] getPlatforms() { return platforms; } public LocalDate getReleaseDate() { return releaseDate; } //setters public void setTitle(String title) { this.title = title; } public void setDeveloper(String developer) { this.developer = developer; } public void setPlatforms(String[] platforms) { this.platforms = platforms; } public void setReleaseDate(LocalDate releaseDate) { this.releaseDate = releaseDate; } } ////// //* For Assign 2, you only need the 2 classes below if your operating system date and time is in USA format. import java.time.LocalDate; import java.time.format.DateTimeFormatter; /** * @author Cindy Li */ public class TestDate { public static void main(String[] args) { //1. create LocalDate objects //Use method: // static LocalDate of(int year, int month, int dayOfMonth) //Get a LocalDate object based on the given year, month, and dayOfMonth. //Example 1: //For the date in US format: 9/30/2018 (Sep. 30, 2018) // call static method of(int year, int month, int dayOfMonth), where the parameters mean: // year in the local date value // month in the local date value, 1 for January, 2 for February, etc. // dayOfMonth: the day of the month in the local date value. LocalDate date1 = LocalDate.of(2021, 8, 13); //August 13, 2021 LocalDate date2 = LocalDate.of(2018, 9, 30); //September 30, 2018 System.out.println("d1: " + date1); System.out.println("d2: " + date2); //2. Compare two Date values //2.1 use different methods: isBefore(...), isAfter(...), equals(...) if (date1.isAfter(date2)) { System.out.println("n" + date1 + " is after " + date2); } if (date1.equals(date2)) { System.out.println(date1 + " is on same date as " + date2); } if (date1.isBefore(date2)) { System.out.println(date1 + " is before " + date2); } //2.2 use one method: compareTo(...) if (date1.compareTo(date2) > 0) { System.out.println(date1 + " is after " + date2); } else if (date1.compareTo(date2) == 0) { System.out.println(date1 + " is on same date as " + date2); } else { System.out.println(date1 + " is before " + date2); } //3. Format local date values //**********You will need these 3 things in Assign 2.************// //make a date from year, month, day LocalDate localDate = LocalDate.of(2009, 9, 10); //Sep. 10, 2009 System.out.println(localDate); //format a date //get a DateTimeFormatter object using the format pattern: like 9/10/2009 DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("M/d/yyyy"); // 9/10/2009 //use the DateTimeFormatter to format the localDate value in the pattern: "M/d/yyyy". System.out.println(dateFormatter.format(localDate)); //date value comparison //make a date from year, month, day LocalDate today = LocalDate.now(); //current date LocalDate christmas = LocalDate.of(2021, 12, 24); // 12/24/2021 System.out.println("today: " + today); System.out.println("christimas: " + christmas); System.out.println("has christmas passed this year? " + today.isAfter(christmas)); } } /*-----Program Output d1: 2021-08-13 d2: 2018-09-30 2021-08-13 is after 2018-09-30 2021-08-13 is after 2018-09-30 2009-09-10 9/10/2009 today: 2021-09-03 christimas: 2021-12-24 has christmas passed this year? false */ /// //File: TestDateOld.java
//* If you have not handled dates before, please use the code in TestDate.java
//* in package: assign2_template.
//* Use the code here only if you have used dates in Java 7 API before.

//* You don’t need to change these two files.
//* Just use them as a reference for handling date values.

//* This file is for demo how to use the old Java 7 API.
//* for handling dates related to Assign 2.

//* Simple examples of using Java classes: java.util.Date, java.text.DateFormat, and java.util.Locale.
//* For Assign 2, you only need java.util.Date and java.text.DateFormat if your operating system date and time is USA format.
//* Note about using the constructor of java.util.Date class.
// In all methods of class Date that accept or return year, month, date (day in a month), hours, minutes, and seconds values, the following representations are used:
// A year y is represented by the integer y - 1900.
// A month is represented by an integer from 0 to 11; 0 is January, 1 is February, and so forth; thus 11 is December.
// A date (day in a month) is represented by an integer from 1 to 31 in the usual manner.
//* Note about Date format styles and Locales
// Sample Date format styles in 2 sample locales
// Style U.S. Locale French Locale
// DEFAULT Jun 30, 2009 30 june 2009
// SHORT 6/30/09 30/06/09
// MEDIUM Jun 30, 2009 30 june 2009
// LONG June 30, 2009 30 june 2009
// FULL Tuesday, June 30, 2009 mardi 30 june 2009



import java.util.Date;
import java.text.DateFormat;
import java.util.Locale;

/**
*
* @author cindy
*/
public class TestDateOld {

public static void main(String[] args) {
//1. Create Date objects

Date date1 = new Date(); //the Date value for today when the program is executed.
//For the date in US format: 9/30/2018 (Sep. 30, 2018)
// call constructor: Date(int year, int month, int date), where the parameters mean:
// year: the value of (yearInTheDate - 1900)
// month: the value of (monthInTheDate - 1)
// date: the dayOfMonth in the Date value.
Date date2 = new Date(2018 - 1900, 9 - 1, 30);
//call toString() in Date class to get and print the date and time values.
System.out.println("date1: n" + date1);
System.out.println("date2: n" + date2);

//2. Compare two Date values

//2.1 use different methods: before(...), after(...), equals(...)
if (date1.after(date2)) {
System.out.println("n" + date1 + " is after " + date2);
}

if (date1.equals(date2)) {
System.out.println(date1 + " is on same date as " + date2);
}

if (date1.before(date2)) {
System.out.println(date1 + " is before " + date2);
}

//2.2 use one method: compareTo(...)
if (date1.compareTo(date2) > 0) {
System.out.println(date1 + " is after " + date2);
}
else if (date1.compareTo(date2) == 0) {
System.out.println(date1 + " is on same date as " + date2);
}
else {
System.out.println(date1 + " is before " + date2);
}

//3. Format Date values

//3.1 Format Date values in US format

Date todayIn = new Date(); //Date value before the formatting
String todayOut; //Date value as string after being formatted
DateFormat myDateFormatter; //a formatter for formatting Date values
//get a Date Formatter that uses DEFAULT style of Date format
// and the default FORMAT locale (i.e. the locale for formatting date, time values)
//The DEFAULT style for Date values in US format: Jun 30, 2018 for June 30, 2018.
myDateFormatter = DateFormat.getDateInstance();
//call format(...) method in DateFormat class to format the Date value
// in the style and locale associated with the DateFormat object: myDateFormatter.
todayOut = myDateFormatter.format(todayIn);
System.out.println("ntoday in DEFAULT style in my local system: n" + todayOut);

//To display the Date value in US as: 6/30/2018 for June 30, 2018
//This is what is required in Lab 4 - Assign 2
myDateFormatter = DateFormat.getDateInstance(DateFormat.SHORT);
todayOut = myDateFormatter.format(todayIn);
System.out.println("ntoday in SHORT style in my local system: n" + todayOut);

//3.2 Format Date values in the format associated with a given local tyle

Locale currentLocale = Locale.FRANCE; //set current Locale to FRANCE style
//get a Date formatter that uses the DEFAULT style for Date value and the given Locale for formatting date and time values.
DateFormat dateFormatter = DateFormat.getDateInstance(DateFormat.DEFAULT, currentLocale);
todayOut = dateFormatter.format(todayIn);
System.out.println("ntoday in DEFAULT style in the " + currentLocale.toString() + " system: n" + todayOut);


}
}

/*-----Sample Program Output
date1:
Thu Feb 04 01:34:56 EST 2021
date2:
Sun Sep 30 00:00:00 EDT 2018

Thu Feb 04 01:34:56 EST 2021 is after Sun Sep 30 00:00:00 EDT 2018
Thu Feb 04 01:34:56 EST 2021 is after Sun Sep 30 00:00:00 EDT 2018

today in DEFAULT style in my local system:
Feb 4, 2021

today in SHORT style in my local system:
2/4/21

today in DEFAULT style in the fr_FR system:
4 févr. 2021
*/