Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > J2EE
|
J2EE General J2EE (Java 2 Enterprise Edition) discussions. Questions not specific to EE will be redirected elsewhere.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the J2EE section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 21st, 2005, 04:27 PM
Registered User
 
Join Date: Aug 2005
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default arraylistclasslist & arraylistclasslist tester

the compiler is saying "}" is expected on line 105 but when i add this closed bracket the problem is not solved as it says the same thing again when i compile it.
these errors occur in both of these programs.

package arrayclasses;

import java.util.*;

public class ArrayListClassList {
   private String courseTitle;
   private String discipline;
   private String semester;
   private String instructor;
   private String courseID;
   private ArrayList studentList;

   public ArrayListClassList(String title, String disc,
                             String sem, String ins, String ID, String s) {
      courseTitle = title;
      discipline = disc;
      semester = sem;
      instructor = ins;
      courseID = ID;
      studentList = new ArrayList();
      student = s;
   }

   public void add(Student s) { // don't forget duplicates
      studentList.add(s);
   }

   public String getCourseID() {
      return courseID;
   }

   public String getDiscipline() {
      return discipline;
   }

   public double getGrade(String ID) {
      Student thisStudent = getStudent(ID);
      if (thisStudent == null){
         return -1;
      return thisStudent.getGrade();
   }
}
   public String getInstructor() {
      return instructor;
   }

   public String getSemester() {
      return semester;
   }

   public String getStudent() {
       return student;
   }

   public Student getStudent(String ID) {
      int position = find(ID);
      if (position == -1){
         return null;
      return (Student) (studentList.get(position));

   }
}

   public String getTitle() {
      return courseTitle;
   }

   public void remove(String ID) {
      int position = find(ID);
      if (position == -1){
         return;
      studentList.remove(position);
   }
}

   public void setGrade(String ID, double grade) {
      Student thisStudent = getStudent(ID);
      if (thisStudent != null){
         thisStudent.setGrade(grade);
   }
}

   public String toString() {
      StringBuffer buf = new StringBuffer(getClass().getName() + "[title=" +
                                          courseTitle + ",discipline=" +
                                          discipline +
                                          ",semester=" + semester +
                                          ",courseID=" +
                                          courseID + ",instructor=" +
                                          instructor + "]");
      for (int i = 0; i < studentList.size(); i++){
         buf.append("\n" + studentList.get(i));
      return buf.toString();
   }
}

   private int find(String ID) {
      for (int i = 0; i < studentList.size(); i++){
         if (ID.equals(( (Student) studentList.get(i)).getID())){
            return i;
      return -1;

   }
}
}


package arrayclasses;

public class ArrayListClassListTester {
   public static void main(String[] args) {
      ArrayListClassList cs1713 = new ArrayListClassList("Intro to Programming",
            "CS", "Fall2004", "Kay Robbins", "CS102333");
      System.out.println("\nClass is " + cs1713);
      cs1713.add(new Student("John", "348234", 95));
      System.out.println("\nAfter 1 add :" + cs1713);
      cs1713.add(new Student("John", "348235", 95));
      System.out.println("\nAfter 2 add :" + cs1713);
      cs1713.add(new Student("Fred", "12345", 80));
      System.out.println("\nAfter 3 add :" + cs1713);
      cs1713.remove("348234");
      System.out.println("\nRemoving 1 : " + cs1713);
      cs1713.setGrade("12345", 90);
      System.out.println("\nAfter changing Fred's :" + cs1713);
   }
}







Similar Threads
Thread Thread Starter Forum Replies Last Post
Error while testing the class tester curiaquita Java Basics 5 February 13th, 2009 02:07 AM
Javascript && keeps turnig into &amp;&amp; ayrton Pro VB.NET 2002/2003 3 June 27th, 2005 03:34 PM
Linux & KDE & C++ & QT & MYSQL & Kdevelop Munnnki Linux 0 January 2nd, 2005 05:41 PM
sql & join tables & find a field in multiple table trangd Beginning PHP 2 January 29th, 2004 07:18 PM
HTTP_REFERER Tester Sometimes Redirects OK Visitor markw707 Classic ASP Basics 4 August 21st, 2003 11:41 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.