Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

please help me with my coding errors

 
Andries Letsela
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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);
}
}
 
Herb Schildt
Author
Ranch Hand
Posts: 253
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Andries Letsela
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanx i'll try t remember to declare all variables.
thanx millions times.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic