Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!

avelin chen

Greenhorn
+ Follow
since Dec 11, 2005
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 avelin chen

Cheese Sacrifice Purchase Day

That sucks, I love cheese
14 years ago
I'm supposed to complete computeStudentMean method and the displayMeans method. Method computeStudentMean accesses the four grades in each individual student record, computes the mean of the four grades and stores the result in mean. Method displayMeans list all the student name and their respective test averages.


For the computeStudentMean part, I know that I can convert an object into a primitive data type by doing somthing like this:


What I don't get is how to convert my Student object into like an integer, s I can add them up and find the mean. Also, for my displayStudentMean, I get the addresses instead of the actual numbers. Thanks in advance!
14 years ago
We haven't learned how to use an arrayList yet so I can't do that. I redited my code, and I was wondering if this woud be on the ight track.


Also, could someone please explain to me why I keep on gettin at comple error at my newWidth and newHeight, it says that I have a possible loss of precision. Wouldn't the round make it an int? Thanks!
14 years ago
Write a program which start by drawing a 200 X 200 square at the top-left corner of the monitor.
Continue drawing squares that become steadily smaller as they are displayed to right side of each preceding square.
The bottom of the square stays at the same level. Each square is 25 percent smaller than the previously drawn square.
Start with the student version, shown below.

In the student version you are provided with a completed main method. This method is designed to execute graphics application, which done by completing the Windows class.
Make no changes to the main method.

Inside the Windows class, you will need to use a paint method that controls the graphics output with an object of the Graphics class.
You will also need to create a method, called drawSquare, which actually draws the squares and calls itself recursively until the base case is reached.

The recursive process exits when it is true that either the square size becomes smaller than four pixels or the border of the monitor is reached.
You must be aware that only full-sized squares must be displayed. Keep this in mind as you determine if you are reaching the border of the monitor.



80 Point Version

The 80 point version draws one set of squares from left to right, starting with a 200X200 square
that is drawn with a top-left corner at coordinate (0,100). Each square is drawn with a 10 pixel space between the squares.

100 Point Version

The 100 point version draws a second set of squares in the same manner as the 80 point version,
but this time the large square start on the right side and successive squares are drawn moving to the left side of the screen.

Code:
// Lab19bst.java
// The student version of the Lab19b assignment.


import java.awt.*;
import java.awt.event.*;

public class lab19b
{
public static void main(String args[])
{
Windows win = new Windows();
win.setSize(1000,750);
win.addWindowListener(new WindowAdapter() {public void
windowClosing(WindowEvent e) {System.exit(0);}});
win.show();
}
}

class Windows extends Frame
{

public void paint(Graphics g)
{
g.fillRect(0,100,200,200);
}

public static int drawSquare(int width, int height)
{
if (height < 0 && width < 0)
return drawSquare(width - 5, height - 5);//How would you tell it to decrease by 25% and also move over?
}

}


This is what I have so far. Could somebody tell me if I am on the right track? Also, how is the Graphics method supposed to display the recursive square. Do I need to put the Graphics inside the recursive method? Thank you for your help!
14 years ago
Could someone give me some pointers on how to start this porgram? Thanks in advance!

Write a program that retrieves the "Lab17a.dat" text file. This is the same text file that you used for the Lab17a assignment with the same student record format. For this assignment you will not only retrieve a text file, but also create a new text file. This means that in addition to using the FileReader class and the BufferedReader class, you will also need to use the FileWriter class and the BufferedWriter class of the java.io.* package.

Retrieve the "Lab17a.dat" file and check the gpa of each student record. A new file, called "Lab17b.dat", is created with all student records purged that have gpas below 2.0. As you execute the program you need to display the record of each student that will be purged, along with a count of the total records purged.

First output:
Name: Ann Seaborn
GPA: 1.785

Name: Mary Pridgen
GPA: 1.957

Name: Steven Johnson
GPA: 0.785

Name: Tom Tooch
GPA: 1.456

Name: Mike Bruun
GPA: 1.783


Total records purged: 5

Second output
Bart Reagor
27
2.075
Kristyn Reckner
19
3.225
Paul Reiman
41
4.000
Andy Reitinger
20
3.525
William Reynolds
50
3.375
William Robbins
34
2.875
Brian Roberts
23
3.175
Lauri Robertson
19
2.925
Richardson Robinson
26
3.210
Laurie Rosemberg
45
4.000
Barbara Salsa
18
3.000
Lori Salbury
23
3.455
Diane Simcox
32
2.175
Kevin Sims
67
3.235
Michael Ward
19
3.451
Cheryl willis
37
3.576
Tracy Springer
41
2.305
Nancy Barone
25
2.975
Patti Skinner
47
2.743
Diana Rockel
56
3.456
Michelle Ritter
25
4.000
Mali Cozart
16
2.345
Todd Deans
22
2.023
Laura Collins
30
3.999
Debbie Mozart
40
2.999
Gordon Collins
25
3.100
Susan Craft
29
3.754
Vance Brawner
31
3.678

Thanks again!
14 years ago
Never mind, I have got it converted to ints and doubles


Also, I have a question, if I want to count the number of time that it diplays name, I know that I can use a for loop.


What would be my upperbound though?
Thanks in advance!
14 years ago

Hello, I'm supposedto write a program that checks to see if the file exists and displays the file contents. Additionally, three statistics need to be computed and displayed. The program needs to count the number of records, compute the meanAge and the meanGPA for each student.

Both meanAge and meanGPA need to be displayed rounded off to three digits beyond the decimal point.
Thisis what I have so far, and I'm wondering if I'm on the right track. I'm a little bit confused on how I can acess every other three lines and then either convert them to a double or int. When I run this program, it gives me a compile error. Any help will be greatly appreciated!
14 years ago





The output is supposed to be:

Enter a string ===>> Racecar

String: Racecar
Palindrome: true
Almost Palindrome: false

Do you wish to repeat this program [Y/N]? ===>> y

Enter a string ===>> Aardvark

String: Aardvark
Palindrome: false
Almost Palindrome: false

Do you wish to repeat this program [Y/N]? ===>> y

Enter a string ===>> A man, a plan, a canal, Panama

String: A man, a plan, a canal, Panama
Palindrome: false
Almost Palindrome: true

Do you wish to repeat this program [Y/N]? ===>> n

While on the other hand, my output is:
Enter a string ===>> Racecar

String: Racecar
Palindrome: true
Almost Palindrome: true<--SUPPOSED TO BE FALSE

Do you wish to repeat this program [Y/N]? ===>> y

Enter a string ===>> Aardvark

String: Aardvark
Palindrome: false
Almost Palindrome: false

Do you wish to repeat this program [Y/N]? ===>> y

Enter a string ===>> A man, a plan, a canal, Panama

String: A man, a plan, a canal, Panama
Palindrome: false
Almost Palindrome: true

Do you wish to repeat this program [Y/N]? ===>> n

I don't know how to change it without altering the other palindromes. Help will be greatly appreciated!
14 years ago
So, I know that if it already a palindrome, it just returns the original String. But, if it is not, then it goes through the least palindrome thing. I know that I want to take the original String and tack it on backwards, but it has to use the least amount of letters. So, I could probably let it go through the isPal thing with the last letter first, and then move forwards, right?
14 years ago
What does the compiler say?
14 years ago

function leastPal takes String s and returns String loop create a String temp if temp is a palindrom return temp end loopend function


So,


I get what my process should be, but I just don't know how to write it out.
I tried a different way again, but when I typed in Raceca, it went RacecaRaRcaRecaRcecaR



I just want it to stop at the first big R. Arghh this is frustrating
14 years ago
I figured out how to mmake a least palindrome, but apparently, it is still not quite a least palindrome yet.


For the least palindrome output of Raceca, I get RacecacecaR
It is supposed to be RacecaR

Could somebody please explain to me how to use the least number of letters for the least palindrome?
Am I supposed to use another for loop of some kind?
14 years ago
Would something like this work?
14 years ago
I think I get the process of doing this, but what I don't get really is after I have found where I nedd to add the letter(s), how do I add it on? I know this sounds dumb, but do I use the concat method? Also, once I have found the palindrome, how do I tell it to stop at that point?
14 years ago