Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,153,479 members, 7,819,748 topics. Date: Monday, 06 May 2024 at 10:10 PM

Programing With Java - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Programing With Java (4041 Views)

Learning To Program With Java by the Fulaman / Is It Advisable To Start Learning Programing With C++ / Which Programing Language Is Best To Start With (2) (3) (4)

(1) (2) (3) (Reply) (Go Down)

Programing With Java by emeka4luv: 8:11am On Aug 06, 2013
Pls can u help me with the code for a program, it is an assignment that was given to me in skul, = creat a class called employee that include 3 piece of information as instant variable(first name , last name, monthly salary) your class shuld hav a constructor that initisalise the 3 instan variable, provid a set and get method for each instant varieble, writ a test app dat demostrat as employee capability, creat 2 employee object and display its object yealy salay, then giv each employee a 10% raise and display each yealy salary.
Re: Programing With Java by emmanwandud(m): 8:49am On Aug 06, 2013
Import.java.util
Public static void main(string args)(
Inbox me to get the rest

2 Likes

Re: Programing With Java by Knownpal(m): 5:46am On Aug 07, 2013
import java.io.*;
public class Employee{String firstName, lastName; double monthlySalary;
public Employee(String welc){System.out.println(welc);}
public setFirstName(String fName){firstName=fName}
public getFirstName(){System.out.println(firstName); return firstName;}
public setLastName(String lName){ lastName=lName}
public getLastName(){ System.out.print(" "+lastName); return lastName;}
public void setmonthlySalary(double salary){ monthlySalary=salary} public void double getmonthlySalary()

1 Like

Re: Programing With Java by Knownpal(m): 6:07am On Aug 07, 2013
{ System.out.println("Salary: "+monthlySalary); return monthlySalary;}
public void main(String args[]({ Employee emp = new Employee("Welcome"wink;
emp.setFirstName("Emmy"wink; emp.getFirstName();
emp.setLastName("Charles"wink;
emp.getLastName();
emp.setmonthlySalary(600000.00);
emp.getmonthlySalary();
int a = 10/100*monthlySalary;
System.out.println("Salary after been raised by 10% is: " + monthlySalary + a);} } }

1 Like

Re: Programing With Java by Knownpal(m): 6:09am On Aug 07, 2013
Jesus!! What has Java got to do with this. Replace those smiley with )
Re: Programing With Java by Knownpal(m): 6:10am On Aug 07, 2013
Jesus!! What has Java got to do with this. Replace those smileys with )
Re: Programing With Java by danvery2k6(m): 8:14pm On Aug 07, 2013


/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package nairaland;

/**
*
* @author HP USER
*/
public class Employee {

//employee information(Biodata and salary)
private String firstName;
private String lastName;
private double monthlySalary;

//constructor to initialise the employee instance variables
public Employee(String first, String last, double salary){
firstName = first;
lastName = last;
monthlySalary =salary;
} //getter and setter methods for employee instance variables
public void setFirstName(String first){
firstName = first;
}
public String getFirstName(){
return firstName;
}
public void setLastName(String last){
lastName = last;
}
public String getLastName(){
return lastName;
}
public void setMonthlySalary(double amount){
if(amount > 0.0){
monthlySalary = amount;
} else{
monthlySalary = 0.0;
}
}
public double getMonthlySalary(){
return monthlySalary;
}
public double raise(){
double newSalary = getMonthlySalary()+
getMonthlySalary()*0.1;
return newSalary;
}
}


1 Like

Re: Programing With Java by danvery2k6(m): 8:26pm On Aug 07, 2013


/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package nairaland

/**
*
* @author HP USER
*/
public class Main {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Employee employee = new Employee("John", "Doe", 500);
System.out.printf("Monthly salary before raise is: N%.2f\n", employee.getMonthlySalary());
System.out.printf("Monthly salary after %s raise is N%.2f\n","10%",employee.raise() );
}
}

1 Like

Re: Programing With Java by mgb4reel(m): 12:47pm On Aug 08, 2013
emmanwandud: Import.java.util
Public static void main(string args)(
Inbox me to get the rest
oga...no class declaration now...and again, the solution wil av two java files..one of the java file wil hav the employe class declation that wil include the data members as wel as the set and get methods while the other java file wil hav the main method wherein you instantiate the class with the argument to match the employee constructor parameters
Re: Programing With Java by mgb4reel(m): 1:02pm On Aug 08, 2013
Known_pal: import java.io.*;
public class Employee{String firstName, lastName; double monthlySalary;
public Employee(String welc){System.out.println(welc);}
public setFirstName(String fName){firstName=fName}
public getFirstName(){System.out.println(firstName); return firstName;}
public setLastName(String lName){ lastName=lName}
public getLastName(){ System.out.print(" "+lastName); return lastName;}
public void setmonthlySalary(double salary){ monthlySalary=salary} public void double getmonthlySalary()
hmmm...kudos to u but am quite sure this program wil not even compile to bytecode,not to talk of running..this is because there are a lots of erors in the code you av writen..let me start from the method getmonthlySalary() declaration..u not only violate java method namin convention but u also use two return types for a method which is neva alowed..some of the method u declared abov do not even av a return type..note that al method delaration in java must av a return type except the constructor.there ar many oda eror dat i cannot mention here but my aim of doin this is just to let u kno so as to avoid such mistake in the future...together we can take programin 4rm where it is to where its ought to be...Kudos to u al

1 Like

Re: Programing With Java by mgb4reel(m): 1:19pm On Aug 08, 2013
P
danvery2k6:


/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package nairaland

/**
*
* @author HP USER
*/
public class Main {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Employee employee = new Employee("John", "Doe", 500);
System.out.printf("Monthly salary before raise is: N%.2f\n", employee.getMonthlySalary());
System.out.printf("Monthly salary after %s raise is N%.2f\n","10%",employee.raise() );
}
}

sincerely,u av done a very good job...nice one bro..kudos to u.the program wil compile and run quite alright but the program may not give the required output as the question demands..firstly we ar asked to create two objects of employee..it would av been nice if u can invoke getFirstName() and getLastName() methods so that the output wil also include the names of the salary owners.....but i realy like ur code bro cos u not only adhere to java naming conventions but u also follow oop concept by encapsulatin dose fields..kudos to u bro...Together, we wil take programing from where it is to where its ought to be!

3 Likes

Re: Programing With Java by Knownpal(m): 6:07pm On Aug 08, 2013
Thanks pal. Mistake noted, I did not compile the codes because I had no compiler to do so. Well thanks bro.
Re: Programing With Java by mgb4reel(m): 7:38pm On Aug 08, 2013
u are welcome know_pal..u can get the compiler by goin to oracle website...u get the java development kit(jdk) and netbeans...instal an enjoy...hav any prob? U can always ask! Together,we can take programing in nigeria from it is to where its ought to be!
Re: Programing With Java by Knownpal(m): 9:52pm On Aug 08, 2013
Thanks for the explanation I've got the compiler and have been compiling since these days, my system got faulty thats why am unable to compile.
Re: Programing With Java by olyjosh(m): 6:50am On Aug 09, 2013
[quote author=Known_pal]import java.io.*;
public class Employee{String firstName, lastName; double monthlySalary;
public Employee(String welc){System.out.println(welc);}
public setFirstName(String fName){firstName=fName}
public getFirstName(){System.out.println(firstName); return firstName;}
public setLastName(String lName){ lastName=lName}
public getLastName(){ System.out.print(" "+lastName); return lastName;}
public void setmonthlySalary(double salary){ monthlySalary=salary} public void double getmonthlySalary()[/quote


Hehehehe, this one go kill system ooo
Re: Programing With Java by Knownpal(m): 8:37am On Aug 09, 2013
^^^ Why you talk am ooooh
Re: Programing With Java by olyjosh(m): 1:52pm On Aug 09, 2013
Known_pal: ^^^ Why you talk am ooooh

WRONG CODE!!!
Re: Programing With Java by Knownpal(m): 2:11pm On Aug 09, 2013
^^^ I'm just learning ni now..In Fact I just got to methods. I was not aware of the rules before.
Re: Programing With Java by danvery2k6(m): 2:25pm On Aug 09, 2013
mgb4reel: P
sincerely,u av done a very good job...nice one bro..kudos to u.the program wil compile and run quite alright but the program may not give the required output as the question demands..firstly we ar asked to create two objects of employee..it would av been nice if u can invoke getFirstName() and getLastName() methods so that the output wil also include the names of the salary owners.....but i realy like ur code bro cos u not only adhere to java naming conventions but u also follow oop concept by encapsulatin dose fields..kudos to u bro...Together, we wil take programing from where it is to where its ought to be!
thanks bro. am on mobile right now. will upgrade next time am on pc
Re: Programing With Java by Knownpal(m): 3:55pm On Aug 09, 2013
Whats the difference between a constructor and a method #with examples please.
Re: Programing With Java by mgb4reel(m): 10:25am On Aug 10, 2013
Known_pal: Whats the difference between a constructor and a method #with examples please.
A method is a unit of a class that perform a specific function or say task in a class. A constructor is also a method that is used to initialize instance variables of a class durin instantiation. A constructor name is exactly d same as dat of d class....an most importantly dos nt av a return type(not even void)
for example,
public class Employee{
private int value;
public Employee(int val){ // the constructor havin d clas name an does nt specify a return type
value = val; // initializin d instance variable
}
public int calculate(){ // a method whose return type is int
return value * value;
}
}
hope this help
Re: Programing With Java by Knownpal(m): 12:10pm On Aug 10, 2013
^^^ sure it does. Now whats the difference between public Employee{int val){//this is a constructor?}
and
pubic static int max(int num1, int num2) {//this is a method right?}
Re: Programing With Java by mgb4reel(m): 10:32am On Aug 11, 2013
Known_pal: ^^^ sure it does. Now whats the difference between public Employee{int val){//this is a constructor?}
and
pubic static int max(int num1, int num2) {//this is a method right?}
haha...this is a very trivial question...cant u see dat d constructor dos not specify a return type and it has d class name...or are u tryin to ask me how this methods are called? If yes, they ar indeed called diferently..whenever u create an object of this Employee class, you are automaticaly calling the constructor of the Employee class...i.e
Employee obj = new Employee(15); // this object i av created wil cal d Employee constructor..note dat d argument i passed during the object creation matches with the parameter specify in the Employee constructor.
Hope u undastand?
Now, to cal a method in class Employee you wil call it on an Employee object...like say
obj.calculate(); where calculate is a non static method in class Employee...but in the example u gave, u av a static method called max there...to cal a static method,u dont need to create an object of the class to call it...just cal it on the class name...as in Employee.max(15,17); since ur static method max specify two int parameters.
I hope u ar clear now? Stil confused? Ask more!!

1 Like

Re: Programing With Java by danvery2k6(m): 7:33pm On Aug 12, 2013
Nice explanations bro. i wish this thread had been started a long time ago.
Re: Programing With Java by mgb4reel(m): 9:46pm On Aug 12, 2013
tanks.....
Re: Programing With Java by danvery2k6(m): 12:06pm On Aug 13, 2013
A company wants to send data over an unsecure connection. to ensure that the data reaches the destination safely, you have been asked to encrypt the data as follows. take a four digit number, separate the digits, subtract 7 from each digit, divide each digit by 10 and take the remainder. form a new four digit number with the remainders obtained. this will be the encrypted data. display your output please. thank you.
Re: Programing With Java by emeka4luv: 4:56pm On Sep 01, 2013
Tnx to u all u saved me, but realy i need to knw dis, am a young programer, i need advice from u guys and also books dat wil asist me in this, becouse there is a saying dat says "if you want to learn sumtin and knw it very well, u need to learn from the master dat y am asking u guys to help me, so dat 1 day i can help odas.
Re: Programing With Java by danvery2k6(m): 1:09pm On Sep 03, 2013
you can try [b]Java How to program by Deitel and Deitel.[/b]Very good book. Perhaps you might even find solutions to most of your school exercises there. Happy time with Java.
Re: Programing With Java by Knownpal(m): 1:59pm On Sep 03, 2013
Mgb4reel Yeah thanks.
Emeka I pray you see, I've been searching as well, but the great words are 'programmers are self-taught'.
Nice day!
Re: Programing With Java by mgb4reel(m): 7:37pm On Sep 03, 2013
@emeka...there ar more dan a thousand books out there on java ranging from dat of begineers to the advance level. U need to ask urself som questions
do u just wana learn java in orda to solve a particular problem dat u hav or do u wanna b a real java coder? If u realy want to do java..i recommend java how to program by paul deitel and harvey deitel 9th edition. U can download it for free online..just google it. Avin any problem on any aspect...u ar free to ask!
Re: Programing With Java by themanager: 12:08am On Sep 09, 2013
Hi guys ,am currently learning java,buh am having an issue with packaging.how do i go about packaging my java software so that i can distribute it easily.
Re: Programing With Java by mgb4reel(m): 2:55pm On Sep 09, 2013
themanager: Hi guys ,am currently learning java,buh am having an issue with packaging.how do i go about packaging my java software so that i can distribute it easily.
this depends on how u want your software/application/program to run on the user's system. I kno two ways of doing this...
1. U can create the .exe version of ur program using software like jar2exe, jsmooth downloadable through google.com...this wil convert ur .jar file to .exe file which u can run on most systems. This .exe version of ur program wil always run from its location i.e. It does not require instalation of d program
2. U can create an installable version of ur program using advance installer downloadable through google bt with a limited period of 30 days...if u try it an u like it, then i may teach u aw u wil use it free for life...Now, this wil create a .msi version of ur program from the .jar file. This .msi version will install the program just like every standard software u see i.e it wil b installed in ur program files on hard drive.
You can give the .msi or .exe version to ur friends to try and see...
Hope this help!
Having more challenge? Ask questions!!!

(1) (2) (3) (Reply)

Nairaland Programming Index(Topic Ordered Listing of Programming Board Threads). / How Can I Learn OOP With Java? / Challenge For Javascript Beginners/intermidiate

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 57
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.