Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 14 of 14

Thread: Can you help me ?

  1. #1
    Member
    Join Date
    Mar 2013
    Posts
    68
    My Mood
    Angelic
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Can you help me ?

    1. Develop a simple grade transcript program. We will have two classes, a Course class representing an individual course that a student has taken and a Transcript class that will combine several Course objects and calculate an overall grade point average (GPA). We will also have two test classes, one for the Course class and one for the Transcript class.

    2. Design and build a Course class. This will have three instance variables. There will be a courseID variable that will hold the course identification number. We will use the standard State of Florida numbering system (this course is "COP 2253"). We will have a letterGrade variable that will hold the assigned course grade. We will also have a numberGrade variable that will hold a numeric equivalent to the letterGrade. The class should have a constructor, accessors for the instance variables, a method to compute the numeric grade, a method to update the grade, and a method to convert the state of the object to a string. Using the UML, the class diagram looks like this:

    Course


    - courseID : String
    - letterGrade : String
    - numberGrade : double


    + Course( String, String )
    + getCourseID( ) : String
    + getLetterGrade( ) : String
    + getNumericGrade( ) : double
    - computeGrade()
    + updateGrade( String )
    + toString( ) : String
    a. The constructor will assign the first parameter to the variable courseID and the second parameter to the variable letterGrade. The constructor will then call the method computeGrade() to convert the letter grade to a numeric equivalent and store it in the variable numberGrade.
    b. The class will have three accessor methods getCourseID(), getLetterGrade(), and getNumericGrade() that will return the value of each respective instance variable.
    c. The method computeGrade() handles the conversion of the letter grade to a numeric equivalent and saves it in the instance variable numberGrade. The letter grades will range from "A" to "F". The letter grades have numeric values ranging from 4.0 for an "A" to 0.0 for an "F". We may also have a "+" or a "-" after some letter grades. The "+" can be appended to B's, C's, and D's and increases the value of the letter grade by 0.3 points. A "-" appended to A's, B's, and C's decreases the value of the letter grade by 0.3 points. There are no "A+", 'D-", "F+" or "F-" grades. Use the switch statement to determine which of the set of letter grades we have. Use the if { ... } else { ... } construction to handle the modification of the basic numeric grade with the "+" and "-' modifiers. There will be 11 possible valid grades.
    d. The class will have a method updateGrade(String) that takes a new letter grade value as a String parameter, and updates the letterGrade and numberGrade variables accordingly. NumberGrade can be updated by calling the computeGrade () method as done in the constructor. Note that we can call methods of a class from within the class; in this case, we do not use the dot (.) operator. Methods which are useful to other methods are called utility methods, and do not need to be public if they will only be called from within the class. In this case, computeGrade() is a utility method.
    e. The method toString() allows us to access the state of the object in a printable or readable form. It converts the variables to a single string that is neatly formatted. Look at pages 23 and 24 of the text for a discussion of escape sequences. These are characters that you can insert into your strings and, when printed, will format the display neatly. You can insert an escape sequence for the tab character and get a tabular form when printing. This tab character is '\t'. Your class will have a toString() method that concatenates courseID, letterGrade, and numberGrade separated by tab characters and returns this new string. When you try to print an object, the toString() method will be implicitly called, which in this case, will print a string that will look something like:

    COP 2253 A- 3.7

    3. Build a Transcript class that will store information about the courses taken (Course Objects) by one specific student. It should include a studentID and studentName. It should also include an ArrayList (You must use an ArrayList, not an array) to hold information about each course (course object) that the student has completed.
    4. Build a TranscriptTest class to test your application. Your test class should not require any interaction with the user. It should verify the correct operation of the constructor and all methods in the Transcript class.
    Specific Requirements for the Transcript Class
    1. The transcript class should have a constructor with two parameters. The first is an integer containing the student's ID and the second is a String containing the student's name.
    2. There should be a method to allow the addition of a course to the transcript. The two parameters for the addCourse method will be (1) the courseID and (2) the letterGrade.
    3. There should be a method to allow the updating of a course already in the transcript. Notice that updating a course means changing the letter grade. The parameters for the updateCourse method are also (1) the courseID and (2) the letterGrade. Notice that the updating of a specific course requires a search through the ArrayList to find the desired course. Anytime a search is done, the possibility exists that the search will be unsuccessful. It is often difficult to decide what action should be taken when such an "exception" occurs. Since exception handling is not covered until later in this textbook, we will make some arbitrary decisions for this project. If the course to be updated is not found, you will take the simplest action possible and do nothing. Do not print an error message to the screen. Simply leave the transcript unchanged.
    4. The transcript class needs a method called getGPA to return the student's GPA. You should implement a method called calculateGPA that will go through the array of courses and make the appropriate calculation. The calculateGPA method should never be called from outside the class, so it should be made private. Recall that the Course class maintains a numeric grade indicating GPA points.
    5. There should also be a method to return information about a specific course. It should return a single String object in the same format described for the Course class:

    COP 2253 A- 3.7

    Again, the possibility exists that the search for a specific class will fail. In this instance, you should return a string containing a message similar to this:

    COP 2253 not found.

    6. The final method needed is a toString method. It should return the transcript information in a single String object. It should use the following format:

    ID : 12345
    Name : John Doe
    GPA : 4.0
    COP 2253 A 4.0
    COP 3022 A 4.0
    COP 3530 A 4.0

    Notice that a newline character '\n' can be inserted into the middle of a string.

    Ex.

    int age = 30;
    String temp = "John Doe \n is " + age + "\n" + " years old";

    The output would be:

    John Doe
    is 30
    years old

    Notice also that the '\n' is a single character and could actually go inside single or double quotes, depending on the circumstances.
    Here is a UML diagram for the Transcript class as describe above. Notice that you may add private instance variables and methods as needed. For all public methods use exactly the name given below. Remember that calculateGPA should be private.


    Transcript


    - courses : ArrayList<Course>
    - studentID : int
    - studentName : String


    + Transcript( int, String )
    + addCourse( String, String )
    + updateCourse( String, String )
    - calculateGPA( )
    + getGPA( ) : double
    + getCourse( ) : String
    + toString( ) : String

    Already tried:
    public class Course 
    {
    	//Instance variable
    	public String courseID;
    	public String letterGrade;
    	public double numberGrade;
     
    	/*
    	@Constructors
    	*/
    	public Course(String courseID, String letterGrade) 
    	{
    		courseID = courseID;
    		letterGrade = letterGrade;
    		computeGrade();
    	}
     
    	public String getCourseID() 
    	{
    		return courseID;
    	}
    	public String getLetterGrade() 
    	{
    		return letterGrade;
    	}
    	public double getNumericGrade() 
    	{
    		return numberGrade;
    	}
     
    	public void computeGrade()
    	{		
    		switch(letterGrade)
    		{
    			case "A": numberGrade = 0.4;break;
    			case "B": numberGrade = 0.3;break;
    			case "C": numberGrade = 0.2;break;
    			case "D": numberGrade = 0.1;break;
    			case "F": numberGrade = 0.0;break;
    			default: numberGrade = 0; break;
    			}
    }
    	public void updateGrade(String letterGrade) 
    	{
    		LetterGrade(letterGrade);
    Last edited by Norm; April 25th, 2013 at 04:54 PM. Reason: Removed spaces in code tag

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Can you help me ?

    What are your questions?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Member
    Join Date
    Mar 2013
    Posts
    68
    My Mood
    Angelic
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Can you help me ?

    My question is how can i update letterGrade and numberGrade as desricbe in instruction letter C above

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Can you help me ?

    how can i update letterGrade and numberGrade
    What problems are you having understanding the problem? Describe what data the program has and what the code needs to do with that data to get the values you want?
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Member
    Join Date
    Mar 2013
    Posts
    68
    My Mood
    Angelic
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Can you help me ?

    How do you use if { ... } else { ... } construction for handle the "+" and "-" modifiers?The "+" can be appended to B's, C's, and D's and increases the value of the letter grade by 0.3 points. A "-" appended to A's, B's, and C's decreases the value of the letter grade by 0.3 points

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Can you help me ?

    handle the "+" and "-" modifiers?
    If you have a String with a "+" or "-" in it you will need to use some of the String classes methods to find it.
    Look at the API doc for the String class for methods that will
    give you the characters in the String
    or to search a String for a character or String
    or to get sub strings of the given String.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Member
    Join Date
    Mar 2013
    Posts
    68
    My Mood
    Angelic
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Can you help me ?

    ok.do you know where can I find that infrmation?

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Can you help me ?

    The API doc: Java Platform SE 7
    Find the class in the lower left, click on the link and the doc will show in the main frame.
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Member
    Join Date
    Mar 2013
    Posts
    68
    My Mood
    Angelic
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Can you help me ?

    public void computeGrade()
    	{	
    		int size = letterGrade.length();
    		switch(letterGrade.substring(0,1))		
    		{
    			case "A": numberGrade = 0.4;break;
    			case "B": numberGrade = 0.3;break;
    			case "C": numberGrade = 0.2;break;
    			case "D": numberGrade = 0.1;break;
    			case "F": numberGrade = 0.0;break;
    			default: numberGrade = 0; break;
    		}
     
    		if(size == 1)
    		{
    			numberGrade = numberGrade + 0.3;
    		}
    		else if(size == 2)
    		{
    			numberGrade = numberGrade - 0.3;
    		}
    	}
    Last edited by Norm; April 25th, 2013 at 06:54 PM. Reason: Removed spaces from code tag

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Can you help me ?

    Did you have any questions about the code?
    If you don't understand my answer, don't ignore it, ask a question.

  11. #11
    Member
    Join Date
    Mar 2013
    Posts
    68
    My Mood
    Angelic
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Can you help me ?

    Is this code right for method computeGrade() handles the conversion of the letter grade to a numeric equivalent and saves it in the instance variable numberGrade?

  12. #12
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Can you help me ?

    Is this code right
    What happens when you compile and execute it?

    How does the length of the String with the letter grade change the number grade?
    Can you post some examples?


    Many methods like this one take an argument and return a value instead of using class variables.
    See the tutorial:
    Defining Methods (The Java™ Tutorials > Learning the Java Language > Classes and Objects)
    Passing Information to a Method or a Constructor (The Java™ Tutorials > Learning the Java Language > Classes and Objects)
    Returning a Value from a Method (The Java™ Tutorials > Learning the Java Language > Classes and Objects)
    If you don't understand my answer, don't ignore it, ask a question.

  13. #13
    Member
    Join Date
    Mar 2013
    Posts
    68
    My Mood
    Angelic
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Can you help me ?

    It didn't give me an error.

  14. #14
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Can you help me ?

    Did it compute the correct results?


    How does the length of the String with the letter grade change the number grade?
    Can you post some examples?
    If you don't understand my answer, don't ignore it, ask a question.