Dean_Grobler 48 Posting Whiz in Training

Wouldn't something like this work?

sqrXY instance3 = new sqrXY(instance1.xaxis+instance2.xaxis, instance1.yaxis+instance2.yaxis);

I'm just guessing here by the way, I'm a student myself...

Dean_Grobler 48 Posting Whiz in Training

I don't understand?
The above code is also correct. Just have to include the import statement.. Like:

import Fruit;
public class FruitList
{
    Fruit fr = new Fruit();
}
Dean_Grobler 48 Posting Whiz in Training

Hmmm..

"There is a class Fruitlist which has a sub class apple"
public class Fruitlist(){...}
public class Apple() extends Fruitlist{....}

"There is a class Fruit which has a sub class orange"
public class Fruit() {...}
public class Orange() extends Fruit {...}

"FruitList uses Fruit"
import Fruit;
public class FruitlList(){...}

"Apple uses Orange"
import Orange;
public class Apple(){...}

That's what I'm making out of it?

Dean_Grobler 48 Posting Whiz in Training

Sir,

Googling "Web hosting" brings up numerous options from hundreds of companies. Should have no difficulty. Unless sir is staying in Kowloon Wallen City.

Regards,

Dean_Grobler 48 Posting Whiz in Training

If you want to develop for the web though things like Servlets and JavaServerPages(JSPs) that are available in JEE is some pretty neato stuff...

Dean_Grobler 48 Posting Whiz in Training

Actualy the code section you posted made alot more sense.. Maybe I should just do it that way..

Dean_Grobler 48 Posting Whiz in Training

Thank you so much for your input!
The information you gave is great, although where you said:
" You can of course synchronize all the actions which operate on the `accBalance` variable but that would effectively mean only a "single" client would be able to work with the `accBalance` variable thereby killing any chances of concurrent requests being processed"

I think this is exaclty what my college wants me to do, not very practical or very effective, but it's just to teach us how synchronization works etc etc. If I were to do this then, would I just make the doPost method synchronized and the rest will fall into place or should i make a synchronized(){....} section of code somewhere INSEIDE the doPost method?

Dean_Grobler 48 Posting Whiz in Training

Hi guys,

I have this assignment to do:

Synchronize access to the instance variable, accBalance. Because accBalance is a double and not an object, it cannot be used as the monitor. Use synchronized methods or synchronized blocks of code, as appropriate. Simultaniously test two threads. Because the threads can complete too quickly to determine if they are interfering with each other, delay the adding of a deposit by inserting the following code within the synchronized block or method:

try
{
      Thread.currentThread().sleep(10000);
}
catch(InterruptedException e) {}

I've been strugling with this thing for weeks now, I just don't get Synchronization. I've tried reading up on it but it just doesn't help me. I'm not asking anybody to do this for me, I just want some advice, a push in the right direction etc.. This is the code that I have to Synchronize:

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.text.DecimalFormat;

public class SyncBank extends HttpServlet
{
	// Create Class Variable
	DecimalFormat myFormat = new DecimalFormat("$#,000.00");
	double accBalance = 0.00;

	public void doGet(HttpServletRequest req,HttpServletResponse res)
						throws ServletException, IOException
	{
		doPost(req,res);
	}

	public void doPost(HttpServletRequest req,HttpServletResponse res)
						throws ServletException, IOException
	{

		//Set MIME type of content returned to browser
		res.setContentType("text/html");
		PrintWriter out = res.getWriter();

		//Starts outputting the HTML Form
		out.println("<html><head>" +
					"<title>Online Bank Simulator</title>" +
					"</head><body>" +
					"<hr color=\"#808000\">" +
					"<center><h1>Banking Simulation</h1></center>" +
					"<form method=\"POST\" action=\"../servlet/HTMLBank\">" +
					"<center>Amount: <input type=\"text\" name=\"Amount\" size=\"20\"></center>");

		//Decides which action to take
		String action = req.getParameter("act");

		if(action != null)
		{
			if(action.equals("Deposit"))
			{
				double amount;
				String strAmount …
Dean_Grobler 48 Posting Whiz in Training

Man you gotta be more specific than that, where is the data stored that you wana update? What data is it?

Dean_Grobler 48 Posting Whiz in Training

Yeah I'm using 1.4 hey. It's ridiculous that my college still teaches in this but that's South Africa for you. Can't wait to start coding in 1.6!

Dean_Grobler 48 Posting Whiz in Training

Thanks alot! Still don't really get the difference between Double and double.. should read up on it a bit.

Dean_Grobler 48 Posting Whiz in Training

Hi there guys,

I got this assignment where I need to set a session attribute. Although I'm having problems since I cant set attribute that is of type double? I got these hints but since I've worked with doubleValue() or downcasting, the hints didn't help me much..

Hints:
-Recall that session attributes are stored as objects and must be downcast.
-Because a Double object cannot be modified, use the Double method, doubleValue(),to return an intrinsic double value.

My code:

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.text.DecimalFormat;

public class SessionBank extends HttpServlet
{
	// Create Class Variable
	DecimalFormat myFormat = new DecimalFormat("$#,000.00");

	public void doGet(HttpServletRequest req,HttpServletResponse res)
						throws ServletException, IOException
	{
		doPost(req,res);
	}

	public void doPost(HttpServletRequest req,HttpServletResponse res)
						throws ServletException, IOException
	{
		//Makes instance variable a local variable
		double accBalance = 0.00;

		//Set MIME type of content returned to browser
		res.setContentType("text/html");
		PrintWriter out = res.getWriter();

		//Starts outputting the HTML Form
		out.println("<html><head>" +
					"<title>Online Bank Simulator</title>" +
					"</head><body>" +
					"<hr color=\"#808000\">" +
					"<center><h1>Banking Simulation</h1></center>" +
					"<form method=\"POST\" action=\"../servlet/HTMLBank\">" +
					"<center>Amount: <input type=\"text\" name=\"Amount\" size=\"20\"></center>");

		//Decides which action to take
		String action = req.getParameter("act");

		if(action != null)
		{
			if(action.equals("Deposit"))
			{
				double amount;
				String strAmount = req.getParameter("Amount");
				amount = Double.parseDouble(strAmount);

				if(amount <= 0.00)
				{
					out.println("<h2>Error: The amount is either null or a minus</h2>");
				}
				else
				{
					accBalance = accBalance + amount;
					out.println("<br><center>Balance:"+myFormat.format(accBalance)+" </center> <br>");
				}
			}
			else if(action.equals("Withdraw"))
			{
				double amount;
				String strAmount = req.getParameter("Amount");
				amount = Double.parseDouble(strAmount);

				if(amount <= 0.00)
				{
					out.println("<h2>Error: The amount is either null …
Dean_Grobler 48 Posting Whiz in Training

So, turns out the actualy problem was that I should've initialized the accBalance under class level and not under the doPost method..

Stupid mistakes like this that just gives me stomach aches! Anyway, it's solved now..

Dean_Grobler 48 Posting Whiz in Training

Well at the moment it's a instance variable..
Will give the it a try as a class variable tonight, hope it works.

It does make sense though doesn't it? Instance variables have separate values for each instance of a class. Class variables maintain a single shared value for all instances of the class.

Will let you know if it works,
Thanks for the tip!

Dean_Grobler 48 Posting Whiz in Training

I'm struggling with a servlet that's suppose to represent an "online banking service".
Once you run the servlet you'll see it's an extremely simple example... You enter an amount in the textfield provided, then click on the apropriate button depeding what action you want to perform e.g. "deposit","withdraw" and "balance". Your balance then is displayed in a label underneath the textfield.

Now the problem is: I had to assign a default value for accBalance (0.00). Now everytime I deposit money in, for example $50, my balance does show $50. But when I want to do another diposit ontop of that, e.g. another $100. You'd think that the balance now should be $150 right? ..It doesn't, it then displays $100.. The reason for this (I think) is that everytime the servlet is re-loaded the accBalance is again set to 0.00.

*Once you run the servlet and test it out you'll see what I mean*

The code:

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;

public class HTMLBank extends HttpServlet
{
	public void doGet(HttpServletRequest req,HttpServletResponse res)
						throws ServletException, IOException
	{
		doPost(req,res);
	}

	public void doPost(HttpServletRequest req,HttpServletResponse res)
						throws ServletException, IOException
	{
		//Create variable
		double accBalance = 0.00;

		//Set MIME type of content returned to browser
		res.setContentType("text/html");
		PrintWriter out = res.getWriter();

		try{

		//Starts outputting the HTML Form
		out.println("<html><head>" +
					"<title>Online Bank Simulator</title>" +
					"</head><body>" +
					"<hr color=\"#808000\">" +
					"<center><h1>Banking Simulation</h1></center>" +
					"<form method=\"POST\" action=\"../servlet/HTMLBank\">" +
					"<center>Amount: <input type=\"text\" name=\"Amount\" size=\"20\"></center>");

		// Gets input from user
		//String strAmount = req.getParameter("Amount");

		//Decides which …
Dean_Grobler 48 Posting Whiz in Training

Never mind! sorted it out.. thanks anyway

Dean_Grobler 48 Posting Whiz in Training

This smells like a homework question.. Doesn't even make sense?

Dean_Grobler 48 Posting Whiz in Training

Hi all,

Does anybody know what this "WSaction" is?
What it does and most importantly how it works?

I've tried googling this but hardly found ANYTHING..
I'm busy working with Servlets and as far as I can
tell it checks what button was pressed in the
HTML form..

But I'm not too sure, any help would greatly be appreciated!

Thanks!

Dean_Grobler 48 Posting Whiz in Training

Hi there,

Name's Dean, I'm a java student here in sunny South Africa.. Very impressed by daniweb!
Been with other IT communities, and daniweb seems way more ontop of things. Other than that, I'm excited on helping other java students like myself. And I still have tons of questions that need answering also...

Nice meeting you guys!

Dean_Grobler 48 Posting Whiz in Training

Hi there!

Okay so the difference between Swing and an Applet..

Applets are little programs imbedded in websites/HTML pages.
Applets also are more commonly used for small single tasks in
webpages.

Swing programs however, would probably be the better choice
in your situation. Swing acctualy refers to a class in the
java language that defines/handles GUI(Graphical user interface)
components like(like buttons, labels, textfields etc).

So just depends what program you want. Do you want a standalone java
program (swing) or do you want a java program imbedded in a website(applet).

Hope this helps!