It's not a secret anymore!
The moose likes Java in General and the fly likes please help me with my coding errors Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "please help me with my coding errors " Watch "please help me with my coding errors " New topic
Author

please help me with my coding errors

Andries Letsela
Greenhorn

Joined: Oct 06, 2003
Posts: 3
public class Bursary
{
public Bursary(String aStudentNumber, String aBirthdate)
{
StudentNumber = aStudentNumber;
Birthdate = aBirthdate;
String message;
}
public int calcAge()
{
String sub = Birthdate.substring(0,4);
int Birthdate = Integer.parseInt(sub);
age = 2003 - Birthdate;
return age;
}
public int calcYear()
{
String sub = StudentNumber.substring(4,8);
int StudentNumber = Integer.parseInt(sub);
year = 2003 - StudentNumber;
return year;
}
public String determineBursary()
{
if(age >= 18 && age <= 25 && year <= 5)
message = "Accepted";
else
message = "Not accepted";
return message;
}
private String StudentNumber;
private String message;
private String Birthdate;
private int year;
private int age;
}

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.StringTokenizer;
public class BursaryTest
{
public static void main(String[] args) throws Exception
{
do
{
BufferedReader console = new BufferedReader(new InputStreamReader(System.in));
System.out.println("studentNumber");
String studentNumber = console.readLine();

System.out.println("birthdate");
String birthdate = console.readLine();

Bursary myBursary = new Bursary(studentNumber, birthdate);

System.out.println("Number of yearsEnrolled : " + myBursary.calcYear());
System.out.println("Your age is : " + myBursary.calcAge());
System.out.println("Bursary : " + myBursary.determineBursary());

System.out.println("Do you want to continue: Yes/No");
String ans = console.readLine();
}
while(input.equalsIgnoreCase("Yes"));
System.exit(0);
}
}


R Letsela.<br /> A
Herb Schildt
Author
Ranch Hand

Joined: Oct 01, 2003
Posts: 253
    
    6
I assume that BursaryTest and Bursary are in two separate files. Right?
In BursaryTest, input, which is used in this line
while(input.equalsIgnoreCase("Yes"));
is not declared anywhere. Remember, in Java, variables must be declared before they are used.


For my latest books on Java, including Introducing JavaFX 8 Programming, see HerbSchildt.com
Andries Letsela
Greenhorn

Joined: Oct 06, 2003
Posts: 3
Thanx i'll try t remember to declare all variables.
thanx millions times.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: please help me with my coding errors
 
It's not a secret anymore!