first commit

This commit is contained in:
Boris
2024-01-15 20:14:10 +00:00
commit 8c81ee28b7
3106 changed files with 474415 additions and 0 deletions

View File

@@ -0,0 +1,23 @@
#BlueJ class context
comment0.params=maxNumberOfStudents
comment0.target=LabClass(int)
comment0.text=\n\ Create\ a\ LabClass\ with\ a\ maximum\ number\ of\ enrolments.\ All\ other\ details\n\ are\ set\ to\ default\ values.\n
comment1.params=newStudent
comment1.target=void\ enrollStudent(Student)
comment1.text=\n\ Add\ a\ student\ to\ this\ LabClass.\n
comment2.params=
comment2.target=int\ numberOfStudents()
comment2.text=\n\ Return\ the\ number\ of\ students\ currently\ enrolled\ in\ this\ LabClass.\n
comment3.params=roomNumber
comment3.target=void\ setRoom(java.lang.String)
comment3.text=\n\ Set\ the\ room\ number\ for\ this\ LabClass.\n
comment4.params=timeAndDayString
comment4.target=void\ setTime(java.lang.String)
comment4.text=\n\ Set\ the\ time\ for\ this\ LabClass.\ The\ parameter\ should\ define\ the\ day\n\ and\ the\ time\ of\ day,\ such\ as\ "Friday,\ 10am".\n
comment5.params=instructorName
comment5.target=void\ setInstructor(java.lang.String)
comment5.text=\n\ Set\ the\ name\ of\ the\ instructor\ for\ this\ LabClass.\n
comment6.params=
comment6.target=void\ printList()
comment6.text=\n\ Print\ out\ a\ class\ list\ with\ other\ LabClass\ details\ to\ the\ standard\n\ terminal.\n
numComments=7

View File

@@ -0,0 +1,91 @@
import java.util.*;
/**
* The LabClass class represents an enrolment list for one lab class. It stores
* the time, room and participants of the lab, as well as the instructor's name.
*
* @author Michael Kölling and David Barnes
* @version 2016.02.29
*/
public class LabClass
{
private String instructor;
private String room;
private String timeAndDay;
private ArrayList<Student> students;
private int capacity;
/**
* Create a LabClass with a maximum number of enrolments. All other details
* are set to default values.
*/
public LabClass(int maxNumberOfStudents)
{
instructor = "unknown";
room = "unknown";
timeAndDay = "unknown";
students = new ArrayList<Student>();
capacity = maxNumberOfStudents;
}
/**
* Add a student to this LabClass.
*/
public void enrollStudent(Student newStudent)
{
if(students.size() == capacity) {
System.out.println("The class is full, you cannot enrol.");
}
else {
students.add(newStudent);
}
}
/**
* Return the number of students currently enrolled in this LabClass.
*/
public int numberOfStudents()
{
return students.size();
}
/**
* Set the room number for this LabClass.
*/
public void setRoom(String roomNumber)
{
room = roomNumber;
}
/**
* Set the time for this LabClass. The parameter should define the day
* and the time of day, such as "Friday, 10am".
*/
public void setTime(String timeAndDayString)
{
timeAndDay = timeAndDayString;
}
/**
* Set the name of the instructor for this LabClass.
*/
public void setInstructor(String instructorName)
{
instructor = instructorName;
}
/**
* Print out a class list with other LabClass details to the standard
* terminal.
*/
public void printList()
{
System.out.println("Lab class " + timeAndDay);
System.out.println("Instructor: " + instructor + " Room: " + room);
System.out.println("Class list:");
for(Student student : students) {
student.print();
}
System.out.println("Number of students: " + numberOfStudents());
}
}

View File

@@ -0,0 +1,18 @@
Project: lab-classes
Authors: David J. Barnes and Michael Kölling
This project is part of the material for the book
Objects First with Java - A Practical Introduction using BlueJ
Sixth edition
David J. Barnes and Michael Kölling
Pearson Education, 2016
It is discussed in chapter 1.
The purpose of this project is to illustrate object interaction and to examine
some simple code. See chapters one and three of the book.
To use this project, create some Student objects, then create a LabClass object.
Add the students to the class using the "enrolStudent" method. Print a class
list.

View File

@@ -0,0 +1,26 @@
#BlueJ class context
comment0.params=fullName\ studentID
comment0.target=Student(java.lang.String,\ java.lang.String)
comment0.text=\n\ Create\ a\ new\ student\ with\ a\ given\ name\ and\ ID\ number.\n
comment1.params=
comment1.target=java.lang.String\ getName()
comment1.text=\n\ Return\ the\ full\ name\ of\ this\ student.\n
comment2.params=replacementName
comment2.target=void\ changeName(java.lang.String)
comment2.text=\n\ Set\ a\ new\ name\ for\ this\ student.\n
comment3.params=
comment3.target=java.lang.String\ getStudentID()
comment3.text=\n\ Return\ the\ student\ ID\ of\ this\ student.\n
comment4.params=additionalPoints
comment4.target=void\ addCredits(int)
comment4.text=\n\ Add\ some\ credit\ points\ to\ the\ student's\ accumulated\ credits.\n
comment5.params=
comment5.target=int\ getCredits()
comment5.text=\n\ Return\ the\ number\ of\ credit\ points\ this\ student\ has\ accumulated.\n
comment6.params=
comment6.target=java.lang.String\ getLoginName()
comment6.text=\n\ Return\ the\ login\ name\ of\ this\ student.\ The\ login\ name\ is\ a\ combination\n\ of\ the\ first\ four\ characters\ of\ the\ student's\ name\ and\ the\ first\ three\n\ characters\ of\ the\ student's\ ID\ number.\n
comment7.params=
comment7.target=void\ print()
comment7.text=\n\ Print\ the\ student's\ name\ and\ ID\ number\ to\ the\ output\ terminal.\n
numComments=8

View File

@@ -0,0 +1,85 @@
/**
* The Student class represents a student in a student administration system.
* It holds the student details relevant in our context.
*
* @author Michael Kölling and David Barnes
* @version 2016.02.29
*/
public class Student
{
// the student's full name
private String name;
// the student ID
private String id;
// the amount of credits for study taken so far
private int credits;
/**
* Create a new student with a given name and ID number.
*/
public Student(String fullName, String studentID)
{
name = fullName;
id = studentID;
credits = 0;
}
/**
* Return the full name of this student.
*/
public String getName()
{
return name;
}
/**
* Set a new name for this student.
*/
public void changeName(String replacementName)
{
name = replacementName;
}
/**
* Return the student ID of this student.
*/
public String getStudentID()
{
return id;
}
/**
* Add some credit points to the student's accumulated credits.
*/
public void addCredits(int additionalPoints)
{
credits += additionalPoints;
}
/**
* Return the number of credit points this student has accumulated.
*/
public int getCredits()
{
return credits;
}
/**
* Return the login name of this student. The login name is a combination
* of the first four characters of the student's name and the first three
* characters of the student's ID number.
*/
public String getLoginName()
{
return name.substring(0,4) + id.substring(0,3);
}
/**
* Print the student's name and ID number to the output terminal.
*/
public void print()
{
System.out.println(name + ", student ID: " + id + ", credits: " + credits);
}
}

View File

@@ -0,0 +1,45 @@
#BlueJ package file
dependency1.from=LabClass
dependency1.to=Student
dependency1.type=UsesDependency
objectbench.height=100
objectbench.width=439
package.editor.height=358
package.editor.width=636
package.editor.x=70
package.editor.y=80
package.numDependencies=1
package.numTargets=2
package.showExtends=true
package.showUses=true
project.charset=UTF-8
readme.editor.height=607
readme.editor.width=815
readme.editor.x=53
readme.editor.y=45
target1.editor.height=730
target1.editor.width=826
target1.editor.x=53
target1.editor.y=60
target1.height=60
target1.name=LabClass
target1.naviview.expanded=true
target1.showInterface=false
target1.type=ClassTarget
target1.typeParameters=
target1.width=100
target1.x=140
target1.y=90
target2.editor.height=777
target2.editor.width=882
target2.editor.x=53
target2.editor.y=23
target2.height=60
target2.name=Student
target2.naviview.expanded=true
target2.showInterface=false
target2.type=ClassTarget
target2.typeParameters=
target2.width=100
target2.x=280
target2.y=190