plz help to find the mistake.....beginner

M

madanmohan

hey guys..m a beginner in java...m not able to print the data in the
following data...no errors,tis takin input successfully.
please help me to find the flaw...plzzzzzzzzz....!!!!!!!please edit
the code if required!!!!


HERE'S THE CODE:

import java.util.Scanner;
class mix
{
public static void main(String args[])
{
String name;
String education;
int age;
int contract;
int payment;
System.out.println("\nWELCOME TO MADANS FIRST JAVA PRACTICE
PROGRAM(hehe...)\n");
System.out.println("\nEnter canditate's name: ");
Scanner input = new Scanner(System.in);
name = input.nextLine();
System.out.println("\nEnter employers education: ");
education = input.nextLine();
System.out.println("\nEnter employers age: ");
age = input.nextInt();
System.out.println("\nEnter employers contract period: ");
contract = input.nextInt();
System.out.println("\nEnter employers salary/year: ");
payment = input.nextInt();

fresher emp = new fresher();
salary empsal = new salary();
emp.fresher(name,education,age);
empsal.salary(contract,payment);

printstatus display = new printstatus();
display.toprint();
System.out.println("\n\nTHANKING MYSELF FOR RUNNING THE PROGRAM
SUCCESSFULLY");
}
}
class printstatus
{
void toprint()
{
fresher details = new fresher();
details.showdata();
salary pay = new salary();
pay.paymentdetails();
}
}

class fresher
{
String name;
String education;
int age;
void fresher(String name,String education,int age)
{
name=name;
age=age;
education=education;
}
void showdata()
{
System.out.println("\n\n----------------EMPLOYEE
DETAILS--------------");
System.out.println("NAME : "+name);
System.out.println("QUALIFICATION : "+education);
System.out.println("AGE : "+age);
if(age>28)
{
System.out.println("APPLICATION STATUS : SORRY,YOUR APPLICATION HAS
NOT BEEN NOT ACCEPTED");
}
else
{
System.out.println("APPLICATION STATUS : ACCEPTED SUCCESSFULLY!!");
}
}
}

class salary extends fresher
{
int contract;
int payment;
int totalpayment;
void salary(int freshercontract,int fresherpayment)
{
contract=freshercontract;
payment=fresherpayment;
}
void paymentdetails()
{
if(age>28)
{
System.out.println("AMOUNT PAID IS :Rs.0000");

}
else
{
System.out.println("CONTRACT PERIOD : "+contract+"years");
System.out.println("SALARY : Rs."+payment);
System.out.println("GROSS AMOUNT TO BE PAID : Rs."+
(contract*payment));
System.out.println("IN-HAND PAYMENT RECEIVED :
Rs."+(0.4*contract*payment));
}
}
}
 
E

Evans

hey guys..m a beginner in java...m not able to print the data in the
following data...no errors,tis takin input successfully.
please help me to find the flaw...plzzzzzzzzz....!!!!!!!please edit
the code if required!!!!

HERE'S THE CODE:

import java.util.Scanner;
class mix
{
        public static void main(String args[])
        {
                String name;
                String education;
                int age;
                int contract;
                int payment;
                System.out.println("\nWELCOME TO MADANS FIRST JAVA PRACTICE
PROGRAM(hehe...)\n");
                System.out.println("\nEnter canditate's name: ");
                Scanner input = new Scanner(System.in);
                name = input.nextLine();
                System.out.println("\nEnter employers education: ");
                education = input.nextLine();
                System.out.println("\nEnter employers age: ");
                age = input.nextInt();
                System.out.println("\nEnter employers contract period: ");
                contract = input.nextInt();
                System.out.println("\nEnter employers salary/year: ");
                payment = input.nextInt();

                fresher emp = new fresher();
                salary empsal = new salary();
                emp.fresher(name,education,age);
                empsal.salary(contract,payment);

                printstatus display = new printstatus();
                display.toprint();
                System.out.println("\n\nTHANKING MYSELF FOR RUNNING THE PROGRAM
SUCCESSFULLY");
        }}

class printstatus
{
        void toprint()
        {
                fresher details = new fresher();
                details.showdata();
                salary pay = new salary();
                pay.paymentdetails();
        }

}

class fresher
{
        String name;
        String education;
        int age;
        void fresher(String name,String education,int age)
        {
                name=name;
                age=age;
                education=education;
        }
        void showdata()
        {
                System.out.println("\n\n----------------EMPLOYEE
DETAILS--------------");
                System.out.println("NAME : "+name);
                System.out.println("QUALIFICATION : "+education);
                System.out.println("AGE : "+age);
                if(age>28)
                {
                        System.out.println("APPLICATION STATUS : SORRY,YOUR APPLICATION HAS
NOT BEEN NOT ACCEPTED");
                }
                else
                {
                        System.out.println("APPLICATION STATUS : ACCEPTED SUCCESSFULLY!!");
                }
        }

}

class salary extends fresher
{
        int contract;
        int payment;
        int totalpayment;
        void salary(int freshercontract,int fresherpayment)
        {
                contract=freshercontract;
                payment=fresherpayment;
        }
        void paymentdetails()
        {
                if(age>28)
                {
                        System.out.println("AMOUNT PAID IS :Rs.0000");

                }
                else
                {
                        System.out.println("CONTRACT PERIOD : "+contract+"years");
                        System.out.println("SALARY : Rs."+payment);
                        System.out.println("GROSS AMOUNT TO BE PAID : Rs."+
(contract*payment));
                        System.out.println("IN-HAND PAYMENT RECEIVED  :
Rs."+(0.4*contract*payment));
                }
        }

}

You didn't say what you were expecting to output. Its hard to know
when it is/not working when we don't know what to look out for.
 
D

Donkey Hottie

Objects are like variables.

You can't do this

int a = 1 ;
int b ;
print b;

and expect it to print "1".

In your program you construct an object variable, and set it's properties.
In your print routine you construct new objects of the same kind, and
somehow expect that they have the value of the other objects of same kind.

It just does not work that way, usually. Objects are self contained
independent entities.

A class is a type, an object is an instance of said type.
 
N

Nostalgia

Objects are like variables.

You can't do this

int a = 1 ;
int b ;
print b;

and expect it to print "1".

In your program you construct an object variable, and set it's properties..
In your print routine you construct new objects of the same kind, and
somehow expect that they have the value of the other objects of same kind..

It just does not work that way, usually. Objects are self contained
independent entities.

A class is a type, an object is an instance of said type.

Hello!
I completely agree with DH, seems like you have got it all wrong!
Though it surprises me for a person who has managed to write this long
piece of code, is unable to figure out basics of classes n objects!

When you take values from user, and assign it to some object, you need
pass the same object around to do further operations on it or with it.

regards,
 
J

John B. Matthews

madanmohan said:
hey guys..m a beginner in java...m not able to print the data in the
following data...no errors,tis takin input successfully. please help
me to find the flaw...plzzzzzzzzz....!!!!!!!please edit the code if
required!!!!
[...]

You need to study constructors more and adopt a more readable style with
less SHOUTING:

<http://java.sun.com/docs/books/tutorial/java/javaOO/constructors.html>

Let's take a step back: After you have collected your data in main(),
create a new Fresher instance with the values you just collected and
tell the instance to print the results:

Fresher emp = new Fresher(name, education, age);
emp.showData();

Here is a more readable version of your Fresher class. Note how the
constructor parameters match up:

class Fresher
{
String name;
String education;
int age;

public Fresher(String name, String education, int age)
{
this.name = name;
this.education = education;
this.age = age;
}

void showData()
{
System.out.println("\n\n-----Employee Details-----");
System.out.println("Name : " + name);
System.out.println("Qualification : " + education);
System.out.println("Age : " + age);
System.out.print("Application Status : ");
if(age > 28)
{
System.out.println("Failed");
}
else
{
System.out.println("Accepted");
}
}
}

Now it's your turn.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Void problem 1
School Project 1
Java Help - Beginner 12
Java method query 2
Console Input Error-2 0
Nothing prints when I compile my code 3
Java Help for a Beginner 9
SQLite issue 3

Members online

No members online now.

Forum statistics

Threads
473,717
Messages
2,569,382
Members
44,704
Latest member
FawnBernay

Latest Threads

Top