[Show all top banners]

jaka2701
Replies to this thread:

More by jaka2701
What people are reading
Subscribers
:: Subscribe
Back to: Computer/IT Refresh page to view new replies
 little help for java newbie please!!
[VIEWED 5417 TIMES]
SAVE! for ease of future access.
Posted on 07-11-15 11:53 PM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Part 1- The Student Class (10 points)

Write a class called Student. A student is described by:

a name
an ID (text-based, such as "A146")
whether or not tuition is paid
Write a constructor, getters and setters, and a toString method for this class.

Part 2- The Course Class (10 points)

Write a class called Course to represent a college class. A course is described by:

a name
the maximum students that can be enrolled in the course
Write a constructor, getters and setters (using appropriate validity checks), and a toString method.

Part 3- The Roster (10 points)

Add a roster to the Course class. A roster is represented by an array of Student objects.

Add instance data and code to the constructor to represent the roster.

(You do not need to add a getter and setter. The methods below will allow an outside class to access the roster appropriately.)

Part 4- Course Methods (50 points)

Write the following 3 methods:

public boolean addStudent(Student s)

if there is room for the student, add the student to the roster and return true

return false otherwise

public boolean dropStudent(Student s)

if the student is currently in the roster, remove them from the roster and return true

return false otherwise

Note: There are different approaches to implementing this method. Any approach is fine, but be sure to test your method thoroughly considering lots of different possible cases. (Use your driver program for this!)

public void printRoster()

print how many students are enrolled in the course

also print the list of each student on a single line (use good object-oriented principles to access a text representation of each student!)

print an appropriate message if there are no students yet enrolled

Part 5- Driver Program (20 points)

Write a driver program that does the following (in this order):

creates six students

creates a course that can hold five students

prints the course

prints the roster

adds the first five students to the course

tries to add the sixth student and prints a message if any add fails

prints the roster

drops the third student from the course

prints the roster

tries again to add the sixth student to the course

prints the roster
 
Posted on 07-11-15 11:57 PM     [Snapshot: 8]     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 


public class Course {
private int currentEnrollment;
private int maxNumOfStudents;
private String courseName;
private Student[] Roster;


public Course(String courseName, int maxNumOfStudents)
{
this.courseName = courseName;
this.maxNumOfStudents =maxNumOfStudents;
Roster = new Student[maxNumOfStudents];
currentEnrollment =0;

}
public int getCurrentEnrollment()
{
return currentEnrollment;
}

public String getCourseName()
{
return courseName;
}
public void setCourseName(String courseName)
{
this.courseName = courseName;
}
public int getNumOfStudents()
{
return maxNumOfStudents;
}
public void setNumOfStudents(int maxNumOfStudents)
{
this.maxNumOfStudents = maxNumOfStudents;
}

public String toString(){
String s = courseName+" ,"+maxNumOfStudents+" Student capacity";
return s;

}
public void printRoster(){
for(int student =0; student< currentEnrollment; student++){
System.out.println(Roster[student]);
}
}
public boolean addStudent(Student s){
if(currentEnrollment < maxNumOfStudents){
for( int i=0; i< maxNumOfStudents; i++){
Roster[i]= s;
System.out.println(Roster[i]);
return true;
}
}else
System.out.println(s+ "Can not be added.");
printRoster();
return false;
}
public boolean dropStudent(Student s){
Roster[2]=s;
printRoster();
return false;
}


return true;
}

return false;

}

}
 
Posted on 07-11-15 11:58 PM     [Snapshot: 11]     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

import java.util.Scanner;
public class StudentTester {

public static void main(String [] args){
Course subject =new Course("Media Studies",5);
Student[]inputArray = new Student[5];
inputArray[0]= new Student("Adam Ant","(S925)");
inputArray[1]= new Student("Bob Barker","(S713)");
inputArray[2]= new Student("Chevy Chase","(S512)");
inputArray[3]= new Student("Doris Day","(S513)");
inputArray[4]= new Student("Emilio Estevez","(S516)");
inputArray[5]= new Student("Farrah Fawcet","(S956)");

subject.printRoster();

for(int i=0; i
while(inputArray[2].equals("Chevy Chase"))
{
subject.dropStudent(inputArray[i]);
subject.printRoster();
}
}


}
}
 
Posted on 07-12-15 12:00 AM     [Snapshot: 13]     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

I am sort of self learner, but I can't find any examples for this kind of problem in book. Any help will be highly appreciated. Thank you !!
 
paani_ma_paade_jasto
Posted on 07-12-15 10:48 AM     [Snapshot: 113]     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

where do you need help? if you can tell us where you are having problem, you will definitely get some hints on how to tackle it.
 
Posted on 07-12-15 11:21 AM     [Snapshot: 128]     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

thank you!! I am trying to get help in methods.Mainly in the dropStudent method. I need to drop the third student and add the sixth student. I am glad that at least you replied :)
 
paani_ma_paade_jasto
Posted on 07-12-15 12:25 PM     [Snapshot: 148]     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

You can not just remove any element from array in java . The closest thing you can do is put some recognizable value there in that index like like 999 etc . Or you can use list if that is permissible. if you just want to drop third student and add sixth student, you can just add/put that sixth student in the index of third student, which will replace the third student.
Your dropStudent does not look good. You are passing student object, so you will need to loop through the array, find the index of that student in that array and then act on that index, probably set null so that you can identify it later.
 


Please Log in! to be able to reply! If you don't have a login, please register here.

YOU CAN ALSO



IN ORDER TO POST!




Within last 200 days
Recommended Popular Threads Controvertial Threads
डीभी परेन भने खुसि हुनु होस् ! अमेरिकामाधेरै का श्रीमती अर्कैसँग पोइला गएका छन् !
शीर्षक जे पनि हुन सक्छ।
What are your first memories of when Nepal Television Began?
Sajha Poll: नेपालका सबैभन्दा आकर्षक महिला को हुन्?
ChatSansar.com Naya Nepal Chat
NRN card pros and cons?
Basnet or Basnyat ??
निगुरो थाहा छ ??
Nas and The Bokas: Coming to a Night Club near you
TPS Re-registration
अमेरिकामा छोरा हराएको सूचना
ओच्छ्यान मुत्ने समस्या ( confession )
Do nepalese really need TPS?
TPS Re-registration case still pending ..
Drawback for applying NRN card
Breathe in. Breathe out.
nrn citizenship
Democrats are so sure Trump will win
My facebook archive (for sale)
ढ्याउ गर्दा दसैँको खसी गनाउच
Nas and The Bokas: Coming to a Night Club near you
Mr. Dipak Gyawali-ji Talk is Cheap. US sends $ 200 million to Nepal every year.
Harvard Nepali Students Association Blame Israel for hamas terrorist attacks
TPS Update : Jajarkot earthquake
NOTE: The opinions here represent the opinions of the individual posters, and not of Sajha.com. It is not possible for sajha.com to monitor all the postings, since sajha.com merely seeks to provide a cyber location for discussing ideas and concerns related to Nepal and the Nepalis. Please send an email to admin@sajha.com using a valid email address if you want any posting to be considered for deletion. Your request will be handled on a one to one basis. Sajha.com is a service please don't abuse it. - Thanks.

Sajha.com Privacy Policy

Like us in Facebook!

↑ Back to Top
free counters