Roger Sanchez

Greenhorn
+ Follow
since Jun 23, 2003
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Roger Sanchez

This is a sample exam question that I struggling with:
Write a boolean method named digit that returns true if the value of its char type parameter is a digit (one of "0", "1", ., "9") and returns false otherwise.
Thanks,
Roger
20 years ago
Another sample exam question I need help with:
If variable s have declared by the statement String s = new String ("Hello World"); then what is the value of the expression s.substring(0,4)+s.charAt(5)+Character.toUpperCase(s.charAt(4))+s.substring(5)

Thanks,
Roger
20 years ago
I am studying for a exam and am trying to work through this sample question (in case it actually shows up on the real thing). Can anyone help?
Thanks,
Roger

The Quadratic applet--see the sketch of the opening screen below--solves equations in the form a * x * x + b * x + c = 0.0 where the numbers (called coefficients) a, b, and c are supplied by the user--in thethree editable text fields (instances of class TextField in Version2, and of class JTextField in Version 3) of the top row of the applet.

Whenever the user clicks on the SOLVE button, the applet responds by displaying a message in the TextField in the second row of the applet. The message is one of four possible types:
"Not all three coefficients are valid" This string is displayed if Java cannot convert the contents of one or more text fields in the top row into a double type number. HINT: Use Double.parseDouble(s) to convert a String s into primitive double type--this call will throw a NumberFormatException if s does not represent a valid double value.
"There is no (real) solution to this problem"
This string is displayed if b*b-4*a*c is negative. HINT: Given a quadratic equation a*x*x+b*x+c=0, define its "discriminant" d as d=b*b-4*a*c. The equation has two solutions--if any at all--and these are given by the formulas
x1 = ( -b + Math.sqrt(d) ) / ( 2 * a )
x2 = ( -b - Math.sqrt(d) ) / ( 2 * a )
A negative number, however, does not have a (real) square root, so if d is negative, then the equation does not have a (real) solution at all.
X = " + x1 + " or X = " + x2
This String expression is displayed if d is positive. (d, x1, and x2 are defined in 2) > above.

" X = " + x1
This String expression is displayed when d is zero. (According to the formulas in 2) above, d=0 implies that x1=x2=(-b)/(2*a), that is, solutions x1 and x2 are one and the same, so we have a single solution.) Based on the information above and the code below, complete the code of the Quadratic applet. In particular, write the code missing from the body of the actionPerformed method.
[ edited to preserve formatting using the [code] and [/code] UBB tags -ds ]
[ July 25, 2003: Message edited by: Dirk Schreckmann ]
20 years ago
Thanks for the quick reply. So, to check my understanding, both statements are false?
20 years ago
I forgot to put the variable values:
x = false, y = true, z = false
( ( x || ! ( y && z ) ) && ! ( y || z) )

x = false, y = true, z = false
( ( ! x && ( y || z ) ) || ( ! y || z))
Thanks again
20 years ago
A couple of other questions in preparation for an exam:
( ( x || ! ( y && z ) ) && ! ( y || z) )

( ( ! x && ( y || z ) ) || ( ! y || z))

Thanks again,
Roger
20 years ago
I am trying to solve the following problem in preparation for an exam I'm taking. Here it is:
"Suppose that a self-organizing vector has 7 elements , ABCDEFG initially in this order (A is the front element), and suppose that the vector is organized by the move-to-front reordering algorithm. Determine the order of elements after the lookup sequence GGDED."
Any help would be great.
Thanks,
Roger
20 years ago
Understood. Thanks again for all your help! I will take another stab at it.
Take care,
RS
20 years ago
Thanks so much, Siu! The program compiled without errors and displayed the required data (some of the "marks" field need to calculate the number of courses the student has completed and average grades, though).
Also, I would still appreciate some help with the "->" and "<-" JButtons to scroll throught the student records and display them in the appropriate JTextFields. Can you also help with this?
You've been incredibly helpful!

Here are the complete .txt files below.
"students.txt":
0000000
Bach
Sebastian
2222 22 Avenue
Edmonton
AB
T2T 2T2
780-222-2222
bachs@telusplanet.net
1111111
Tchaikovsky
Pyotr Ilyich
3333 33 Street
Vancouver
BC
V3V 3V3
604-333-3333
chaiko@connect.bc.ca
2222222
Strauss
Johann
4444 Vienna Crescent, North West
Saskatoon
SASK
S4S 4S4
306-444-4444
jstrauss@frisky.net
3333333
Handel
George Frideric
Appartment 1685 1759 Hamburg Plaza
Winnipeg
MA
W5W 5W5
314-555-5555
concerto@allegro.com
4444444
Vivaldi
Antonio
1678 66 Avenue
Venez
ON
Z6Z 6Z6
416-666-6666
vivaldi@grosso.padrona.net
5555555
Mozart
Wolfgang A.
1756 Bavarian Boulevard
Salzburg
ON
S0S 0S0
416-555-5555
magic@cs.flute.ca
6666666
Haydn
Franz
#66 Eszterhaza Place
Mississauga
ON
M6M 6M6
416-666-6666
neusiedler@primrose.net
7777777
Beethoven
Ludwig, Van
777 Longandwinding Road
Fort McMurray
AB
T7T 7T7
780-777-7777
ludwig@tihuana.brass.net
8888888
Mahler
Gustav
1860 Piazza del Torro 11
Madrid
Spain
MS 6611
66-123-888-888
gustavm@europa.esp
9999999
Dvorak
Antonin
9999 Romantic Avenue
Montreal
QU
Q9Q 9Q9
816-999-999
anton@orchestra.net
"courses.txt":
COMP 111
Relativity in Computing
Alfred Einstein
COMP 222
Computers and Uncertainties
Bradley Heisenberg
COMP 333
Robotics
Chester Von Neumann
COMP 444
Sanity in a Digital World
Douglas Freud
COMP 555
Management Systems
Elmer Socrates
COMP 666
Systems Management
Florence Damocles
"marks.txt":
0000000
COMP 111
71
1111111
COMP 111
100
1111111
COMP 222
100
2222222
COMP 111
69
2222222
COMP 222
74
2222222
COMP 555
84
3333333
COMP 111
67
3333333
COMP 222
72
3333333
COMP 444
77
3333333
COMP 666
87
5555555
COMP 111
65
5555555
COMP 222
70
5555555
COMP 444
75
5555555
COMP 555
80
5555555
COMP 666
85
6666666
COMP 111
63
6666666
COMP 222
68
6666666
COMP 444
73
7777777
COMP 111
61
7777777
COMP 222
66
7777777
COMP 444
71
7777777
COMP 555
76
8888888
COMP 111
59
8888888
COMP 222
64
8888888
COMP 444
69
9999999
COMP 111
57
9999999
COMP 222
62
9999999
COMP 444
67
9999999
COMP 555
72
9999999
COMP 666
83
20 years ago
I'll wait for your reply. Thanks for much for your help.
20 years ago
To clarify your response, the first record in "students.txt" should be displayed in jtfStudentID. When the "->" JButton is clicked , the second record in "students.txt" should be displayed in the jtfStudentID. When the "->" JButton clicked again, the third record should be displayed in jtfStudentID; and so on. After the final record is displayed in jtfStudentID, the first record should be displayed in jtfStudentID. I also need the reverse functionality in the "<-" JButton - to be able to scroll through the "students.txt" lines in reverse order. Below is the content of the "students.txt" file:
0000000
1111111
2222222
3333333
4444444
5555555
6666666
7777777
8888888
9999999

The error messages received when trying to compile the applet are:
TME4.java:106: cannot resolve symbol
symbol: variable line
location: class TME4
if (line == null)
TME4.java:106: cannot resolve symbol
symbol: variable line
location: class TME4
jtf.setText(line + '\n')
I hope you can help.
Thanks
20 years ago
I have simplified my code to one textfield and three JButtons. It nows reads as follows:

I am trying to populate the textfield with the first StudentID record from the students.txt text file when the STUDENTS JButton is clicked. When the -> JButton is clicked, the second record (or line) should be displayed in the textfield. When I attempt to compile the code above, I receive two errors: one on line 106 and one of line 108. Please provide a recommendation on how to proceed.
Thanks
20 years ago
You've been really helpful, Jim. However, I'm still having difficulty implementing the code that you provided. Basically, I have three text files that I need to import information from and populate textfields with (students.txt, courses,txt and marks.txt). I also need to scroll through records the various records using forward and back JButtons. It feels as though I've tried everything and still can't get this to work!(I'm fairly new to JAVA but am getting a little frustrated). I spent alot of time creating the GUI interface with all the text fields, JButtons, labels, etc. Do you think you can help? Please see my full applet source code below to see what I've completed to date (this code does compile if you want to see the interface):

[ June 25, 2003: Message edited by: Jim Yingst ]
20 years ago
I implemented your code as follows:
void showFile()
{
// Use a BufferedReader to read text from the file
BufferedReader infile = null;
// Get file name from the text field
String filename = "students.txt";

// Create a buffered stream
infile = new BufferedReader(new FileReader(filename));
String line;
setup(jtfStudentID);
setup(jtfLastName);
setup(jtfFirstName);
setup(jtfAddress);
setup(jtfCity);
setup(jtfProvince);
setup(jtfPcode);
setup(jtfPhone);
setup(jtfEmail);
}

private void setup (JTextField jtf) {
String line = infile.readLine();
if (line == null)
throw new RuntimeException("This infile sucks");
jtf.setText(line + '\n');
}
However, I receive an error when trying to compile stating that the VARIABLE INFILE cannot be resolved. This is strange because this variable was recoginzed in other methods but not this one. Please help!!!
20 years ago
I'm still confused .... do I replace my existing code with the one you provided or add to my code?
20 years ago