Como inserir um valor LocalDate na caixa de diálogo BlueJ "Create Object"
Não estou tentando formatar a data em AAAA-MM-DD ou dd / MM / AAAA. Estou perguntando sobre o formato literal do LocalDate.
Comecei a aprender Java e estou usando esse IDE chamado BlueJ. e eu quero criar um método de teste.
A captura de tela mostrará o que estou tentando fazer
Agora, desde o construtor, sabemos que ele requer int, LocalDate e double. Eu pesquisei online e descobri que
java.time.LocalDate: uma instância LocalDate mantém uma data sem fuso horário no sistema de calendário ISO-86011. LocalDate tem o formato padrão "AAAA-MM-DD", como em "12/12/2016".
Então, eu colocaria um número normal em 10001 para o testID e double seria algo como 50,5. Também sei que para registrar uma string (se necessário), seria necessário incluí-lo em "string"
Mas eu tentei todo o tipo de data e eu ficaria com um erro
2018-05-30,30-05-2018,30 / 05/2018 me daria
Error: incompatible types: Int cannot be converted to java.time.LocalDate
"30/05/2018", por outro lado, me daria
Error: Incompatible types: java.lang.String cannot be converted to java.time.LocalDate
Se eu tentar 30.05.2018, diria
Error: ';' expected
Se eu tentar '2018-05-30', diria
Error: unclosed character literal
Fiquei sem maneiras de experimentar. Então, se você pudesse me dizer como eu deveria colocá-lo lá, seria ótimo.
Eu realmente preciso saber como o BlueJ quer que eu insira. Porque os recursos do BlueJ são tão escassos online.
Código:
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;
}