Skip to content

Problem 2 : Basic OOP

Jatawatsafe edited this page May 22, 2018 · 1 revision

WELCOME TO S2S (SitSpace To School)

by Safe_IT23

PART 1: STORY

After SitSpace is successful. The header of SitSpace have project named "S2S" for find student to be a new generation of SitSpace. You are a programmer in S2S. He told you that you must create a program for our school. This program can run id and keep name and score of each Student. Another function, It can calculate grades each student. I think you can remember SIT SPACE. This one is easily than that! You need to know concept about object, if-else, and loops. Fighting for Future!

PART 1: Create a basic Array Object

Create class Student and have details as follows:

  • a String data named ‘name’ for the stocked’s name of student.
  • a integer data named ‘studentId’ for the stocked’s id of student.
  • a double data named ‘scores’ for the stocked’s scores of student.
  • a char data named ‘grades’ for the stocked’s grades of student.
  • a static integer data named ‘counts’ for count number of students
  • has getter and setter Method of each data except studentId hasn’t setter method.
  • has toString Method
  • A constructor that creates a stock with the specific name and scores only.
  • The studenId data is autorun from 601, 602, 603, … when you create array object.
  • The grades data is calculare from scores. If scores >=80, grades= ‘A’. Else if scores >=70, grades= ‘B’. Else if scores >=60, grades= ‘C’. Else if scores >=50, grades= ‘D’. Else if scores is under, grades = ‘F’

Create Driver Class named StudentTest and receive number of student from keyboard after that you need to receive name and scores of each students from keyboard.

  • The result will show numbers of Student in SIT SCHOOL and show data of each students.

Enter Number of Student: 4

Student1

Enter Name: Ant

Enter Scores: 68

Student2

Enter Name: bat

Enter Scores: 49.5

Student3

Enter Name: Cat

Enter Scores: 80.5

Student4

Enter Name: Dog

Enter Scores: 52.25

ตัวอย่าง OUTPUT

SIT SCHOOL have 4 students.

SIT INFO

ID: 601 | Name=Ant | scores=68.0 | Grade 'C'

ID: 602 | Name=bat | scores=49.5 | Grade 'F'

ID: 603 | Name=Cat | scores=80.5 | Grade 'A'

ID: 604 | Name=Dog | scores=52.25 | Grade 'D'


PART 2: STORY

The SIT School program is successful. The header of school like this program very much. He wants to praise the student who get the highest scores in this school for make this school more popular. I think if you can do part 1, you can do part 2. Let’s start now !

PART 2: Create Method for find student who get the highest scores

Create method named highestScore and return String type. Message will show named and scores of Student who get the highest scores

ตัวอย่าง OUTPUT

SIT SCHOOL have 3 students.

SIT INFO

ID: 601 | Name=Safe | scores=98.0 | Grade 'A'

ID: 602 | Name=Book | scores=89.3 | Grade 'A'

ID: 603 | Name=Run | scores=95.75 | Grade 'A'

The Student named Safe get Highest Scores = 98.0


PART 3: Create Aggregation

(Use Student from Part1 to create Aggregation)

Create class Room and have details as follows:

  • a Student Array data named ‘std’ for the stocked’s Student.
  • a String data named 'teacher' for the stocked's name of teacher. (Will use in Part4)
  • a integer data named ‘room’ for the stocked’s number room.
  • a integer data named 'point' for the stocked's point of room.
  • a static integer data named ‘countsRoom’ for count number of room.
  • has method getter, setter and toString of each data.
  • a method: "public String topStudent()" will show name of student that get highest score
  • a method: "public int getA()" will show number of Student that get grades A. (Adapt from Part2)

Create class Secondary and have details as follows:

  • a Room Array data named ‘room’ for the stocked’s Room.
  • a integer data named 'level' for the stocked's Level.
  • a method: "public String topRoom()" will show room and point which room get highest point
  • a method: "public void addPoint(Room room[i],int point)" will add point to room[i]
  • a method: "public void minusPoint(Room room[i],int point)" will minus point to room[i]

PART 4: Create Inheritance

(You need to keep Student, Room and Secondary for the future! This time we will create new Class)


KEY Student: https://github.com/safesit23/JavaLabExercise/blob/master/INT105/src/Array/Student.java

KEY SitStudent: https://github.com/safesit23/JavaLabExercise/blob/master/INT105/src/Array/SitStudent.java

Clone this wiki locally