Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

please help me with my coding errors

 
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);
}
}
 
Author
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.
 
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic