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

More Major Inheritance Stuff.

Rory Scott
Greenhorn

Joined: Nov 15, 2004
Posts: 12
Greetings to everyone. I am pasting most of the same letter I had last time because I am having the same issues. I am on a time frame if you guys can help.

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 believe my main class is no longer grades, but Readmeta. I have majority of the class typed, but It does not seem to work. Now my task is to read in the MetaData file and print out the numbers. My teachers instructions for that section are as follows.

// 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


I can not completely understand what she means on this, and in now way shape or form understand what I need to do to read in this file. If you could help me it would be much appreciated.


Rory Scott



import java.io.*;
public class Readmeta
{
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());
}
}
}
Rory Scott
Greenhorn

Joined: Nov 15, 2004
Posts: 12
The rest of the classes to be inherited. I believe all of them are correct, it is just my main class that needs help.



//
// This class define an exam may that be Quiz or Test
//
public class Exam {
private int score; // actual score for the test
private Meta meta; // meta info about the test

public void setScore(int sc) {

//
// should validate against maxScore and throw
// an exception if out of range
//
this.score = sc;
}

public void setMeta(Meta m) {
this.meta = m;

}

public int getScore() {
return this.score;
}

public Meta getMeta() {
return this.meta;
}

public int getWeightedScore() {
return this.meta.getWeight()*this.getScore();
}
}

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

import java.util.StringTokenizer;
public class LineTokenizer
{
StringTokenizer Token = null;
public LineTokenizer(String words)
{
Token = new StringTokenizer(words, ";");
}
public String nextString()
{
return Token.nextToken();
}
}

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

// This class defines the fixed meta information
// about each exams i.e quiz, test etc
//
// This information is same for a exam for each student
// i.e quiz 1 has the same weight and max score for each
// student
//
public class Meta {
//list of methods to be called
private int examNumber; // number of the exam i.e. 2 for second quiz
private int weight; // weight of this exam
private int maxScore; // maxScore for this exam

public Meta(int exNum) {
setExamNumber(exNum);
}
// getter/setter for various attributes
//calling methods listed above
public int getExamNumber() {
return this.examNumber;
}

public void setExamNumber(int eNum) {
this.examNumber = eNum;
}

public int getWeight() {
return this.weight;
}

public void setWeight(int wt) {
this.weight = wt;
}

public int getMaxScore() {
return this.maxScore;

}

public void setMaxScore(int ms) {
this.maxScore = ms;
}
}
***************************************************************************

//
// 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
}
***************************************************************************
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;
}
}

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


public class Student {
private String id;
private Quizzes quizzes;
private Tests tests;

public void setId(String v) {
this.id = v;
}

public void setQuizzes(Quizzes q) {
this.quizzes = q;

}

public void setTests(Tests t) {
this.tests = t;

}

public String getId() {
return this.id;
}

public Quizzes getQuizzes() {
return this.quizzes;
}

public Tests getTests() {
return this.tests;
}
//Add method for student stats

}
***************************************************************************

// class that encapsulates the tests for a student
//
public class Tests {
private Exam [] tests;
private int current=0;
public Tests(int maxTsts) {
tests = new Exam[maxTsts];
}

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

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

// define test stat method
}
***************************************************************************
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
Please keep this discussion in the other thread. It will help keep the coherence in case anyone else wants to join in.

Also, just to clarify, it doesn't look like this program uses inheritence at all, or at least in only limited areas. When you get a chance, you should probably research what inheritence is all about. The main reason I make this claim is that inheritence uses the "extends" keyword, which I don't see in your program. In fact, from your description, it doesn't look like inheritence is appropriate, so you aren't necessarily missing anything here.

Regards,

Layne


Java API Documentation
The Java Tutorial
Rory Scott
Greenhorn

Joined: Nov 15, 2004
Posts: 12
Originally posted by Layne Lund:
Please keep this discussion in the other thread. It will help keep the coherence in case anyone else wants to join in.

Also, just to clarify, it doesn't look like this program uses inheritence at all, or at least in only limited areas. When you get a chance, you should probably research what inheritence is all about. The main reason I make this claim is that inheritence uses the "extends" keyword, which I don't see in your program. In fact, from your description, it doesn't look like inheritence is appropriate, so you aren't necessarily missing anything here.

Regards,

Layne



Yes I know there is no inheritance in this code. The challenge our teacher has proposed to us is to integrate inheritance in this project. I have attached the other classes to be used. They were given to us verbatim by the teacher, so I know they are correct. The main class is what has problems. I partially understand inheritance, but not the concept of how I will inherit these classes, and how they will read in the information, store it, and be able to calculate with them.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: More Major Inheritance Stuff.