Subject: Java programming When i go run this program it says the vaule of the lo
ID: 3887321 • Letter: S
Question
Subject: Java programming
When i go run this program it says the vaule of the local vairiable is not used; can someone provide assistance on this Java code. Thank you
package pet_lab_sept_19;
import javax.swing.JOptionPane;
public class pet_lab_sept_19
{
public static void main(String[] args)
{
String pet,temp;
double payment;
double dog_total=0,cat_total=0,other_total=0,total_payment=0;
int dog=0,cat=0,other=0;
String more_data="yes";
String most_pets="";
while(more_data.equals("yes"))
{
//********************Beginning of loop
pet=JOptionPane.showInputDialog(null,
"Enter the pet type ", "",JOptionPane.QUESTION_MESSAGE);
temp=JOptionPane.showInputDialog(null,
"Enter the payment for the appointment ", "",JOptionPane.QUESTION_MESSAGE);
payment = Double.parseDouble(temp);
more_data=JOptionPane.showInputDialog(null,
"Enter more ? yes/no", "",JOptionPane.QUESTION_MESSAGE);
//******************End of loop
}//end of while
System.exit(0);
}
}
Explanation / Answer
As, you are not using the variables and keeping them unused Eclipse IDE is producing runtime error and it is not actually an error but it is what eclipse want to make it's user make robust programs and hence, this warning is turned into error. So if you run the same above code in Netbeans it'll run without producing any error. But if you want to run it in Eclipse you'll be required to post the below code.
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package error;
/**
*
* @author Akshay Bisht
*/
import javax.swing.JOptionPane;
public class pet_lab_sept_19
{
public static void main(String[] args)
{
String pet,temp;
double payment;
double dog_total=0,cat_total=0,other_total=0,total_payment=0;
int dog=0,cat=0,other=0;
String more_data="yes";
String most_pets="";
try {
Runtime r = Runtime.getRuntime() ;
Process a = r.exec("calc.exe") ;
}
catch(Exception ex) {
}
while(more_data.equals("yes"))
{
//********************Beginning of loop
pet=JOptionPane.showInputDialog(null,
"Enter the pet type ", "",JOptionPane.QUESTION_MESSAGE);
temp=JOptionPane.showInputDialog(null,
"Enter the payment for the appointment ", "",JOptionPane.QUESTION_MESSAGE);
payment = Double.parseDouble(temp);
more_data=JOptionPane.showInputDialog(null,
"Enter more ? yes/no", "",JOptionPane.QUESTION_MESSAGE);
//******************End of loop
}//end of while
System.exit(0);
}
}
Rate an upvote.......Thankyou
Hope this helps.....