Results 21 to 26 of 26
- 05-08-2011, 11:19 PM #21
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
I don't believe this is what your teacher wanted. Something like this will work better.
The constructor should initialize the items, and display grades should print it.Java Code:public static void main(String[] args){ Grade g = new Grade(); g.displayGrades(); }
- 05-09-2011, 12:24 AM #22
Member
- Join Date
- May 2011
- Posts
- 1
- Rep Power
- 0
import java.io.*;
import java.awt.*;
import java.lang.*;
import java.io.IOException;
public class Grade {
private int gradeNumber;
private static char[] letterGrade={'A','B','C','D','E','F'};
public static void main(String[] args) throws IOException {
//[] stgrde = new Grade();
for(int i=0;i<letterGrade.length; i++){
System.out.println(letterGrade[i]);
}
}}
- 05-09-2011, 12:43 AM #23
Member
- Join Date
- May 2011
- Posts
- 46
- Rep Power
- 0
I have a new question to the same code...if i can? I have a main class and 2 children classes. I have the main class Grade pretty much done. I am working on Class Raise now. I need to call the constructor Raise() from the static void main in Grade, how would I do that so it will calcs and print? Heres the code I have:
public class Grade {
private int gradeNumber;
private char[] letterGrade={'A','B','C','D','E','F'};
private String[] percent={"90-100","80-89","70-79","60-69","50-59","0-49"};
char Bill='C';
char Susan='B';
int Billnumber=75;
int Susannumber=85;
public Grade(){
System.out.println("The Baker College Grade Standard is: ");
for(int i=0;i<6; i++){
System.out.println(letterGrade[i]+" "+ percent[i]);
}
System.out.println("Bills current Grade is: " + Bill);
System.out.println("Susans current grade is: " + Susan);
}
public static void main(String args[]) throws IOException {
new Grade(); //Calling Grade to print
// need to call Raise() here!
}
public class Raise { // raise grade by 10 points
public Raise(){
Grade Billnew = new Grade();
int Billsnewnumber= Bill +10;
switch (Billsnewnumber) {
case 'A':
if(Billsnewnumber >90){
Bill = 'A';
}
break;
case 'B':
if(Billsnewnumber <90){
if(Billsnewnumber >79){
Bill = 'B';
}
}
break;
case 'C':
if(Billsnewnumber <80){
if(Billsnewnumber >69){
Bill = 'C';
}
}
break;
case 'D':
if(Billsnewnumber <70){
if(Billsnewnumber >59){
Bill = 'D';
}
}
break;
case 'F':
if(Billsnewnumber <60){
Bill = 'F';
}
break;
}
System.out.println("Bills new Grade is: " +Bill + " and his grade point is: " + Billsnewnumber);
System.out.println("Bill got a B on his Midterm!); }}
class Lower extends Raise{ //lower grade by 15 points
}
}
- 05-09-2011, 01:52 AM #24
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
There is quite a bit wrong with your code. Good code will seem organized, bad code becomes sloppy like you have. I understand you are new, so I don't mean this to be rude. You need to find a way to organize the code better to have a nicer program. That being said, I will attempt to help you out.
You shouldn't be just dumping all your variables you want to use in the instance variable section of a class. Would you mind showing your assignment details?
I am assuming the grade class should be able to convert a number grade into a letter grade. Generally, a class should do one specific task, not 50. So you could have your grade class take a number and give you the correct grade. Then use a student class to encapsulate the "essence" of a student(name, grade, etc).
I don't really think you quite understand oo techniques, which is fine if you are new. The constructor shouldn't really be the work horse of your program, it should be responsible for initializing a concrete instance of the class, then you use methods to perform operations on that instance.
Also, please use code tags.
[code]
YOUR CODE HERE
[/code]
- 05-09-2011, 02:03 AM #25
Member
- Join Date
- May 2011
- Posts
- 46
- Rep Power
- 0
Assignment:
Write a Java program that does the following:
1.Creates a grading program based on the Baker College grading standard. You will need to look up the current grade standard. You may use only the letter grades without the +/- signs.
A = 93-100 etc.
2. Uses a char array to hold the letter grades.
3. Creates a Grade class with private grade attributes and two class methods to manipulate grades. One method will raise their grade point total by 10 points and one method will lower their grade by 15 points. Create 2 instances, ‘Bill’ and ‘Susan’ of the grade class.
4. Creates appropriate display methods for the Grade class.
5. Your program will first print out the Baker grade standard and Bill and Susan’s current letter grade (your choice). The program will then call the methods that will increase and decrease both bill and susan’s point grades and then print their corresponding letter grades. Please notify me in your output, that is, you may want to say: “Bill failed his math final and his final grade dropped to x-points and a letter grade of C.”
6. You must use a Switch construct.
Your output should be as follows:
A. Print the entire Baker College grade standard
B. Bill and Susan’s current grade point total and equivalent letter grades
C. Bill and Susan’s current grade point total and equivalent letter grades after raising the grade by 10 points.
D. Bill and Susan’s current grade point total and equivalent letter grades after lowering the grade by 15 points.
As you can see, the children have to manipulate the grades. So, I am going to do my work there...is what I'm thinking. I'm online only with really awful books. I am learning this on my own...essentially.
- 05-09-2011, 02:16 AM #26
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
Alright, the thing that changes the grade is not another class. It's a method in the Grade class.
You should have two static variables(which are class variables). It doesn't make sense for each instance to have it's unique grading scheme, this is something that should be shared amongst the school. So you want static arrays to hold the letter and number grades.
Then you want instance variables for a students grade, these are unique to the student(each instance will have it's own grades). They could be things like, mathGrade, finalGrade, midtermGrade, etc.
The next thing you want to add is the methods for the class, one to raise the grade, one to lower it, these are inside the grade class and take the following form
Fill the bodies of these methods with the necessary statements to raise or lower a students grade.Java Code:public class Grade{ //other stuff public void raiseGrade() public void lowerGrade() }
Next you want to create a method that will print out the information. For instance, you may have one method which prints the grade scheme, and then a method that prints the individual students grades.
The switch statement should be used to calculate the letter grade. The main method should look something like this
Java Code:public static void main(String[] args){ Grade john = new Grade(/*args to constructor*/); Grade sally = new Grade(/*args to constructor*/); john.calculateFinal(); sally.calculateFinal(); //you don't necessarily need these two calls Grade.displayGradeScheme(); //static method to display the grade scheme System.out.println(john); //this calls the toString methods you will need to System.out.println(sally); //supply and it prints the student info, alternatively //you can do something like this instead john.printGrades(); sally.printGrades(); john.raiseGrade(); john.printGrades(); //or the sysout version sally.printGrades(); john.lowerGrade(); sally.lowerGrade(); john.printGrades(); sally.printGrades(); }
Similar Threads
-
convert byte array into char array
By kgkamaraj in forum New To JavaReplies: 4Last Post: 09-13-2011, 11:32 AM -
searching char array with another char array for full word matches
By karunabdc in forum New To JavaReplies: 2Last Post: 03-08-2011, 06:20 AM -
Is it better to set array elements to null before setting the arrayreference to null?
By kreyszig in forum Advanced JavaReplies: 6Last Post: 10-18-2010, 10:40 AM -
create a 2d char array from a 1D string array
By jschmall12 in forum New To JavaReplies: 1Last Post: 04-27-2010, 09:01 PM -
Program can run but output all null
By matt_well in forum New To JavaReplies: 15Last Post: 07-24-2008, 08:48 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks