Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


morris
Applets
2 Answer(s)      4 years and 8 months ago
Posted in : IDE Questions


Someone please help how to solve this JAVA programs
a)An applet that does the following. Takes as input three numbers, computes two numbers and prints these two numbers (interest and amount) out. Have three textfields to input the three numbers (principal, rate and the number of years). With three five top-level variables: simpleInterest, amount, principal, numYears, rate.

B)program that will have the buttons one, two and three run from left to right along the top of the frame

C) Program that tosses a coin several times until head it obtains 10 heads. it should also record number of tails.

Thanks






























































Advertisement
View Answers

April 17, 2010 at 3:55 PM


Hi Friend,

a)

AppletForm.java

import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;

public class AppletForm extends Applet implements ActionListener {
Label l1,l2,l3,l4,l5;
TextField t1,t2,t3;
Button b;
Panel p;

public void init(){
l1=new Label("Principal");
l2=new Label("Rate Of Interest (in %)");
l3=new Label("Number of years");
l4=new Label();
l5=new Label();
t1=new TextField(20);
t2=new TextField(20);
t3=new TextField(20);

p=new Panel(new GridLayout(5,2));
b = new Button("Calculate");
b.addActionListener(this);
p.add(l1);
p.add(t1);
p.add(l2);
p.add(t2);
p.add(l3);
p.add(t3);
p.add(l4);
p.add(l5);
p.add(b);
add(p);
}
public void actionPerformed(ActionEvent e){
double principal=Double.parseDouble(t1.getText());
double rate=Double.parseDouble(t2.getText());
double years=Double.parseDouble(t3.getText());
double simpleInterest=principal*rate*years/100;
double amount=simpleInterest+principal;
l4.setText("Simple Interest= "+Double.toString(simpleInterest));
l5.setText("Amount= "+Double.toString(amount));
}
}


April 17, 2010 at 4:04 PM


continue..

2)ButtonForm.java:

import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;

public class ButtonForm extends Applet{
Button b1,b2,b3;
Panel p;

public void init(){
p=new Panel();
b1 = new Button("One");
b2 = new Button("Two");
b3 = new Button("Three");
p.add(b1);
p.add(b2);
p.add(b3);
add(p);
}
}

3)Toss.java:

class Toss{
public final int HEADS = 0;
static int countH=0;
static int countT=0;

private static int face;
public static void flip(){
face = (int) (Math.random() * 2);
}
public String toString(){
String faceName;
if (face == HEADS){
faceName = "Heads";
countH++;
}
else{
faceName = "Tails";
countT++;
}
return faceName;
}
public static void main (String[] args) {
do{
flip();
System.out.println(new Toss().toString());
}
while (countH!=10);
System.out.println("Number of Tails: "+countT);
}
}

Thanks


Related Tutorials/Questions & Answers:
Applets?
Applets?  applets are using now a days   Please visit the following link: Applet Tutorials
APPLETS - Security
APPLETS  In java applets sun.misc is not working can any body help me for the alternate solution. while using new sun.misc.BASE64Encoder().encode(enc); i got runtime error... java.security.AccessControlException
Advertisements
Applications and Applets
Applications and Applets       Now a days, Java is widely used for applications and applets. The code... the user's browser. Applets can be very useful, user friendly programs or can
Applications and Applets
Applications and Applets       Now a days, Java is widely used for applications and applets. The code... the user's browser. Applets can be very useful, user friendly programs or can
Servlet v/s Applets - Servlet Interview Questions
Servlet v/s Applets  what is difference between servlets & applets
Programming using applets and oracle - Applet
Programming using applets and oracle  Develop an Online Examination software in java using applets as front end and oracle as back end. Software should handle at least ten users at a time. There are Multiple Choice questions
Applets in Java
Applet is a Java program embedded within HTML pages. Java applets is compatible with almost all the web browsers like Mozilla Firefox, Google Chrome, Internet explorer, Netscape navigator and others that are java enabled. Applets
Free Java Applets
Free Java Applets       There are many free java applets available on the web that you can use in your website. These applets includes menu, clock, slide show, image animation
Should we go for javascript or applets for online exam project using java
Should we go for javascript or applets for online exam project using java  Hi, I am new to java and i am working on online examination project.As soon as the candidate login successfully a window pop up should appear
Role of Java Applets in Web Application Development
In this article, we are discussing about the role of Java Applets in web application development. As we all know that an Applet is a simple Java program, which is written in Java programming language that extends the java.applet.
I am new to java applets. When i run this code on applet viewer status is displayed that applet not initialized
I am new to java applets. When i run this code on applet viewer status is displayed that applet not initialized  import java.awt.*; import java.awt.event.*; import java.applet.*; public class Textfields extends Applet implements
What is Applet in Java?
computer. Applets are used to make the web site more dynamic and entertaining. The main difference between Java based applications and applets...? Applets are cross platform and can run on Windows, Mac OS and Linux platform
Java Applet
Applets are Java programs that run on java enabled web browser. Java applets can run on client servers with some restrictions. Applets are embedded into HTML...: There are various advantages of using Java Applets: They can run on any
Applet versus Application
;    Applets as previously described, are the small programs while applications are larger programs. Applets don't have the main method while in an application execution starts with the main method. Applets can run in our
Free Java stuffs
for cell phones Free Java Applets
Java JAR Files
Java JAR Files       A JAR file is a collection of  class files and auxiliary resources associated with applets and applications. The Java Archive (JAR) file format enables
<APPLET> Tag Parameters: The <PARAM> Tag
directly to a Java applet. Parameters are to applets what command-line... to applets are: First, add the PARAM tag (with values) to the HTML source file... These parameter values are retrieved by Java applets using the getParameter() method
Java Update
Update 2 provides improved behavior for applets in Safari and increased stability.... The Kernel online installer lets first time Java users run applets... Java applets and applications and any additional libraries that may
The Java Applet Viewer
; Applet viewer is a command line program to run Java applets... that inherits the Applet. We generally use web browsers to run applets. Its not always... that acts as a test bed for Java applets. The working of Applet viewer is a bit
Java hello world
Java hello world       Java is a high-level object-oriented programming language developed by the Sun Microsystems and is available in different form like JSP, Java Applets, J2EE
 

 

 

DMCA.com