package Hw3CoursePkg;
import java.util.ArrayList;
import java.util.Scanner;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Papa Smurf
*/
public class Hw3CMS {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String userSelect =null;
boolean found =true;
do{
Scanner console = new Scanner(System.in);
System.out.println();
System.out.println("Please select from the following options: \n"
+ "\n 1.Add a course "
+ "\n 2.Add a student to a course "
+ "\n 3.View available course "
+ "\n 4.Exit from system ");
int select=reader.read();
Hw3Course nc=null;
int courseNum;
String courseTitle;
int courseMaxSize;
int studentUID = 0;
String studentName = null;
double studentGPA = 0;
int courseRostorSize = 0;
String newStudent= studentUID + studentName +studentGPA;
ArrayList<Hw3Course>courseArr = new ArrayList<Hw3Course>();
console.next();
if(select==1 ){
System.out.print("Enter Course Number: ");
courseArr.add(nc);
courseNum=console.nextInt();
System.out.print("Enter Course Title: ");
courseArr.add(nc);
courseTitle=console.next();
System.out.print("Enter Course Max Size: ");
courseArr.add(nc);
courseMaxSize=console.nextInt();
if (select==2) {
for(int i =0;i<courseArr.size()&&found==false;i++){
if (courseArr.isEmpty()) {
System.out.println("There are no courses in the system ");
}else if (courseArr.size()<=1){
System.out.print("Enter course number to register for: ") ;
console.next();
} if (nc.getCourseNum()==courseNum){
System.out.print("Enter Student UID: ");
studentUID=console.nextInt();
System.out.println(" Enter Student Name: ");
studentName=console.next();
System.out.print("Enter Student GPA: ");
studentGPA=console.nextDouble();
System.out.println("The course"+ courseNum + "now has" + courseRostorSize + "students");
found=true;
}else if (nc.getCourseNum()!=courseNum){
System.out.println("Sorry, that course was not found. Try another.");
}
}
}
if(select==3){
for (int i=0;i< courseArr.size();i++){
if (courseArr.isEmpty())
System.out.println("No course to list. ");
if(courseArr.size()<=1){
System.out.println("Listing courses available in the system: /n"
+courseArr.get(i).getCourseNum()+courseArr.get(i).getCourseTitle()+ courseArr.get(i).getCourseMaxSize());
}
}
}
if(select==4){
found=false;
System.out.println("Session exited. Thanks!");
}
}
}while(found==true);
} catch (IOException e) {
} catch (NumberFormatException e) {
System.out.println("Input by user was not a number.");
}
}
}
//This is the code that is holding the package Hw3Course package*//
package Hw3CoursePkg;
import java.util.ArrayList;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Papa Smurf
*/
public class Hw3Course {
private int cNumber=0;
private String cTitle ="";
private int cMaxSize = 0;
private int id=0;
private int rostorSize= 0;
private ArrayList<String>roster=new ArrayList<String>();
private ArrayList<Hw3Course>courseArr=new ArrayList<Hw3Course>();
public Hw3Course(){
cNumber = 0;
cTitle="";
cMaxSize=0;
rostorSize=0;
}
public Hw3Course(int courseNum, String courseTitle, int courseMaxSize){
cNumber= courseNum;
cTitle= courseTitle;
cMaxSize=courseMaxSize;
}
public void setcNumber (int newcNumber) {
cNumber= newcNumber;
}
public void setcTitle (int newcMaxSize) {
cMaxSize= newcMaxSize;
}
public void setrostorSize (int newrostorSize) {
rostorSize= newrostorSize;
}
public int getCourseNum(){
return cNumber;
}
public String getCourseTitle(){
return cTitle;
}
public int getCourseMaxSize(){
return cMaxSize;
}
public int addStudent(String newStudent){
roster.add(newStudent);
return rostorSize;
}
}
Any direction on where I am wrong would be greatly appreciated. Thank you.
This post has been edited by <sch2550>: 26 March 2011 - 01:35 AM

New Topic/Question
Reply




MultiQuote






|