Rory Scott

Greenhorn
+ Follow
since Nov 15, 2004
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Rory Scott

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.

20 years ago

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.
20 years ago

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


}
}
20 years ago
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
}
***************************************************************************
20 years ago
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());
}
}
}
20 years ago
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;
}
}
20 years ago
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
20 years ago
I just want to thank everyone for all of their speedy help. My program seems to be working fine, and I have a better understanding of what I am doing. (Still got a lot of work to do though). For any future reference, I have posted my final code.



Rory





//Class declaration
class Vowel
{
//main method
public static void main(String[] args)throws Exception
{
//Declaring variables and array
int counter=0;
int length;
char letter;
String[] name = {"Rory", "Ana", "Carla", "Mom", "Dad"};
sortString(name);
//This loop helps to count the vowels and compare them throughout the strings
for(int i=0; i<5;i++)
{
length = name[i].length();
for(int j=0; j<length;j++)
{
letter=name[i].charAt(j);
if(letter=='a'||letter=='e'||letter=='i'||letter=='o'||letter=='u'||letter=='A'||letter=='E'||letter=='I'||letter=='O'||letter=='U')counter++;
}
//The print statement is in the loop so it can print for each string in the array, the total amount of Vowels thus far
System.out.println(+counter+" vowels were total have been counted.");
}
}
//This method is specifically for sorting.
public static void sortString(String[] name)
{
for(int i=0;i<name.length;i++)

for(int j=i+1;j<name.length;j++)
{
if(name[i].compareTo(name[j])>0)
{
String temp = name[i];
name[i] = name[j];
name[j]=temp;
}
}
for(int i=0; i<name.length;i++)
System.out.print(name[i]+" ");
}
}
20 years ago
Oops, forgot the code



class Vowel
{
public static void main(String[] args)throws Exception
{
int counter=0;
int length;
char letter;
String[] name = {"Rory", "Ana", "Carla", "Mom", "Dad"};
sortString(name);
for(int i=0; i<5;i++)
{
length = name[i].length();
for(int j=0; j<length;j++)
{
letter=name[i].charAt(j);
if(letter=='a'|| letter=='e'||letter== 'i'||letter== 'o'||letter=='u'||letter=='A'||letter=='E'||letter=='I'||letter=='O'||letter=='U')
counter++;
}
System.out.println("There were "+counter+" vowels.");
}
}
public static void sortString(String[] args)
{
length = 4;
for(int i=0;i<length;i++)
{
if(name[i].compareTo(name[i+1])>0)
{
char temp = name[i];
name[i] = name[i +1];
name[i+1]=temp;
}
}
for(int i=0; i<5;i++)
System.out.print(name[i]+" ");
}
}
20 years ago

Originally posted by Ernest Friedman-Hill:
[QB]

As far as the string sorting goes, your routine is a good start, but it actually only puts the first element into the right place; you need two nested loops, one varying the "left hand" index, and the other the "right hand" index, to sort the whole array. Think about that for a bit and let's see what you can come up with.

The argument list of sortString() is a little wrong. The "char temp" declaration belongs inside the routine, and the String[] parameter (which you call "name" inside the routine) needs to be named in the parameter list.
QB]



I feel I have conquered most of these concepts. Thank you again for your help. But how do I fix my "char temp" declaration in the second method? I have attached my revisions, but am not sure what else I need in the begining of the second method. I know it is lacking, but I dont know what.

Also could you further explain your definition of the sort, and how I should fix it. I do not think I am quite comprehending.

Rory
20 years ago

Originally posted by Ernest Friedman-Hill:
Hi Rory,

Welcome to JavaRanch!

Hmm. This is rather a lot to pack into one assignment.

First, the vowel-counting looks mostly OK to me, if the point is to count all the vowels in all the words; otherwise, it needs a bit of rearranging. In particular, the println() call would move inside the outer loop.

You don't need to construct a StringBuffer to get the length of a String; String has its own perfectly good length() method you can call directly.

That long and scary conditional with all the comparisons-to-vowels could be made shorter in several ways, but none of them are too beginnerish so I'd leave well enough alone.

As far as the string sorting goes, your routine is a good start, but it actually only puts the first element into the right place; you need two nested loops, one varying the "left hand" index, and the other the "right hand" index, to sort the whole array. Think about that for a bit and let's see what you can come up with.

The argument list of sortString() is a little wrong. The "char temp" declaration belongs inside the routine, and the String[] parameter (which you call "name" inside the routine) needs to be named in the parameter list.

Finally, of course, something in main() probably ought to call sortString(), or it won't actually run.







Thank you very much for your reply. It is much appreciated. However, I am confused on some things. First of all, how do I call a method? My book tells me how to call from another class, but that is not what I need. Also, if I cut the string buffer, would I also cut the lines proceeding it until my loop starts? I think that is all of my questions. Again thank you for your help.

Rory
20 years ago
Greetings to all. This is my first time using this forum, and it is kind of an emergency, so I hope for quick responses. I believe this is a beginner problem.

I am enrolled in an Introductory Java Programming class, and seem to be having issues grasping some of the concepts. Our teacher recently gave us an assignment of making a program that contains an array of names. It must count and display number of vowels in the string (name). It also must display in alphabetical order the names. The name sort is to be in a seperate method. I think I have it thus for, but it seems not to be working. Could someone help me work the kinks out?


Rory Scott




[ EJFH -- Added CODE tags to preserve formatting. ]
[ November 15, 2004: Message edited by: Ernest Friedman-Hill ]
20 years ago