I'm not trying to format the date in YYYY-MM-DD or dd/MM/YYYY. I'm asking about the literal format of LocalDate.
I just started learning Java and I am using this IDE called BlueJ. and I want to create a test method.
The screenshot will show what I am trying to do
Now since from the constructor we know that it requires a int, LocalDate and a double. I've searched online and found that
https://www.javabrahman.com/java-8/java-8-working-with-localdate-localtime-localdatetime-tutorial-with-examples/
java.time.LocalDate: A LocalDate instance holds a date without a time zone, in ISO-86011 calendar system. LocalDate has the default format ‘YYYY-MM-DD’ as in ‘2016-12-12’.
So I would put a normal number in 10001 for the testID and double would be something like 50.5 I also know that for it to register a string (if it was needed) I would need to enclose it within "string"
But I've tried all sorts of way to put in the date and I would be left with an error
2018-05-30,30-05-2018,30/05/2018 would give me
Error: incompatible types: Int cannot be converted to java.time.LocalDate
"30/05/2018" on the other hand would give me
Error: Incompatible types: java.lang.String cannot be converted to java.time.LocalDate
If I try 30.05.2018 it would say
Error: ';' expected
If I try '2018-05-30' it would say
Error: unclosed character literal
I ran out of ways to try it. So if you could tell me how I should put it in there, that would be great.
I just really need to know how BlueJ wants me to input it. Cause the resources for BlueJ is so sparse online.
Code:
import java.time.LocalDate;
import java.util.ArrayList;
/**
* Write a description of class TestPaper here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class TestPaper
{
// instance variables - replace the example below with your own
private int testID;
private LocalDate testDate;
private double testMarks;
private ArrayList<MCQ> MCQDetails;
/**
* Constructor for objects of class TestPaper
*/
public TestPaper(int testID, LocalDate testDate, double testMarks)
{
this.testID = testID;
this.testDate = testDate;
this.testMarks = testMarks;
MCQDetails = new ArrayList<MCQ>() ;
}
/**
* Accessor Method getTestID to get the testID
*
* @return int value of the choice ID
*/
public int getTestID(){
return testID;
}
/**
* Mutator Method to set the testID
*
* @param int format of the testID to set
*/
public void setTestID(int testID){
this.testID = testID;
}
/**
* Accessor Method getTestMarks to get the Test Marks
*
* @return double value of the test marks
*/
public double getTestMarks(){
return testMarks;
}
/**
* Mutator Method to set the testMarks
*
* @param String format of the choice Description to be set
*/
public void setTestMarks(double testMarks){
this.testMarks = testMarks;
}
/**
* Accessor Method getTestDate to get the testDate
*
* @return LocalDate value of the testDate
*/
public LocalDate getTestDate(){
return testDate;
}
/**
* Mutator Method to set the testDate
*
* @param LocalDate format of the testDate to set
*/
public void setTestDate(LocalDate testDate){
this.testDate = testDate;
}
/**
* Method addMCQ will allow users to add a MCQ Object to the list of MCQ
*
* @param addMCQ a MCQ Object
* @return boolean will return true if it is successfully added or false if not
*/
public boolean addMCQ(MCQ MCQName)
{
return MCQDetails.add(MCQName);
}
/**
* Method removeMCQ to remove an MCQ object from the Arraylist
*
* @param MCQName A parameter of type MCQ
*/
public void removeMCQ(MCQ MCQName)
{
MCQDetails.remove(MCQName);
}
/**
* Method listMCQ to return a list of MCQ arraylist
*
* @return The return value of MCQDetails (MCQ Arraylist)
*/
public ArrayList<MCQ> listMCQ()
{
return MCQDetails;
}
public MCQ findMCQ(int MCQID)
{
for(MCQ m : MCQDetails)
{
if(m.getQuestionID() == MCQID)
{
return m;
}
}
return null;
}