java 新建double对象_java-如何在BlueJ“创建对象”对话框中输入...
我不嘗試將日期格式設(shè)置為YYYY-MM-DD或dd / MM / YYYY.我在問LocalDate的字面格式.
我剛剛開始學(xué)習(xí)Java,并且正在使用稱為BlueJ的IDE.我想創(chuàng)建一個測試方法.
屏幕截圖將顯示我正在嘗試做的
現(xiàn)在,從構(gòu)造函數(shù)開始,我們知道它需要一個int,LocalDate和一個double.我在網(wǎng)上搜索后發(fā)現(xiàn)
07001
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’.
所以我將一個普通數(shù)字放在10001作為testID,并將double變成50.5
我也知道要為它注冊一個字符串(如果需要),我需要將其包含在“字符串”中
但是我嘗試了各種各樣的方式輸入日期,但我會遇到一個錯誤
2018-05-30,30-05-2018,30 / 05/2018將給我
Error: incompatible types: Int cannot be converted to java.time.LocalDate
另一方面,“ 30/05/2018”會給我
Error: Incompatible types: java.lang.String cannot be converted to java.time.LocalDate
如果我嘗試30.05.2018它會說
Error: ';' expected
如果我嘗試’2018-05-30’會說
Error: unclosed character literal
我沒有辦法嘗試.因此,如果您能告訴我如何將其放入其中,那就太好了.
我只是真的需要知道BlueJ如何讓我輸入它.因為BlueJ的資源在線如此稀疏.
碼:
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 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() ;
}
/**
* 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 listMCQ()
{
return MCQDetails;
}
public MCQ findMCQ(int MCQID)
{
for(MCQ m : MCQDetails)
{
if(m.getQuestionID() == MCQID)
{
return m;
}
}
return null;
}
總結(jié)
以上是生活随笔為你收集整理的java 新建double对象_java-如何在BlueJ“创建对象”对话框中输入...的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java查看sql视图_SQL视图与MS
- 下一篇: java application文件夹_