aspose file tools*
The moose likes Beginning Java and the fly likes Inheritance Issues Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Inheritance Issues" Watch "Inheritance Issues" New topic
Author

Inheritance Issues

Rory Scott
Greenhorn

Joined: Nov 15, 2004
Posts: 12
Greetings to everyone. To me inheritance does not seem like a beginner issue, but this is encapsulated in a introductory course. I really feel like I am asking someone to teach me Java from scratch, but some of the basic stuff I feel I dont understand. Anyone who can help I greatly appreciate.

My issue is much bigger than what I am giving you guys now, but as time progresses, I will post more on this same topic. We are writing a program that inherits many classes. It is a program about class scores on test and quizzes and such. There is are 7 classes. Student, Exam, Tests, Quizzes, Section, Meta, and the superclass of Grades. It will read a file called Metadata. The metadata file is supposed to look like this:

10 3 ;
3 3 3 3 3 3 3 3 3 3 ; 40 40 40 ;
2 2 2 2 2 2 2 2 2 2 ; 20 25 35 ;
A0262 ; 51030 ; 3 3 2 3 3 3 3 3 3 3 ; 33 37 39 ; 0.5 ;

The first line defines the 10 quizzes and 3 exams. The second line defines the max score for the grades. The third line defines the weight for the grades. The fourth line is an actual example of a student record.

I am having trouble putting this all together. Our teacher said there are 7 classes, the ones stated above, but also had us create valuetokenizers, and stringtokenizers. Im not sure where and how to implement those. Also, we must write a method to get the statistics of the class grades and store them. We must have a method like this in the student, tests, and quizzes classes. I dont think the method of calculating them one by one will be too hard. However how do I get all of them together and store them?

Here is an example from the quizzes class




//
// Class that encapsulates number of quizes
// for a student
//
public class Quizzes {
private Exam [] quizzes;
private int current=0;

public Quizzes(int maxQZs) {
quizzes = new Exam[maxQZs];
}

public void add(Exam e) {
quizzes[current++] = e;
}

public Exam get(int i) {
return quizzes[i];
}

// Define the quiz stat methods here
}




I am so confused at the moment, I hope I am providing enough information. For anyone that helps, if you could please explain for me line by line what this does and how to do the statistical method. It will help me understand what I am doing, and not just getting answers. I appreciate your assistance in advance.


Rory
Rory Scott
Greenhorn

Joined: Nov 15, 2004
Posts: 12
Additionally, attached is the Section class. Guys, I really do not understand the purpose of this class, nor what some of the things do. Please explain.



import java.util.*;
public class Section {

private String section;
private List students=new ArrayList();

public String getSection() {
return this.section;
}

public void addStudent(Student s) {
this.students.add(s);
}

public void setSection(String s) {
this.section = s;
}
}
Barry Higgins
Ranch Hand

Joined: Jun 05, 2003
Posts: 89
Right for a start have you at least got some kind of a class with a
public static void main(String[] args)
in it?

This function will be the entry point for your application. From here you can create all of the instances of the classes you need to write and call any functions needed.

As far as I can see the the next thing that would be handy to have would be something to parse those strings of yours. You say in your post that you reckon this should be straight forward GREAT but if you have any problems there is always help here.

These functions I assume will fit into Meta so in your calling class (the one with the main in it) you will say



You will obviously need you implement these methods in your Meta class. Have a go at these for a start and then post back if your having problems!
Rory Scott
Greenhorn

Joined: Nov 15, 2004
Posts: 12
Originally posted by Barry Higgins:
Right for a start have you at least got some kind of a class with a
public static void main(String[] args)
in it?

This function will be the entry point for your application. From here you can create all of the instances of the classes you need to write and call any functions needed.

As far as I can see the the next thing that would be handy to have would be something to parse those strings of yours. You say in your post that you reckon this should be straight forward GREAT but if you have any problems there is always help here.

These functions I assume will fit into Meta so in your calling class (the one with the main in it) you will say



You will obviously need you implement these methods in your Meta class. Have a go at these for a start and then post back if your having problems!


Thanks, that helped me. I actually found some notes my teacher had given that had a little bit of what you said in it. This is where I am at right now.

Rory Scott

***************************************************************************

import java.io.*;
public class Readme
{
public static void main(String[] args)throws Exception
{
if(args.length<1)
{
System.out.println("usage: java Readmeta Metadata");
System.exit(1);
}
FileReader file = new FileReader(args[0]);
BufferedReader fileline = new BufferedReader(file);
String line = null;
line = fileline.readLine();
LineTokenizer linesegment = new LineTokenizer(line);
String numbers = linesegment nextString();
ValueTokenizer value = new ValueTokenizer(line);
int Numquiz = Value.nextInt();
int Numtests = Value.nextInt();


Meta[] QuizMeta = new Meta[Numquiz];
for(int i=0; i<Numquiz; i++)
{
Quizmeta[i] = new Meta(i+1);
}

Meta[] TestMeta = new Meta[Numtests];
for(int i=0; i<Numtests; i++)
{
Testmeta[i] = new Meta(i+1);
}

line = fileline.readline();

LineTokenizer linesegment = new LineTokenizer(line);
String quizvalues = linesegment.nextstring();
String testvalues = segment.nextstring();

ValueTokenizer token = new ValueTokenizer(quizvalues);
for(int i=0; i<= Numquizzes; i++)
{
Quizmeta[i].set MaxScore(token.nextInt());
}


ValueToken value = new ValueToken(testvalues);
for(int i=0; i<Numtests; i++)
{
Testmeta[i].set MaxScore(token.nextInt());
}

line = MaxScore.readline();
String Quizweight = linesegment.nextString();
String Testweight = linesegment.nextString();

ValueTokenizer firstvalue = new ValueTokenizer (Quizweight);
for (int i = 0; i <= numquizzes; i++)
{
QuizMeta[i].setWeight(firstvalue.nextint());
}

ValueTokenizer secondtvalue = new ValueTokenizer (Testweight);
for (int i = 0; i <= numtests; i++)
{
QuizMeta[i].setWeight(secpmdvalue.nextint());
}

// while(not end of file) {
// Next read each line from the file with actual scores
// for the quizzes and tests and save it into students
// Now Read each line for Student grades etc

// using line and value tokenizer, get values of
// actuals scores of quizzes and tests

// for each value read -- create an instance
// of Exam and save it into appropriate array
// i.e. Quizzes or Tests

// Create an intstance of student class
// and set the quize and tests score
// values
// determine and print stats for each student


}
}
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
I'm not likely to read through all of your code, but I'm more than happy to help if you have specific questions. I suggest that you start with just a little bit at a time. Barry's example main() above is one place to start. Perhaps you can implement the supporting Meta class and its methods. You might find it helpful to add some System.out.println() (SOP) calls to make sure things work the way you expect.

Whether you start with Barry's example or somewhere else, the main idea is to work on the program in pieces: implement some code, get it to compile, test it to see if it runs correctly, fix any problems you encounter along the way. Some sequence of steps like this should help you to organize your work. So do you think your code is to a point where it will compile and run? If so, does it actually compile? If not, can you identify some small portion of the program that you can get to compile so you can run it? If you try to compile it, but there are compiler errors, what are the errors (word for word)? If it compiles, what happens when you run it?

Typically, I like to see answers to these kinds of questions. Any details you can give about what you have tried and what problems you encountered along the way will greatly help when it comes to answering your questions. Hopefully this also helps you think of things you can do to keep working on this project.

It's great to see you working at this. Please come back with more questions as you encounter problems.

Keep Coding! (TM)

Layne

p.s. When you post code snippets, it will be helpful if you use UBB CODE tags. There are buttons just below the area where you enter your message to help with this.
[ December 09, 2004: Message edited by: Layne Lund ]

Java API Documentation
The Java Tutorial
Rory Scott
Greenhorn

Joined: Nov 15, 2004
Posts: 12
Originally posted by Layne Lund:
I'm not likely to read through all of your code, but I'm more than happy to help if you have specific questions. I suggest that you start with just a little bit at a time. Barry's example main() above is one place to start. Perhaps you can implement the supporting Meta class and its methods. You might find it helpful to add some System.out.println() (SOP) calls to make sure things work the way you expect.[QB]





I know that is a lot of code, but I figured everyone might have a better understanding if I attached the files. I have my main method, but I do not understand what I have to print out. I realize that I must store the information and calculate some things, but I dont know what those particular things are called to print. This is where my biggest issue is.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Inheritance Issues