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); } }
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>
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); } }