Why is FileReader not reading beyond the end of the first line? - java

I'm trying to read in data from a text file using FileReader. There are four lines of text. Each line has the same attribute types (first name, last name, dob, ssn, etc.). I am trying to split the data read in by the " " delimiter into one long array and then assign the values to a record ArrayList. My logic (if you can even call it that), is that by doing this I'd have one giant array of String data which I could then assign to each of the record's 7 fields - 0-6 for the first record, 7-13 for the second record, 14-20 for the third... But it looks like my while loop is stopping at the end of line one. I feel really stupid here, but I cannot figure out how to get this to work. And yes, I know, there is a lot that is bad form in my code, but I'm just trying to get a feel for the functionality. Any advice here would be most appreciated. Thank you!
The text file looks like this:
John Smith 1996.03.07 123-45-6789 Chickenpox BedRest aspirin
Joe Blow 1996.03.07 123-45-6888 Smallpox BedRest Whiskey
Julie Wilson 1996.03.07 123-45-6999 Insomnia Exercise HotPeppers
Wayne Blaine 1942.07.07 123-45-6777 Measles WaitToGetBetter CodLiverOil
Here's my main.
public static void main(String [] args) throws Exception {
String line = "";
BlockRecord record0 = null;
BlockRecord record1 = null;
BlockRecord record2 = null;
BlockRecord record3 = null;
try {
ArrayList<String> data = new ArrayList<String>();
BufferedReader reader = new BufferedReader(new FileReader("BlockInput0.txt"));
while((line = reader.readLine()) != null) {
System.out.println(line);
data.add(line);
}
record0 = new BlockRecord();
record1 = new BlockRecord();
record2 = new BlockRecord();
record3 = new BlockRecord();
record0.setBlockID(new String(UUID.randomUUID().toString()));
record1.setBlockID(new String(UUID.randomUUID().toString()));
record2.setBlockID(new String(UUID.randomUUID().toString()));
record3.setBlockID(new String(UUID.randomUUID().toString()));
//manually set until more functionality is in place
data = line.split(" ");
record0.setFirstName(data[0]);
record0.setLastName(data[1]);
record0.setDob(data[2]);
record0.setSsn(data[3]);
record0.setDiagnosis(data[4]);
record0.setTreatment(data[5]);
record0.setRx(data[6]);
record1.setFirstName(data[7]);
record1.setLastName(data[8]);
record1.setDob(data[9]);
record1.setSsn(data[10]);
record1.setDiagnosis(data[11]);
record1.setTreatment(data[12]);
record1.setRx(data[13]);
record2.setFirstName(data[14]);
record2.setLastName(data[15]);
record2.setDob(data[16]);
record2.setSsn(data[17]);
record2.setDiagnosis(data[18]);
record2.setTreatment(data[19]);
record2.setRx(data[20]);
record3.setFirstName(data[21]);
record3.setLastName(data[22]);
record3.setDob(data[23]);
record3.setSsn(data[24]);
record3.setDiagnosis(data[25]);
record3.setTreatment(data[26]);
record3.setRx(data[27]);
}
}catch(Exception e) {
e.printStackTrace();
}
}
Here's my BlockRecord class:
class BlockRecord{
String firstName;
String lastName;
String ssn;
String dob;
String diagnosis;
String treatment;
String rx;
String seed;
String winner;
String blockID;
String previousHash;
String verificationID = "0";
String uuid = UUID.randomUUID().toString();
String winningHash;
public static KeyPair keyPair;
public static int recordCount;
public String getWinningHash() {
return winningHash;
}
public void setWinningHash(String winningHash) {
this.winningHash = winningHash;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getSsn() {
return ssn;
}
public void setSsn(String ssn) {
this.ssn = ssn;
}
public String getDob() {
return dob;
}
public void setDob(String dob) {
this.dob = dob;
}
public String getDiagnosis() {
return diagnosis;
}
public void setDiagnosis(String diagnosis) {
this.diagnosis = diagnosis;
}
public String getTreatment() {
return treatment;
}
public void setTreatment(String treatment) {
this.treatment = treatment;
}
public String getRx() {
return rx;
}
public void setRx(String rx) {
this.rx = rx;
}
public String getSeed() {
return seed;
}
public void setSeed(String seed) {
this.seed = seed;
}
public String getWinner() {
return winner;
}
public void setWinner(String winner) {
this.winner = winner;
}
public String getBlockID() {
return blockID;
}
public void setBlockID(String blockID) {
this.blockID = blockID;
}
public String getPreviousHash() {
return previousHash;
}
public void setPreviousHash(String previousHash) {
this.previousHash = previousHash;
}
public String getVerificationID() {
return verificationID;
}
public void setVerificationID(String verificationID) {
this.verificationID = verificationID;
}
public String getUuid() {
return uuid;
}
public void setUuid(String uuid) {
this.uuid = uuid;
}
}

You read all the lines and add each on them to the list data in the loop:
while((line = reader.readLine()) != null) {
System.out.println(line);
data.add(line);
}
But then, you only split line, which is the last read line.
data = line.split(" ");
Quick fix:
Merge all the lines into one. Then split it.
String mergedLines = "";
while((line = reader.readLine()) != null) {
System.out.println(line);
mergedLines = mergedLines + line;
}
This is really dirty and uneffective as the file already provides separated records.
Better solution:
Create a BlockRecordfor each line without merging them. Then store the record in a list.
ArrayList<BlockRecord> allRecords = new ArrayList<String>();
BufferedReader reader = new BufferedReader(new FileReader("BlockInput0.txt"));
while((line = reader.readLine()) != null) {
System.out.println(line);
data = line.split(" ");
BlockRecord record = new BlockRecord()
record.setFirstName(data[0]);
record.setLastName(data[1]);
record.setDob(data[2]);
record.setSsn(data[3]);
record.setDiagnosis(data[4]);
record.setTreatment(data[5]);
record.setRx(data[6]);
allRecords.add(record)
}
This way, you don't even have to know how many records to declare before reading

Related

Java Isolate comma seperated values in text file

I've been searching for a solution to my problem without any luck. So now I'm asking here for help.
I'm creating "Groups" by the following class:
public class Group {
private String groupID;
private ArrayList<User> usersInGroup;
The User class looks like this:
NOTE: I already have an ArrayList containing all existing Users.
public class User {
private String firstName;
private String lastName;
private String age;
private String gender;
private String usernameID;
private String password;
I'm already adding the groupID field from the "groupData.txt" CSV text file like this:
public static ArrayList<Group> listOfCreatedGroups() throws IOException {
ArrayList<Group> listOfGroups = new ArrayList<>();
FileReader fr = new FileReader("src/groupData.txt");
BufferedReader bfr = new BufferedReader(fr);
String line;
int totalLine = Destination.linesInFile("src/groupData.txt"); //total lines in file
for (int i = 0; i < totalLine; i++) {
line = bfr.readLine();
String[] groupID = line.split(",");
Group temp = new Group();
temp.setGroupID(groupID[0]);
listOfGroups.add(temp);
}
try {
bfr.close();
fr.close();
} catch (IOException e) {
e.printStackTrace();
}
return listOfGroups;
}
The "groupData.txt" file is structured like this:
Line example = groupID,String_1,String2,String3 ... Stringn,\n
groupid,user,user,user,user,user,user,user,
groupid,user,user,user,
groupid,user,user,user,user,user
groupid,user,user
groupid,user,user,user,user
Since I only have the number of users in every group User.usernameID as 1 to n strings in the text file I can't add the whole User object to the Arraylist usersInGroup.
I somehow need to isolate the usernameID's and find the corresponding Users and add them to the ArrayList usersInGroup.
I hope any of you can give me a hint in the right direction. Thanks.
I don't know if this is how you were wanting because I didn't find the user data very specific or even mentioned of how you wanted. But let me know if this is enough
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
public class Group {
private static String groupID;
private static ArrayList<User> usersInGroup = new ArrayList<User>();
public static void main (String [] args) throws IOException {
addListToGroup(readFile());
}
public static void addListToGroup(ArrayList<ArrayList<String>> list) {
for (int i = 0; i < list.size(); i++) {
groupID = list.get(i).get(0);
for (int x = 0; x < list.get(i).size(); x++) {
User temp = new User(); // change this to however you setup the txt file
// the information from the list is in list.get(i).get(x) in order as in the textfile
temp.setAge(null);
temp.setFirstName(null);
temp.setGender(null);
temp.setLastName(null);
temp.setPassword(null);
temp.setUsernameID(null);
usersInGroup.add(temp);
}
}
}
public static ArrayList<ArrayList<String>> readFile() throws IOException {
List<String> temp = new ArrayList<String>();
Path path = Paths.get("file.txt");
temp = Files.readAllLines(path);
ArrayList<ArrayList<String>> lines = new ArrayList<ArrayList<String>>();
for (int i = 0; i < temp.size(); i++) {
String [] s = temp.get(i).split(",");
ArrayList<String> quickArray = new ArrayList<String>();
for (int x=0; x < s.length; x++) {
quickArray.add(s[x]);
}
lines.add(quickArray);
}
return lines;
}
}
class User {
private String firstName;
private String lastName;
private String age;
private String gender;
private String usernameID;
private String password;
//setters and getters
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getAge() {
return age;
}
public void setAge(String age) {
this.age = age;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public String getUsernameID() {
return usernameID;
}
public void setUsernameID(String usernameID) {
this.usernameID = usernameID;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}

Scan some text in a document, replace certain words(these words should be variables) and save in a new document using Apache POI in Java

I have json file from which I parse json objects to java objects using Gson library. The next step is to create main class in which with the help of Apache POI prepared docx file is read, some changes were made in the text and new document with changes is created. The problem I faced is that the text which should be changed need to be variable(from json file). I mean that "name" and "testName" both should be variables or methods, so I can call them from text.contains. Can you show my mistake and the right way to do the task. Thanks in advance.
Here is my code `
public class main {
public static void gson() {
Gson gson = new Gson();
BufferedReader br = null;
try {
br = new BufferedReader(new FileReader("jsonn.json"));
Result result = gson.fromJson(br, Result.class);
if (result != null) {
result.getName();
result.getLastname();
System.out.println(result.getName());
System.out.println(result.getLastname());
for (Phone p : result.getPhones()) {
p.getType();
p.getNum();
System.out.println(p.getType() + ": " + p.getNum());
// System.out.println(p.getType()+" : "+p.getNum());
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} finally {
if (br != null) {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}}
public class Result {
#SerializedName("name")
#Expose
private String name;
#SerializedName("lastname")
#Expose
private String lastname;
#SerializedName("phones")
#Expose
private List<Phone> phones = null;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getLastname() {
return lastname;
}
public void setLastname(String lastname) {
this.lastname = lastname;
}
public List<Phone> getPhones() {
return phones;
}
public void setPhones(List<Phone> phones) {
this.phones = phones;
}}
public class Phone {
#SerializedName("name")
#Expose
private String name;
#SerializedName("lastName")
#Expose
private String lastName;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
#SerializedName("num")
#Expose
private String num;
#SerializedName("type")
#Expose
private String type;
public String getNum() {
return num;
}
public void setNum(String num) {
this.num = num;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}}
public class Read {
public static void main(String[] args) throws InvalidFormatException,
IOException {
main.gson();
XWPFDocument doc = new XWPFDocument(OPCPackage.open("Шаблон.docx"));
Result res = new Result();
String replaceName = res.getName();
for (XWPFParagraph p : doc.getParagraphs()) {
List<XWPFRun> runs = p.getRuns();
if (runs != null) {
for (XWPFRun r : runs) {
String text = r.getText(0);
if (text != null && text.contains("name")) {
text = text.replace("name", "Alex");
r.setText(text, 0);
}
}
}
}
for (XWPFTable tbl : doc.getTables()) {
for (XWPFTableRow row : tbl.getRows()) {
for (XWPFTableCell cell : row.getTableCells()) {
for (XWPFParagraph p : cell.getParagraphs()) {
for (XWPFRun r : p.getRuns()) {
String text = r.getText(0);
if (text != null && text.contains("name")) {
text = text.replace("name", "Alex");
r.setText(text, 0);
}
}
}
}
}
}
doc.write(new FileOutputStream("Пример.docx"));
}}
`
Here is json file:
{
"name":"testName",
"lastname":"testLastName",
"phones":[
{
"num":"9000000",
"type":"mobile"
},
{
"num":"1000000",
"type":"home"
} ]}

Prevent adding duplicate data into JTable in Java

How to prevent adding duplicate data into Jtable.
This is my code.
try {
URL url = new URL("http://localhost:8080/webservice/rest/bdetails/get");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setRequestProperty("Accept", "application/json");
if (conn.getResponseCode() != 200) {
throw new RuntimeException("Failed : HTTP error code : "
+ conn.getResponseCode());
}
BufferedReader br = new BufferedReader(new InputStreamReader(
(conn.getInputStream())));
String output;
String json = "";
System.out.println("Output from Server .... \n");
while ((output = br.readLine()) != null) {
System.out.println(output);
json += output;
}
conn.disconnect();
java.lang.reflect.Type listType = new TypeToken<ArrayList<BDetails>>() {
}.getType();
List<BDetails> bList = new Gson().fromJson(json, listType);
for( BDetails adr : bList)
{
DefaultTableModel model = (DefaultTableModel) pTable.getModel();
Vector<String> row = new Vector<String>();
row.add(detail.getUserName());
row.add(detail.getFirstName());
row.add(detail.getLastName());
row.add(detail.getAddress();
model.addRow( row );
}
} catch (IOException | RuntimeException ex) {
System.out.println(ex);
}
When I run this method It add data to the table. When I run again It add same data to the table. And again it do the same. How can I fix that? Can anybody help me? Thanks in advance. Below I have added the BDetails Class.
BDetails Class
public class BDetails
{
private String username;
private String firstName;
private String lastName;
private String address;
public BDetails() {
}
public BDetails(String username, String firstName, String lastName, String address) {
this.username = username;
this.firstName = firstName;
this.lastName = lastName;
this.address = address;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
You can try this,
java.lang.reflect.Type listType = new TypeToken<ArrayList<BDetails>>() {
}.getType();
List<BDetails> bList = new Gson().fromJson(json, listType);
DefaultTableModel model = (DefaultTableModel) pTable.getModel();
model.setRowCount(0);
for( BDetails adr : bList)
{
Vector<String> row = new Vector<String>();
row.add(detail.getUserName());
row.add(detail.getFirstName());
row.add(detail.getLastName());
row.add(detail.getAddress();
model.addRow( row );
}
model.setRowCount(0) will clear all the rows before inserting data. It worked for me.
First, I took BDetails and used Netbeans to add the equals and hashcode methods. This is important, as it provides away to assess if two instances of an object are the same
public class BDetails {
private String username;
private String firstName;
private String lastName;
private String address;
public BDetails() {
}
public BDetails(String username, String firstName, String lastName, String address) {
this.username = username;
this.firstName = firstName;
this.lastName = lastName;
this.address = address;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
#Override
public int hashCode() {
int hash = 7;
hash = 13 * hash + Objects.hashCode(this.username);
hash = 13 * hash + Objects.hashCode(this.firstName);
hash = 13 * hash + Objects.hashCode(this.lastName);
hash = 13 * hash + Objects.hashCode(this.address);
return hash;
}
#Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final BDetails other = (BDetails) obj;
if (!Objects.equals(this.username, other.username)) {
return false;
}
if (!Objects.equals(this.firstName, other.firstName)) {
return false;
}
if (!Objects.equals(this.lastName, other.lastName)) {
return false;
}
if (!Objects.equals(this.address, other.address)) {
return false;
}
return true;
}
}
I then create a custom TableModel (I'm bias, but I don't have much love for DefaultTableModel and it makes the next step easier)
public class BDetailsTableModel extends AbstractTableModel {
private List<BDetails> rows;
private String[] columnNames = {"User name", "First name", "Last Name", "Address"};
public BDetailsTableModel(List<BDetails> rows) {
this.rows = rows;
}
#Override
public int getRowCount() {
return rows.size();
}
#Override
public String getColumnName(int column) {
return columnNames[column];
}
#Override
public int getColumnCount() {
return 4;
}
#Override
public Object getValueAt(int rowIndex, int columnIndex) {
BDetails details = rows.get(rowIndex);
switch (columnIndex) {
case 0:
return details.getUsername();
case 1:
return details.getFirstName();
case 2:
return details.getLastName();
case 3:
return details.getAddress();
}
return null;
}
}
And finally...
List<BDetails> bList = new Gson().fromJson(json, listType);
//for (BDetails adr : bList) {
// DefaultTableModel model = (DefaultTableModel) pTable.getModel();
// Vector<String> row = new Vector<String>();
// row.add(detail.getUserName());
// row.add(detail.getFirstName());
// row.add(detail.getLastName());
// row.add(detail.getAddress();
// model.addRow(row);
//}
Set<BDetails> unquie = new HashSet<>(bList);
List<BDetails> rows = new ArrayList<>(unquie);
BDetailsTableModel model = new BDetailsTableModel(rows);
pTable.setModel(model);
Okay, all this does is adds the bList to Set, this will remove all duplicates from the list for us (using the hashcode of the objects), add the results to a ArrayList (because it has a get method) and then supplies that to our BDetailsTableModel
Now, if you don't want to replace the TableModel each time, but instead, add the results it becomes a little more difficult, as you need to manage the possibility that the new set of data might contain duplicates of the old set.
You could add the following to BDetailsTableModel...
public void add(BDetails details) {
int rowCount = getRowCount();
if (rows.contains(details)) {
return;
}
rows.add(details);
fireTableRowsInserted(rowCount, rowCount);
}
public void addAll(List<BDetails> newRows) {
Set<BDetails> rows = new HashSet<>(newRows);
addAll(rows);
}
public void addAll(Set<BDetails> newRows) {
Set<BDetails> allRows = new HashSet<>(rows);
allRows.addAll(newRows);
rows = new ArrayList<>(allRows);
fireTableDataChanged();
}
and instead of creating a new instance of BDetailsTableModel, simply use the existing instance (from pTable) and use the above functionality to add new rows

Write text file content into custom arraylist in Java

Suppose I have a text file DataBase.txt with the following content:
1 leo messi 12.12.1986
2 cristiano ronaldo 22.01.1985
3 arjen robben 14.11.1991
And a custom arraylist which looks like this:
public static ArrayList<Rows> InfoList = new ArrayList<Rows>();
This is my Rows class implementation with setters, getters and toString method:
public class Rows {
public int id;
public String firstName;
public String secondName;
public String dateOfbrth;
#Override
public String toString() {
return this.id + " " + this.firstName + " " +
this.secondName + " " + this.dateOfbrth;
}
public int getId() {
return id;
}
public String getFirstName() {
return firstName;
}
public String getSecondName() {
return secondName;
}
public String getDateOfbrth() {
return dateOfbrth;
}
public void setId(int id) {
this.id = id;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public void setSecondName(String secondName) {
this.secondName = secondName;
}
public void setDateOfbrth(String dateOfbrth) {
this.dateOfbrth = dateOfbrth;
}
}
So. the question is: How to write text file content into an arrayList where every element will be refered to its own field in class Rows. despite of different count of spaces in each line ? Which algorithms or Java classes will be useful to approach that ?
I'm novice in Java so I tried to do this using BuffredReader but I stuck with separating line and adding each element into arrayList:
try (BufferedReader br = new BufferedReader(new FileReader("F:/DataBase.txt"))) {
for (String line; (line = br.readLine()) != null; ) {
}
}
Thanks for any help
This is the way:
try (BufferedReader br = new BufferedReader(new FileReader("F:/DataBase.txt"))) {
String line;
while((line = br.readLine())!=null ) {
String[] values = line.split("\\s+");
...
}
}
while ((line = br.readLine()) != null) {
String[] row = line.split("\\s+");
Row row = new Row();
row.setId(row[0]);
row.setFirstName(row[1]);
row.setSecondName(row[2]);
row.setDateOfbrth(row[3]);
InfoList.add(row);
}
\s+ is a regex expression which will cause any number of consecutive spaces to split your string into tokens, see this answer How to split a String by space
Hope it helps.

Where should i declare the field in this code in order for it to compile?

This is not supposed to be a client class. I'm just making a class for others to use. I'm using this for a Highschool. For example i have classes for the address, teacher, students, principal, roomnumber, etc..But its not compiling for some odd reason. I believe its because I'm not declaring a field but not sure.
import java.io.*;
public class HighSchool {
// Constructors
public HighSchool() { }
public HighSchool(String title, String teacher, int roomNumber, String period, String[] students, String address, String subjects ) {
this.title = title;
this.teacher = teacher;
this.roomNumber = roomNumber;
this.period = period;
this.String[] students = students;
this.String address =a ddress;
this.String subjects = subjects;
}
public class Classcourse (String title, String teacher, int roomNumber, String period, String[] students, String address, String subjects
private String period;) {
public String gettitle() {
return title;
}
public void settitle(String title) {
this.title = title;
}
public String getteacher() {
return teacher;
}
public void setteacher(String teacher) {
this.teacher = teacher;
}
public int getroomNumber() {
return roomNumber;
}
public void setroomNumber (int roomNumber) {
this.roomNumber = roomNumber;
}
public String getperiod() {
return getperiod();
}
public void setperiod (String period) {
this.period = period;
}
public String[] getstudents () {
return students[];
}
public void setstudents[] (String[] students
private String address;) {
this.students = students;
}
public String getaddress() {
return address;
}
public void setaddress (String address) {
this.address = address;
}
public String getsubjects() {
return subjects;
}
public void setsubjects (String subjects) {
this.subjects = subjects;
}
}
// modifier method
public void addstudents(String students) {
String[] newstudents = new String[students.length + 1];
for (int i = 0; i < students.length; i++) {
newstudents[i] = students[i];
}
newstudents[students.length] = student;
students = newstudents;
}
public boolean isInClass(String students) {
for (int i = 0; i < students.length; i++) {
if (students[i].equals(students)) {
return true;
}
}
return false;
}
// static creator method
public static HighSchool readFromInput() throws IOException {
BufferedReader kb = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter a HighSchool title: ");
HighSchool newHighSchool = new HighSchool(kb.readLine());
String students = null;
do {
System.out.print("Enter a student, or press Enter to finish: ");
students = kb.readLine();
if (students != null){
newHighSchool.addstudents(students);
}
} while (students != null);
return newHighSchool;
}
// Variables (Fields)
private String title;
private String[] students;
}
In addition, you wrote something that doesn't make sense from the point of view of Java Compiler:
private String period;) {
- probably remove ")".
The second thing:
Take a look on the declaration of class Classcourse.
It rather sounds wrong, although it can be an issue of this site's editor or something...
An "overall" hint - java has a very "intelligent" compiler in the most of the cases it can say what's wrong exactly with your code, so, assuming you're a newbie in Java, try to understand what compiler says to you.
Good luck!
Some things I noticed about the code:
public String getperiod() {
return getperiod();
}
This code will cause a endless loop when you call this function.
private String address;) {
this.students = students;
}
The compiler will give an error about the ";)". Change it to "()" to fix this.
Furthermore, you should really tell us more about the errors it's giving you. We can't help you if you don't give us the compiler errors.

Categories

Resources