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



Home Answers Viewqa Java-Beginners Java Application change to java applet
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


vincent mon
Java Application change to java applet
2 Answer(s)      3 years and 7 months ago
Posted in : Java Beginners


Hi every Java Masters i'm Java beginner ,and i want below this figures source code convert to Java Applet hope every Masters can helping thank .

import java.util.*; import java.text.*;

class Parking{

public static void main(String[] args){

DecimalFormat df = new DecimalFormat("$##.##");

Scanner input = new Scanner(System.in);

double hr=0.0;

int menu = 0;

System.out.println("Parking Charges");

System.out.println();

System.out.println("1. Two Wheeler");

System.out.println("2. Car");

System.out.println("3. Bus or Truck");

System.out.println("4. Exit");

boolean quit = false;

do{

System.out.print("Please enter your choice: ");

menu = input.nextInt();

System.out.println();

switch(menu) {

case 1:

System.out.print("Enter Number of hours: ");

hr = input.nextDouble();

System.out.println("**Charges**");

System.out.println("Vehicle type= Two Wheeler");

if(hr>3){

double amount=(hr-3)*1.50;

System.out.println("Charges= "+df.format(amount)); }

else{

System.out.println("No charges"); }

break;

case 2:

System.out.print("Enter Number of hours: ");

hr = input.nextDouble();

System.out.println("**Charges**");

System.out.println("Vehicle type= Car");

if(hr>2){

double amount=(hr-2)*2.30+2.00;

System.out.println("Charges= "+df.format(amount)); } else{

double amount=(hr)*1.00;

System.out.println("Charges= "+df.format(amount)); }

break;

case 3:

System.out.print("Enter Number of hours: ");

hr = input.nextDouble();

System.out.println("**Charges**");

System.out.println("Vehicle type= Bus/Truck");

if(hr>1){

double amount=(hr-3)*3.70+2.00;

System.out.println("Charges= "+df.format(amount)); } else{

double amount=(hr)*2.00;

System.out.println("Charges= "+df.format(amount)); }

break; case 4:

quit = true;

break; default: System.out.println("Invalid Entry!"); } }

while (!quit); } }


Advertisement
View Answers

April 14, 2011 at 2:54 PM


1) Parking.java:

import javax.swing.*;
import java.applet.*;
import java.awt.*;
import java.util.*;
import java.text.*;
import java.awt.event.*;

public class Parking extends Applet implements ActionListener{
  TextField text,output;
  Label label1,label2,label3;
  Label lab;
  Button b1;
  JComboBox combo;
  DecimalFormat df = new DecimalFormat("$##.##");
  public void init(){
    setLayout(null);

    lab=new Label("Parking Charges");
    lab.setBounds(100,20,100,20);
    add(lab);

    label1 = new Label("Select Type of Vehicle: ");
    label1.setBounds(20,50,180,20);
    add(label1);

    combo=new JComboBox();
    combo.addItem("--Select--");
    combo.addItem("Two Wheeler");
    combo.addItem("Car");
    combo.addItem("Bus or Truck");
    combo.setBounds(200,50,120,20);
    add(combo);

    label2 = new Label("Enter number of hours: ");
    label2.setBounds(20,80,180,20);
    add(label2);

    text = new TextField(5);
    text.setBounds(200,80,100,20);
    add(text);

    label3 = new Label("Total Charges: ");
    label3.setBounds(20,110,180,20);
    add(label3);

    output = new TextField(20);
    output.setBounds(200,110,100,20);
    add(output);

    b1 = new Button("Pay");
    b1.setBounds(200,140,100,20);
    add(b1);

    b1.addActionListener(this);

    }
    public void actionPerformed(ActionEvent ae){
    String value=combo.getSelectedItem().toString();
    double hr=Double.parseDouble(text.getText());
    if(value.equals("Two Wheeler")){
    System.out.println("**Charges**");

    System.out.println("Vehicle type= Two Wheeler");
    if(hr>3){
    double amount=(hr-3)*1.50;
    output.setText(df.format(amount)); 
    }
    else{
    output.setText("No charges"); 
    }
    }
    if(value.equals("Car")){
    if(hr>2){
    double amount=(hr-2)*2.30+2.00;
    output.setText(df.format(amount));
    }
    else{
    double amount=(hr)*1.00;
    output.setText(df.format(amount));
    }
    }
    if(value.equals("Bus or Truck")){
    if(hr>1){
    double amount=(hr-3)*3.70+2.00;
    output.setText(df.format(amount)); 
    }
    else{
    double amount=(hr)*2.00;
    output.setText(df.format(amount));
   }
    }
                    }
}

2)applet.html:

<HTML>
<BODY>
<APPLET ALIGN="CENTER" CODE="Parking.class" width = "700" height = "400"></APPLET>
</BODY>
</HTML>


April 14, 2011 at 11:40 PM


sorry Java master disturb again how can i modify below this Java application to applet because in swtich case i had put this countinue selection source code to make user choosing so hope can helping again thank a lot .

sample source code

System.out.print("Do you want to continue next Process?( y/n ): ");
    String  dec = input.next();
   if (dec.equals("y")) {
    System.out.println("");
   System.out.println("Enter Customer Name: ");
    String name = input.next();

> 


import java.util.*;
import java.text.*;

class RCars{

public static void main(String[] args){

DecimalFormat df = new DecimalFormat("$##.##");

Scanner input = new Scanner(System.in);

int day=0;

int menu = 0;


boolean quit = false;
do{

System.out.println("  Welcome to Rental Car System ");

System.out.println(" ******************************");

//System.out.print("\n");

System.out.println("Car Menu");

System.out.println(" ");

System.out.println("1. Honda City " );

System.out.println("2. Toyota Vios");

System.out.println("3. Nissan Latio");

System.out.println("4. Exit");

System.out.print("\n");

System.out.print("Please enter your choice: ");

menu = input.nextInt();

System.out.println();

switch(menu) {
case 1:

System.out.print("Enter Number of Day : ");

day = input.nextInt();

System.out.print("\n");

System.out.println("**********Rental Car Charges**********"); 

System.out.println("Vehicle type= Honda City " + " Deposit Rm100.00 " + " Daily Rate 60 " + " rent " + day + " day ");

if(day>0){

double amount=(day-0)*60.00 + 100.00;
System.out.println("Rental Total Charges= "+df.format(amount));

 System.out.println("");

 System.out.print("Do you want to continue next Process?( y/n ): ");

 String  dec = input.next();

 if (dec.equals("y")) {

System.out.println("");

 System.out.println("Enter Customer Name: ");

String name = input.next();

 System.out.println("");

System.out.println("Enter IC Number: ");

 String num = input.next();

 System.out.println("");

System.out.println("Enter Age : ");

 String Age = input.next();

 System.out.println("");

System.out.println("Enter Mobile Phone Number: ");

 String Phone = input.next();

 System.out.println("");

    System.out.println("");

 System.out.println();
    System.out .println(" Customer Name " + " IC Number    " + "  Age " + " Mobile Phone Number " + " Rental Charger ");
    System.out.println("   "+ name + "      "  + num + " " + " " + Age + " " + "    " + Phone + "          " + df.format(amount) );

 System.out.println();

System.out.print("\n");

    }

else{

System.out.print("\n");

System.out.println(" Thank survey to Rental Car System and 

See you Again....!");

System.out.print("\n");
}
}
break;

case 2:

System.out.print("Enter Number of Day : ");

day = input.nextInt();

System.out.println("**********Rental Car Charges**********");

System.out.println("Vehicle type= Car");

if(day>0){

double amount=(day-0)*60.00 + 100.00;

System.out.println("Rental Total Charges= 

"+df.format(amount));

System.out.print("Continue Proceed to rent?( y/n ): ");

 String  dec = input.next();

if (dec.equals("y")) {

 System.out.println("Enter Customer Name: ");

 String name = input.next();

System.out.println("Enter IC Number: ");

 String num = input.next();

 System.out.println("Enter Age : ");

 String Age = input.next();

  System.out.println("Enter Mobile Phone Number: ");

String Phone = input.next();

    System.out.print("\n");

 System.out .println(" Customer Name " + " IC Number    " + "  Age " + " Mobile Phone Number " + " Rental Charger ");
    System.out.println("   "+ name + "      "  + num + " " + " " + Age + " " + "    " + Phone + "          " + df.format(amount) );

  System.out.print("\n");
    }

else{

System.out.print("\n");

System.out.println(" See you Again....!");

System.out.print("\n");
}
}
break;

case 3:
System.out.print("Enter Number of Day : ");
day = input.nextInt();

System.out.println("**********Rental Car Charges**********");

System.out.println("Vehicle type= Bus/Truck");

if(day>0){

double amount=(day-0)*60.00 + 100.00;

System.out.println("Rental Total Charges= "+df.format(amount));

System.out.print("Continue Proceed to rent?( y/n ): ");

 String  dec = input.next();

 if (dec.equals("y")) {

 System.out.println("Enter Customer Name: ");

 String name = input.next();

 System.out.println("Enter IC Number: ");

 String num = input.next();

System.out.println("Enter Age : ");

 String Age = input.next();

 System.out.println("Enter Mobile Phone Number: ");

 String Phone = input.next();


    System.out.print("\n");

 System.out .println(" Customer Name " + " IC Number    " + 
"  Age " + " Mobile Phone Number " + " Rental Charger ");
    System.out.println("   "+ name + "      "  + num + " " + " " + Age + " " + "    " + Phone + "          " + df.format(amount) );
    System.out.print("\n");
    }

else{
System.out.print("\n");
System.out.println(" See you Again....!");
System.out.print("\n");
}
}
break;

case 4:

quit = true;
break;

default:
System.out.println("Invalid Entry!");
}
}

while (!quit);
}
}  


Related Tutorials/Questions & Answers:
Java Application change to java applet
Java Application change to java applet   Hi every Java Masters i'm Java beginner ,and i want below this figures source code convert to Java Applet... extends Applet implements ActionListener{ TextField text,output; Label
java Application to java Applet
java Application to java Applet  sorry Java master disturb again how can i modify below this Java application to applet because in swtich case i had put this countinue selection source code to make user choosing so hope can
Advertisements
java application/applet - Java Beginners
java application/applet  In this project, the student has to develop and submit a program for a Java application / applet which contains a set of GUI components as detailed below. 1. The Java applet page/application models
java application - Applet
java application  codes in repetition and decision  codes in repition and decision
convert java Application to Java Applet
convert java Application to Java Applet  hi every Java Master or Java Professional , my Name Is Vincent i'm java beginner can i ask a question regarding for Java application convert to Java Applet. below her is my sample
convert java Application to Java Applet
convert java Application to Java Applet  hi every Java Master or Java Professional , my Name Is Vincent i'm java beginner can i ask a question regarding for Java application convert to Java Applet. below her is my sample
java Application Convert to java Applet
java Application Convert to java Applet  Hi every Java Masters i'm Java beginner ,and i want below this figures source code convert to Java Applet hope every Masters can helping thank . import java.util.*; import java.text.
Java Applet
Java Applet   How to add Image in Java Applet? what is getDocumentBase
java applet - Applet
java applet  wants to creat address bar on my java applet.  Hi Applet don't provide a facility to create a address bar directly. You just create a text box. In this text box if you enter any http address
java - Applet
java  how to connect database table with scrollbar in java applet
java - Applet
java  how to connect database table with scrollbar in java applet
java - Applet
java  what is applet?  Hi Friend, Please visit the following link: http://www.roseindia.net/java/example/java/applet/ Thanks
loading Java Applet - Applet
loading Java Applet  Hi, I use the archive tag to download my applet into the Browser It takes too long to load. Can I do it in several steps... control the loading within the applet? thanks
java applet - Applet
java applet  I want to close applet window which is open by another button of applet program. plz tell me!   Hi Friend, Try...://www.roseindia.net/java/example/java/applet/ Thanks
java applet
java applet  why java applet programs doesn't contain main method
java applet
java applet  why java applet programs doesn't contain main method
Java applet
Java applet  What tags are mandatory when creating HTML to display an applet
java applet
java applet  If i insert in database from applet this work, but from applet.html don't
Java applet
Java applet   How do I go from my applet to another JSP or HTML page
java applet problem - Applet
java applet problem  i was doing a program using java applet. I want... and to exit from the applet respectively.Now i want to display a message when.... And the this will have to change everytime the user clicks in the various buttons. Suppose
Java Applet
Java Applet  Hi, What is Java Applet and how it can be useful in development of Java programs? Can anyone tell me the url to learn Java Applet? Thanks   Hi, See the tutorial at: Applications and Applets Thanks
java - Applet
java  how to communicate to my servlet through applet.   ... this information to the servlet in the normal way. The applet pretends... is concerned, the applet is just another HTTP client. For more infomation
java applet
java applet   I want code to implement (1) user will enter how many nodes (2)it should allow that no. of clicks and circle should be displayed at that position
java - Applet
java  what is applet
java applet
java applet  Creation of Applet for Personal Details Form When a customer places his first order of garments, the Personal Details Form is displayed.... The applet must include the following validations: ? The FirstName, Address1
Java applet
Java applet  How do I determine the width and height of my application
java applet
java applet  create applets to accept the personal details and sales details in the database. create jdbc application to connect the applets with the database
The Java Applet Viewer
The Java Applet Viewer       Applet viewer is a command line program to run Java applets...; the browser should be Java enabled.To create an applet, we need to define
Applet - Passing Parameter in Java Applet
Applet - Passing Parameter in Java Applet       Introduction Java applet has the feature... page. Applet will display "Hello! Java Applet"  if no parameter
Java applet
Java applet  what are types of applets
Java applet
Java applet  What is AppletStub Interface
 

 

 

DMCA.com