0
My code is not running
8 odpowiedzi
+ 5
@Syed, try the above code. In main(), we call the functions u have defined. As the same variables' instances are used in all the functions, we should declare them as static. With these modifications, this code compiles now.
+ 1
yes, please share your code and the compiler(IDE) you are using..
+ 1
I think main () statement is required which is missing in your code..
+ 1
import java.io.*;
class Syed
{
static String name;
static String address;
static int phone;
static String subject;
static float salary;
static float tax;
public static void inputdata(String n,String a,int p,String s,float sal)
{
name = n;
address = a;
phone = p;
subject = s;
salary = sal;
}
public static void displaydata()
{
System.out.println ("===============");
System.out.println("Name="+name);
System.out.println("Address="+address);
System.out.println("Phone Number="+phone);
System.out.println("Subject Specialization="+subject);
System.out.println("Monthly Salary="+salary );
}
public static void compute()
{
float totalsal;
totalsal=(float)12.0*salary;
if(totalsal>175000)
{
System.out.println("Annual Salary(salary*12)") ;
tax=(totalsal-175000)*5/100;
System.out.println("Annual Income Tax is="+tax);
}
else
System.out.println("No Tax Amount on this Income:");
}
public static void main (String [] args)
{
inputdata("Syed","address",4608,"Accounts",6 );
displaydata ();
compute();
}
}
0
share your code so we can see whats wrong....
0
import java.io.*;
class tax
{
private String name;
private String address;
private int phone;
private String subject;
private float salary;
private float tax;
public void inputdata(String n,String a,int p,String s,float sal)throws IOException
{
name = n;
address = a;
phone = p;
subject = s;
salary = sal;
}
void displaydata()
{
System.out.println ("===============");
System.out.println("Name="+name);
System.out.println("Address="+address);
System.out.println("Phone Number="+phone);
System.out.println("Subject Specialization="+subject);
System.out.println("Monthly Salary="+salary );
}
public void compute()
{
float totalsal;
totalsal=(float)12.0*salary;
if(totalsal>175000)
{
System.out.println("Annual Salary(salary*12)") ;
tax=(totalsal-175000)*5/100;
System.out.println("Annual Income Tax is="+tax);
}
else
System.out.println("No Tax Amount on this Income:");
}
}
0
sir
please edit
0
he is right. without a main() your program doesn't have a start