Need help with classes in Applets and drawing buildings.
I'm trying to create an Applet that draws a starfield (I got that right) and then searches for any parameters in the Applet tag. The Applet then draws as many buldings as there are parameters in the Applet tag, and uses the number in the parameter as the height. I have it working OK, but it won't draw the buildings. Here is me code:
import java.applet.Applet;
import java.awt.*;
import java.awt.geom.*;
import java.util.*;
import javax.swing.*;
public class Skyline extends Applet {
public void init() {
setBackground(Color.black);
public void paint(Graphics g) {
Graphics2D pen = (Graphics2D) g;
Random generator = new Random();
Stars starField = new Stars();
starField.drawStars(pen, getWidth(), getHeight());
int n = 1;
String param = null;
while((param = getParameter("param" + n)) != null) {
n++;
int startX = 0;
int startY = getHeight();
int height = 0;
int width = getWidth() / (n + 2);
Building structure = new Building();
structure.drawBuilding(pen, height, width, startX, startY, n);
class Stars {
public void drawStars(Graphics2D pen, int Width, int Height) {
Random generator = new Random();
int runs = 1;
while (runs <= 1000) {
int Xcord = generator.nextInt(Width - 3);
int Ycord = generator.nextInt(Height - 3);
Ellipse2D.Double star
= new Ellipse2D.Double(Xcord, Ycord, 3, 3);
pen.setColor(Color.white);
pen.fill(star);
runs++;
class Building {
public void drawBuilding(Graphics2D pen, int height, int width, int startX, int startY, int n) {
Random generator = new Random();
int n2 = 1;
int runs = 1;
String input = "";
int red = generator.nextInt(100),
green = generator.nextInt(100),
blue = generator.nextInt(100);
pen.setColor(new Color(red, green, blue));
while (runs <= n) {
input = getParameter("building" + n2);
height = Integer.parseInt(input);
height = startY - height;
Rectangle building = new Rectangle(startX, startY, height, width);
pen.fill(building);
startY = startY + width;
n2++;
runs++;
Can anyone help me?
That didn't work, so I looked at the code again and found some errors. I decided to rewrite it, here is the updated code...
import java.applet.Applet;
import java.awt.*;
import java.awt.geom.*;
import java.util.*;
import javax.swing.*;
public class Skyline extends Applet {
public void init() {
setBackground(Color.black);
public void paint(Graphics g) {
Graphics2D pen = (Graphics2D) g;
Random generator = new Random();
Stars starField = new Stars();
starField.drawStars(pen, getWidth(), getHeight());
Building structure = new Building();
structure.drawBuilding(pen);
class Stars {
public void drawStars(Graphics2D pen, int Width, int Height) {
Random generator = new Random();
int runs = 1;
while (runs <= 1000) {
int Xcord = generator.nextInt(Width - 3);
int Ycord = generator.nextInt(Height - 3);
Ellipse2D.Double star
= new Ellipse2D.Double(Xcord, Ycord, 3, 3);
pen.setColor(Color.white);
pen.fill(star);
runs++;
class Building {
public void drawBuilding(Graphics2D pen) {
Random generator = new Random();
int n = 1;
int n2 = 1;
int runs = 1;
String input = "";
String param = "";
while ((param = getParameter("building" + n)) != null) {
n++;
int height = getHeight();
int width = getWidth();
int startX = 0;
int startY = height;
int red = generator.nextInt(100),
green = generator.nextInt(100),
blue = generator.nextInt(100);
pen.setColor(new Color(red, green, blue));
while (runs <= n) {
height = getHeight();
input = getParameter("building" + n2);
height = Integer.parseInt(input);
height = startY - height;
Rectangle building = new Rectangle(startY, startX, height, width);
pen.fill(building);
startX = startX + width;
n2++;
runs++;
I can get it to draw one large black building, but that's it.
Similar Messages
-
I need help with the Quote applet.
Hey all,
I need help with the Quote applet. I downloaded it and encoded it in the following html code:
<html>
<head>
<title>Part 2</title>
</head>
<body>
<applet codebase="/demo/quote/classes" code="/demo/quote/JavaQuote.class"
width="300" height="125" >
<param name="bgcolor" value="ffffff">
<param name="bheight" value="10">
<param name="bwidth" value="10">
<param name="delay" value="1000">
<param name="fontname" value="TimesRoman">
<param name="fontsize" value="14">
<param name="link" value="http://java.sun.com/events/jibe/index.html">
<param name="number" value="3">
<param name="quote0" value="Living next to you is in some ways like sleeping with an elephant. No matter how friendly and even-tempered is the beast, one is affected by every twitch and grunt.|- Pierre Elliot Trudeau|000000|ffffff|7">
<param name="quote1" value="Simplicity is key. Our customers need no special technology to enjoy our services. Because of Java, just about the entire world can come to PlayStar.|- PlayStar Corporation|000000|ffffff|7">
<param name="quote2" value="The ubiquity of the Internet is virtually wasted without a platform which allows applications to utilize the reach of Internet to write ubiquitous applications! That's where Java comes into the picture for us.|- NetAccent|000000|ffffff|7">
<param name="space" value="20">
</applet>
</body>
</html>When I previewed it in Netscape Navigator, a box with a red X appeared, and this appeared in the console when I opened it:
load: class /demo/quote/JavaQuote.class not found.
java.lang.ClassNotFoundException: .demo.quote.JavaQuote.class
at sun.applet.AppletClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.applet.AppletClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.applet.AppletClassLoader.loadCode(Unknown Source)
at sun.applet.AppletPanel.createApplet(Unknown Source)
at sun.plugin.AppletViewer.createApplet(Unknown Source)
at sun.applet.AppletPanel.runLoader(Unknown Source)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.io.FileNotFoundException: \demo\quote\JavaQuote\class.class (The system cannot find the path specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at sun.net.www.protocol.file.FileURLConnection.connect(Unknown Source)
at sun.net.www.protocol.file.FileURLConnection.getInputStream(Unknown Source)
at sun.applet.AppletClassLoader.getBytes(Unknown Source)
at sun.applet.AppletClassLoader.access$100(Unknown Source)
at sun.applet.AppletClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
... 10 more
Exception in thread "Thread-4" java.lang.NullPointerException
at sun.plugin.util.GrayBoxPainter.showLoadingError(Unknown Source)
at sun.plugin.AppletViewer.showAppletException(Unknown Source)
at sun.applet.AppletPanel.runLoader(Unknown Source)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
java.lang.NullPointerException
at sun.plugin.util.GrayBoxPainter.showLoadingError(Unknown Source)
at sun.plugin.AppletViewer.showAppletStatus(Unknown Source)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)What went wrong? and how can I make it run correct?
Thanks,
Nathan PinnoJavaQuote.class is not where your HTML says it is. That is at the relative URL "/demo/quote/".
-
Need help with my iPhone 5 and my Macbook Pro.
Need help with my iPhone 5 and my Macbook Pro. I was purchased some music on itunes at my mac. Some reason I deleted those music from both on Mac and iPhone 5. Today, I went to my iPhone iTunes store inside of iCloud to redownload my puchased. But those song won't able to sync back to my iTunes library on my Mac. Can anyone help me with that ??....
iPhone 5, iOS 6.0.1You've posted to the iTunes Match forum, which your question does not appear to be related to. You'll get better support responses by posting to either the iTunes for Mac or iTunes for Windows forum. Which ever is more appropriate for your situation.
-
Need HELP with Stick Figure Applet
I need help with this java program for college....we need to make a applet which displays a stick figure or some type of person using appleviewer..please can someone help me......
email: [email protected]import java.awt.*;
import java.applet.*;
public class StickMan extends Applet {
public void init() {
public void paint(Graphics g) {
g.drawOval(....);
g.drawLine(....);
g.drawLine(....);
g.drawLine(....);
g.drawLine(....); -
I''ve just started out with Java and I need help with my latest program.
The program looks someting like this:
public class MultiServer {
public static void main(Straing[] args) {
ServerGUI GUI = new ServerGUI();
public class ServerGUI extends JFrame implements ActionListener {
private TextArea textArea;
public ServerGUI() {
//setting up the JFrame and stuff like that
public void actionPerformed(ActionEvent event) {
if(button == addButton) {
addGUI add = new addGUI();
public class addGUI extends JFrame implements ActionListener {
private TextField t1 = new TextField(25);
public addGUI() {
//setting up the JFrame and stuff like that
public void actionPerformed(ActionEvent event) {
if(button == printButton) {
textArea.append("THIS DOES NOT WORK!");
} The problem is as follows: I want to be able to write text in the textArea in class ServerGUI from the class addGUI, but I can't. I hope you understand what I mean.
How is this fixed? Please help me!public void actionPerformed(ActionEvent event) {
if(button == addButton) {
addGUI add = new addGUI(textArea);
public class addGUI extends JFrame implements ActionListener {
private TextArea textArea;
public addGUI(TextArea textArea) {
this.textArea = textArea;
}/Kaj -
I need help with my text tone and I have ring tone. no text tone for the 4s.
I need help with my text tone. I have ring tone no text tone. I have a 4s.
Hi Sarar2333! Let's get your text tones working again!
Here's a link with instructions how to enable and change your alert sounds for your text/notification settings on your iPhone 4S: http://vz.to/1stiF8a. You can ensure text tones are enabled by selecting a tone in the "Text Tone" setting. Let me know how that works out for you. Thanks!
AnthonyTa_VZW
Follow us on Twitter @VZWSupport -
Need help with buying graphics card and ram for MSI 865PE NEO 2-V
Hi,
I want to buy 1GB of ram for motherboard MSI 865PE NEO 2-V I need help with finding correct parts.
I also want to buy 512Mb or 1GB graphics card.
as i said before i need help with finding correct ones so they match motherboard, I would appreciate if any one would post link to cheap and fitting parts.
I found graphics card allready, i just need to know if it will fit.
the card is
NVIDIA GeForce 7600 GS (512 MB) AGP Graphics Card
Thanks for help.here you can see test reports for your mobo:
http://www.msi.com/product/mb/865PE-Neo2-V.html#?div=TestReport -
Need help with clickbios ii terminolgy and values. Z77A-GD65 / 3770k
Hello All
I recently purchased a Z77A-GD65 board and after searching I've found the differences in terminology between this and my previous Asus board but still have a couple of settings I cant find any info on.
System Specs:
motherboard: msi z77a-gd65
cpu: intel 3770k
ram: corsair vengeance 2133mhz 1.5v
psu: corsair 850w
First things first is I believe I am running in turbo oc mode. I've selected the oc genie tab on the center right of the bios screen and proceeded to change settings there. With cpu voltage on auto and vdroop set to 50% at 4.6ghz. (I'll try and get screenshots of bios settings soon)
The following are the terms I need help with:
In the my oc genie section;
1. Long duration power limit
2. Long duration maintained
3. Short duration power limit
In the main overclocking section;
4. Digital Compensation level (not in owners manual, options auto/high)
5. Cpu core ocp expander (enabled for overclock 4.5ghz+?)
In the CPU Features section;
6. long duration power limit w (does "w" stand for watts?)
7. long duration maintained s (does "s" stand for seconds?)
8. short duration power limit
9. primary plane current limit a (does "a" stand for amps?)
10. secondary plane current limit
11. primary plane turbo power limit
12. secondary plane turbo power
I know those are a lot of settings, but would appreciate any simple definitions as to what they do and recommended values for mild overclocking (4.5-4.80)
Also on my previous board (Asus P8P67 Pro) my 3770k was stable in prime95 for 18 hrs at 4.5ghz fixed 1.155v with only ram timings put in manually and LLC set to extreme.(or whatever max is called in asus bios) Voltage was fixed and everything else was defailts.Well I'm back. Been digging around for a few days and found some answers to my questions.
First things first s that for some reason I could not adjust voltage values with the + or - symbols. Clearing cmos did not help this. I had to reflash the bios to get this functionality back as well as clearing cmos before and after the flash.
So I figured out the values in the oc genie section are the same as the normal section but only used when your using the oc genie. (numbers 1-3)
Digital compensation level and ocp expander should be set to high and enabled respectively when going for higher overclocks. (4 and 5)
Now for the rest of my questions ( 6 through 12) I have found suggested settings and some info after hours and hours of searching but still have a couple of questions about them.
Long/short duration power limit, and primary/secondary plane turbo limit. I see suggestion settings of 250 or 255. I take it this is simply max supplied watts to the chip? If so why the 250/255 values? Is that the highest the board will give? Is plane turbo limit related to the enhanced turbo stated and how much wattage can be drawn there while the other limit is for any non turbo frequencies?
Long duration maintained, I've seen 60 suggested a lot. Why is this?
There's not an over abundance of info on these boards as compared to asus so it seems info is a little less documented and video tutorials explaining things are next to none.
Any help would be appreciated. Thanks -
I need help with my phone it is not ringing and I cant figure where in here to make it so it will something has been pushed so I cant hear any calls or texts
Not when you insist on being so impatient.
These are user to user support forums. No one here is paid to read or respond to messages.
Try explaining the issue instead of the jumbled, rambling mess of a title and we will be happy to assist. -
So im just starting java, about 12 weeks in.
So in my class we are getting started with objects. What i want to do is create a class called car, and have it create a new car and draw images loaded, and then have the tires rotate, there are 2 images,
the car base and the tires.
I know how to display images in applets, but i dont know how to define the images in the objects class and then draw them from the class.I get errors with this code from my car class
import java.applet.*;
public class car extends Applet{
* @param args
private String model;
private int passangers;
private double gas,speed;
private Image tire;
private MediaTracker tr;
tr = new MediaTracker(this);
tire = getImage(getCodeBase(), "tire.png");
tr.addImage(tire,0);
public car(String id, int pass, double tank)
model=id;
passangers=pass;
gas=tank;
public car()
model="";
passangers=0;
gas=0;
}I get errors on these lines
private Image tire;
private MediaTracker tr;
tr = new MediaTracker(this);
tire = getImage(getCodeBase(), "tire.png");
tr.addImage(tire,0);errors
Severity and Description Path Resource Location Creation Time Id
Image cannot be resolved to a type Car Game car.java line 13 1197077768237 1745
MediaTracker cannot be resolved to a type Car Game car.java line 14 1197077768238 1746
Return type for the method is missing Car Game car.java line 16 1197077768239 1750
Syntax error on token ";", { expected after this token Car Game car.java line 14 1197077768238 1747
Syntax error on token "(", delete this token Car Game car.java line 17 1197077768239 1752
Syntax error on token "0", invalid FormalParameter Car Game car.java line 17 1197077768239 1753
Syntax error on token(s), misplaced construct(s) Car Game car.java line 15 1197077768238 1748
Syntax error on token(s), misplaced construct(s) Car Game car.java line 16 1197077768239 1749
Syntax error on tokens, delete these tokens Car Game car.java line 16 1197077768239 1751
The serializable class car does not declare a static final serialVersionUID field of type long Car Game car.java line 4 1197077768237 1744
The serializable class main does not declare a static final serialVersionUID field of type long Applet main.java line 5 1196990860997 1682
The serializable class main does not declare a static final serialVersionUID field of type long Car Game main.java line 5 1197077768196 1743
The serializable class ShowImage does not declare a static final serialVersionUID field of type long Display JPEG/src ShowImage.java line 4 1196488911896 1393Edited by: jasonpeinko on Dec 7, 2007 5:42 PM -
I want to design and use one or more classes for a particular project I am working on.
I need some advice hopefully from someone who has experience in this area. Basically,
for this particular problem I have two database tables. I want the first class to
represent the first database table and the second class to represent the second
database table. An object of the first class will be created first, and then if certain
criteria are met then an object of the second class will be created.
Question:
Should I use classical inheritance and let the first class inherit from the second class?
Or should I use the containment delegation model and embed an object of the second
class in the first class?
----Tables------
For example, my first table ET_UserData looks something like this:
ET_UserData
(PK)UserName
Password
FirstName
LastName
My second table ET_DetailedUserData looks like this
ET_DetailedUserData
(FK)UserName
WorkAddress
WorkPhoneNumber
CityWhereEmployed
SocialSecurityNumber
City
State
StreetAdress
PrimaryTelephoneNumber
AlternatePhoneNumber
HasRegistered
RegistrationDate
RegistrationTime
CreditCardNumber
NameOfPrimaryContact
DateOfBirth
Weight
EyeColor
Height
Member
Here is are some pseudo classes for the two classes.
Class UserData
string UserName
string FirstName
string LastName
Class DetailedUserData /* For a classical approach, sub class off of class UserData */
/* UserData ThisUser --> Containment delegation model */
string (FK)UserName
string WorkAddress
string WorkPhoneNumber
string CityWhereEmployed
string SocialSecurityNumber
string City
string State
string StreetAdress
Int PrimaryTelephoneNumber
Int AlternatePhoneNumber
Bool HasRegistered
Int RegistrationDate
Int RegistrationTime
Int CreditCardNumber
String NameOfPrimaryContact
Int DateOfBirth
Int Weight
Int EyeColor
Int Height
bool Member
}Thank you for your help. If you can continue to help me I would appreciate it.
I and another developer did the database design. Pretty solid design. Plus we have all of the requirements
which are very good too.
Originally I wanted just one table to contain all of the data associated with a user. Instead of ET_UserData and ET_Detailed user data I wanted just one table. But I decided to break this table up into the two tables for the following reason.
1.) This is a web application where each user logs into a web form. At a minimum, in order to use the website the session associated with each user needs the UserName, Password, First and last name.
This is the data in the first table.
If they choose to do more specialized functions on this website, then they will need all of the information (Attributes) that are located in the second table. In general 40% of the time all users will need information located in the second table.
My reasoning for breaking the table into two seperate tables is that I wanted to minimize the amount of data involved in a result set, created from the sql query. The math tells me that 60% of the time most of the data in the result set will not be used.
2.) If I create one class to represent all of the data/attributes in both tables, then my reasoning is that their will be alot of overhead in the single class because 60% of the time, a majority of the attributes are not needed and used.
I would deeply appreciate your help with this. You seem to have great insight and advice. Please help me as I increase the duke dollars Sir. -
Need Help with External Hard drives and too much music
I am not terribly tech-savvy, and I need your help. I have a G5 PPC dual processor with an internal 250GB drive. I have two seagate firewire/USB2 external hard drives. One is 250GB and one is 350GB. I want to know how to use them to get my Mac to run faster and better.
My original hard drive is 7GB shy of being full. Almost half of this is my itunes library which is over 100GB. The older (250GB) hard drive has about 150GB of photos/videos.
My Mac is running slow as molasses and when I power up the external hard drives it slows down to what I recall my original Mac Plus ran like.
I use the G5 primarily to work with photos, illustrations and creating the occasional DVD with video and photos. the apps I use most often are Photoshop, Illustrator and Painter. I always listen to music while work.
I hope all of this information is helpful! Here is my question:
What is the best way for me to set up and use these external hard drives to return my G5 to its original blazing (to me) fast speed?
PPC G5 Mac OS X (10.4.9)I think you should look at adding two 500GB internal drives. I'd say Maxtor MaxLine Pro for cost, but they also run much warmer (43ºC even when nearly doing zilch) so I'd go with WD RE2 500GB for $40 ea. more.
dump whatever you don't need, trash anything that is hogging space and is just temp file or useless cache. Web browsers can leave behind a ton of small files eating up tens of MBs.
Use SuperDuper to backup/clone your drive.
Disk Warrior 4 to repair (after it gets to 15% free, or just forget for now).
A 250GB drive formats to 240GB and you have ~3% free it looks like.
For every data drive plan to have two backup drives.
Keep your boot drive to 40% used.
And your data drive to 60%.
Backups can go a little higher.
Drives are cheap and inexpensive, especially for the space and performance. And they have improved SATA over the years it has been out.
By doing a backup followed by erasing your drive, and then restoring it, using SuperDuper, which optimizes the organization, skips copying temp files that aren't needed, it also defragments your files. I would do backup daily to different sets that you "rotate." And before any OS update. And do the erase and restore probably every 2 months.
Make sure you keep one drive partition somewhere that is just your disk utility emergency boot drive that is not a copy of working system, used for doing repairs like running Disk Warrior and Disk Utility.
You may need to repair; backup; even erase and restore your external drives. Rather than spend on vendor made case, just pick up a good FireWire case either with drive, or bare (and add your own). I think it'd add 500GB FW drive though.
Why?
To begin backup of your current drive. To leave your other FW drives "as is" for now.
Then install a new internal 500GB drive as well so you now have a good current backup, and you have moved your data off 250GB to 500GB. If anything happens, you have one off line FW backup.
Then begin to clean up, organize, and get your FW drives working. It sure sounds like they have had some directory or file problems.
You can find a lot of Firewire and SATA drive choices over at OWC:
http://www.macsales.com/firewire/ -
Need help with ext. SWF and XML
I'm trying to create an External SWF to load into my main
site (photography).
Home | Portfolio | Published Work | Bio | Contact
The SWF I want to load externally is Portfolio because it has
5 sections
Those 5 sections are:
-Editorial
-Adventure
-Fly Fishing
-Multimedia
-Weddings
I'm looking to keep this dynamic as possible, but I'm one of
those guys who doesn't write code from scratch, but knows AS well
enough to modify a base or a generic template if ever given. It
would be easier to use one subsection as an example, which could be
applied to all others.
e.g. "Fly Fishing" 1-Main container; 5-10 thumbnails (1
dyanamic thumbnailcontainer)
- I don't know XML (but can modify it). basically having an
ID tag for each image, possibly dynamically generate a thumbnail
too. Also have a spot for dynamic text to load in (captions with
multiple text lines for images upon onRelease - maybe this could be
it's own MC that loads on top of the main photo container)
- on (release) on a thumbnail: there would be a little
information icon that would appear. If you mouse over, it would
overlay a layer over that specific ID photo, and the text appear.
RollOut it would fade out the layer above that specific ID photo.
- Transition: FadeOut/Blur/Exposure Blur, something
interesting to that nature.
- Thumbnails: is it just easier to create thumbnail images
manually, and just create a separate container?
- Image folders: I would imagine each section would have
it's own watch folder. For example "Fly Fishing" would be a folder
"/swfImg_flyFishing/", but perhaps having one XML file.
- XML file details
id
location
caption summary
title
As you can see, if I had one template to build off of, I
could repeat it self for the others. I need help and if there is a
flash component (free or purchase) that does at least 70% of what I
need, please share information. thank you!PortfolioI know doing a pushback to the client requires Flex Data
Services, but since I don't use FDS I can't tell you exactly how.
But look in the documentation about "pushing" data to the client.
Once you've figured out how to do that, you can trigger that push
once you've finished editing the xml file. You may want to ask over
in the FDS forum. -
Where to start? Need help with classes
My question involves those classes he wants us to make. I don't really get the concept of classes, so could someone tell me what they think he wants us to do? And try to explain it to me in terms I might be able to understand. Does that mean for us to use subclasses or use separate files for each class? Or could I do either? I'm so confused :(
Assignment: Write a program that consists of the classes listed below.
Player Class: The Player Class consists of at least two elements -- the player name and a list of scores for
games. The score attribute is not used in Program #3 but will be needed in Program #4. Include in the
class appropriate accessor and mutator methods for each element in the class. You may have other
attributes if needed.
Team Class: The Team class consists of at least 6 elements -- the name of the team and five players from
the Player class. Include in the class appropriate accessor and mutator methods for each element in the
class. You may have other attributes if needed.
Course Syllabus Page 3
Input3 class: The Input3 class is provided for you. The Input3 class supplies data for your program. The
Input3 class has a public method called getNextString, which returns a string with the input for your
program, one after the other. You must use this class to get the data for your program. See Input3.java on
WebCT to understand the class construction.
Your program should display the roster of each team in alphabetical order by last name.
This is the Input3 that he gave us to work with if anyone needs to see it:
public class Input3
private String[] input = new String[40];
private static int StringNum = -1;
public static final int NUMBER_OF_TEAMS = 3;
public static final int NUMBER_OF_PLAYERS = 5;
public Input3()
//The first six inputs will be for the first team
input[0] = "LAKERS";
input[1] = "Kobe Bryant";
input[2] = "Derek Fisher";
input[3] = "Shaquille O'Neal";
input[4] = "Karl Malone";
input[5] = "Brian Cook";
//The next six inputs will be for the second team
input[6] = "MAVERICKS";
input[7] = "Antoine Walker";
input[8] = "Dirk Nowitzki";
input[9] = "Tony Delk";
input[10] = "Shawn Bradley";
input[11] = "Travis Best";
//The next six inputs will be for the third team
input[12] = "KNICKS";
input[13] = "Mike Sweetney";
input[14] = "Allan Houston";
input[15] = "Howard Eisley";
input[16] = "Kurt Thomas";
input[17] = "Shanon Anderson";
//This method returns the strings one after the other.
public String getNextString()
StringNum++;
return input[StringNum];
}<br>
<br>
<br>
ThanksYou could put the classes in separate files, but it's not necessary. They wouldn't be called 'subclasses' here, as that word is specific to inheritance, which you don't need here. Here's an example of using multiple classes:
public class MainClass {
public static void main(String [] args) {
OtherClass1 oc1 = new OtherClass1(3);
OtherClass2 oc2 = new OtherClass2("hello");
System.out.println("" + oc1.getInt());
System.out.println(oc2.getString());
class OtherClass1 {
int someInt;
public OtherClass1(int i) {
someInt = i;
public getInt() {
return someInt;
class OtherClass2 {
String someString;
public OtherClass2(String s) {
someString = s;
public getString() {
return someString;
}and like BDLH said above, it's preferred to put them in separate files. Just make sure the file name is EXACTLY the same as the class name, followed by .java -
Need help with class inheritance
I've got a class called jemAccount and i need to create a savings account class and a checking account class that inherit from it.
Here is the jemAccount:
public class jemAccount
protected String myName;
protected double myBalance;
protected double[] withdrawls = new double [50];
protected double[] deposits = new double [50];
protected int withIndex = 0;
protected int depIndex = 0;
public jemAccount ()
myBalance = 0;
public jemAccount (String newName)
myName = newName;
myBalance = 0;
public jemAccount (String newName, double newBal)
myName = newName;
myBalance = newBal;
public void setName(String newName)
myName = newName;
public double balance()
return myBalance;
public void withdrawl (double amount)
if (amount < 0)
myBalance += amount;
else
myBalance -= amount;
if (withIndex < 50)
withdrawls[withIndex] = amount;
withIndex++;
public void deposit (double amount)
if (amount > 0)
myBalance += amount;
if (depIndex < 50)
deposits[depIndex] = amount;
depIndex++;
public void printAccount()
System.out.println("Owner of account: " + myName);
System.out.println("Balance of account: " + myBalance);
System.out.println("Deposits: ");
for (int i = 0; i < depIndex; i++)
System.out.println(" " + deposits);
System.out.println("");
System.out.println("Withdrawls: ");
for (int i = 0; i < withIndex; i++)
System.out.println(" " + withdrawls[i]);
System.out.println("");
System.out.println("");
} // end of class jemAccount
Here are my requirements for the savings account class:
� Call the class "abcSaveAccount".
� Have this class inherit from "jemAccount"
� Add a float for keeping track of the yearly interest rate of the checking account. Call this class variable "interest" Make it protected.
� Add a public constructor for the savings account class. It should have one parameter, a float that initializes the new savings account class variable. This constructor should also call the parent class constructor with no arguments.
� Add a public method for calculating interest. Call it "calcInterest". Have it take one parameter, an integer which represents the number of months to calculate the interest for. This method should return a float, the result of the interest calculation. For example, if 30 months are entered as a parameter of 30, then 2 and one/half years of interest on the balance are calculated and returned.
Here are the requirements for the checking account class:
� Call the class "abcCheckAccount"
� Have this class inherit from "jemAccount"
� Add an array for keeping track of the checks you write. For now, just make this an array of 100 doubles, very similar to withdrawals
� Add a public constructor for the checking account class. It should have zero parameters. This constructor should also call the parent class constructor with no arguments.
� Add a new public method to your checking account class. Call it "writeCheck". This should take one double parameter. If the value of the parameter is positive, subtract the parameter from the balance, and copy the value into the "checks" array. (Keep the checks and withdrawals separate.) Else do nothing.
� Override the "printAccount" method. Have the checking account "printAccount" run its parent "class printAccount", then print out a list of the checks, after the list of the withdrawals.
Here's what i have so far for the savings account class:
public class abcSaveAccount extends jemAccount
protected float interest;
public void abcSaveAccount (float newSavings)
super ();
public calcInterest (int numberMonths)
return interest;
And here's what i have so far for the checking account class:
public class abcCheckAccount extends jemAccount
double[] checks = new doulbe[100];
public abcCheckAccount ()
super ();
public writeCheck (double value)
if (value >= 0)
balance = balance - value;Few changes,
public class abcCheckAccount extends jemAccount {
private double[] checks = new double[100];
private int checkIndex;
public abcCheckAccount() {
super ();
checkIndex=0;
public void writeCheck (double value) {
if ( value >= 0) {
withdrawl(value);
checks[checkIndex++]=value;
public void printAccount() {
super.printAccount();
System.out.println("Checks:");
for (int i = 0; i < checkIndex; i++) System.out.println(" "+checks[ i ]);
System.out.println("");
System.out.println("");
} // end of abcCheckAccount classand
public class abcprog {
public static void main (String args[]) {
abcCheckAccount check = new abcCheckAccount();
check.setName("Sudha");
check.deposit(1000.0);
check.deposit(200.0);
check.withdrawl(112.0);
check.writeCheck(300.0);
check.printAccount();
abcSaveAccount save = new abcSaveAccount(6);
save.setName("Mike");
save.deposit(1000.0);
save.withdrawl(112.0);
save.printAccount();
System.out.println("Calculated Interest : "+save.calcInterest(120));
}U can use this program to test your classes.
Sudha
Maybe you are looking for
-
Canon S750 printer not working after upgrading to Leopard
Leopard is brilliant, and everything works after I upgraded from Tiger except... my Canon S750 printer gives error messages and fails to print. This is VERY annoying. I can't seem to find an S750 driver for OS X 10.5 on Canon's web site. So, what to
-
Switch to changeove method occuring in next fiscal year instead of next per
In configuration of depriciation keys, changeover method 5 (changeover after end of planned useful life) is used, but problem is switch to changeover method occurs in first period of next fiscal year, instead of immediate next period after the end of
-
How to access class variables in anonymous class??.
I have a boolean class level variable. Fom a button action , this boolean will set to true and then it used in anonymous class. In anonymous class, I am getting default value instead of true. Could u anyone help in this plzzz.
-
ISE Guest Portal Time Profiles
G'day All, Could someone advise if it is possible to extended or change the time profile of a guest account that has already been created? I am trying to understand using time profiles from within the Sponsor Portal. Imagine a guest user has an accou
-
ASA 5520 v7.2 - VPN site to site problem and clear command
Hi all, I am getting some problems with a Site to Site VPN from the last two weeks. In some occasions it stops to send traffic through the VPN without any apparent reason. I have other VPNs that continue working fine. While it is failing I have run t