各位大哥大姐!
我是一个JAVA语言的初学者!更正确的说是一点基础都没有,刚学的时候连CLASS和OBJECT是什么关系都不知道!
由于我身在外国读书,于是我选了计算机科学来主修!
虽然说在国外书上讲的,老师说的~我都理解!但是毕竟不是母语还是比较困难!
最主要的是要给我一个例题~让我知道怎么编!毕竟这样比较好理解!
现在我有个简单的问题难倒了我!
题目是这样的!
/**
* Some methods to practice if statements on.
*
* @author Ray Hidayat
* @version 20 March 2008
*/
public class IfPractice
{
/**
* getAMPMString
* Given an hour of the day, returns "am" or "pm", whichever is appropriate
*
* @param hourOfDay the hour of the day, 0-23
NOTE: the above line is a special way to describe a parameter. The code @param
says the line will describe a parameter, 'hourOfDay' is the name of the parameter,
and 'the hour of the day, 0-23' is the parameter's description.
*
* @return "am" for hours 0-11, "pm" for hours 12-23
NOTE: the above line is a special way of describing what the method should return.
The code @return says the line will describe what the method returns.
*
*/
/*
* Below this comment is an example of how you can interpret the Javadoc comment above.
*
* Notice how the method signature below has a return type of String. For this lab you
* have four options for return types - boolean, int, double, or String, choose an
* appropriate type for each method.
*
* Also in the method signature below, the parameter hourOfDay is of type int.
* In the same way, for the other methods in this class, choose an appropriate type
* for each parameter, whether it be boolean, int, double or String.
*
* If you don't remember what boolean, int, double, or String are, refer to your lecture
* notes.
*/
public String getAMPMString(int hourOfDay){
String a = "am";
String p = "pm";
if (hourOfDay <=11)
{
if (hourOfDay >=0)
return a;
}
else if (hourOfDay <=23)
{
if (hourOfDay >=12)
return p;
}
return "";
} /**
* getGardeningCost
* Returns the cost of hiring a gardener for a certain amount of time.
* The gardener charges $25 per hour, and will always charge for at least
* 2 hours worth of work.
*
* Examples:
Input: 0.5 (hours)
Returns: 50 (dollars)
Input: 2 (hours)
Returns: 50 (dollars)
Input: 2.5 (hours)
Returns: 62.5 (dollars)
Input: 5 (hours)
Returns: 125 (dollars)
*
* @param hoursWorked the number of hours worked - must allow decimal places to be input
* @return the total cost of hiring the gardener
*/
public int getGardeningCost(int hours){
if (hours <=2)
{
if (hours >0)
return 50*1;
}
return hours * 25;
}
/**
* getMovieTicketPrice
* Returns the cost of a movie ticket for a person.
* Movie tickets cost $15 for adults, $12 for students, $8.50 for children
* aged 15 years or under. Children who are also students take the children's
* price.
*
* @param age the age of the person
* @param isStudent true if they're a student, false if not
* @return the movie ticket price
*/
/**
* isOverLimit
* Returns whether someone is over the breath alcohol limit for their age.
* People under 20 have a limit of 150 mg/litre of breath
* People 20 and over have a limit of 400 mg/litre of breath
*
* @param age the age of the person
* @param breathAlcohol the amount of breath alcohol the person has in mg/litre - must allow for decimal places in input
* @return true if they are over the limit, false if they are not
*/
/**
* getFullLicenceTime
* Returns the amount of months someone has to hold their restricted driver's licence
* before they can apply for their full licence, given their age and whether they
* have completed a defensive driving course.
*
* You can apply for your full licence after you've held your restricted licence for:
* at least 18 months if you're under 25 years old
* at least 12 months if you're under 25 years old and have completed a defensive driving course.
* at least six months if you're 25 or older
* at least three months if you're 25 or older and have completed a defensive driving course.
*
* @param age the age of the person
* @param hasDoneDefensiveCourse true if they person has completed a defensive driving course
* @return the minimum number of months that the person must hold their restricted before applying for their full
*/
/**
* getIncomeTax
* Returns the amount of income tax someone owes under New Zealand's tax system,
* given the amount they earn per year.
*
* The first $38,000 a person earns is taxed at 19.5%.
* Income between $38,001 and $60,000 is taxed at 33%.
* Income greater than that is taxed at 39%.
*
* Example 1:
* John earns $65,238 per year. That means he owes $16,712.82 in tax.
* This is how it is calculated:
* $0 to $38,000 @ 19.5% = $7,410.00
* $38,001 to $60,000 @ 33% = $7,260.00
* $60,001 to $65,238 @ 39% = $2,042.82
* Total = $16,712.82
*
* Example 2:
* Sarah earns $45,000 per year. That means he owes $9,720.00 in tax.
* This is how it is calculated:
* $0 to $38,000 @ 19.5% = $7,410.00
* $38,001 to $45,000 @ 33% = $2,310.00
* Total = $9,720.00
*
* @param income the amount of annual income the person is getting. This input must take decimal places.
* @return amount of tax owed per year
*/
}
(我想学编程的,英语都还可以吧!
他这里一共有5个题目,要我按他要求编,前面两个我自己想的,也不知道对不对
还有我用的是BLEUJ)希望大家能帮帮我~
该怎么编~主要是要有例题,好让我学习!谢谢
我是一个JAVA语言的初学者!更正确的说是一点基础都没有,刚学的时候连CLASS和OBJECT是什么关系都不知道!
由于我身在外国读书,于是我选了计算机科学来主修!
虽然说在国外书上讲的,老师说的~我都理解!但是毕竟不是母语还是比较困难!
最主要的是要给我一个例题~让我知道怎么编!毕竟这样比较好理解!
现在我有个简单的问题难倒了我!
题目是这样的!
/**
* Some methods to practice if statements on.
*
* @author Ray Hidayat
* @version 20 March 2008
*/
public class IfPractice
{
/**
* getAMPMString
* Given an hour of the day, returns "am" or "pm", whichever is appropriate
*
* @param hourOfDay the hour of the day, 0-23
NOTE: the above line is a special way to describe a parameter. The code @param
says the line will describe a parameter, 'hourOfDay' is the name of the parameter,
and 'the hour of the day, 0-23' is the parameter's description.
*
* @return "am" for hours 0-11, "pm" for hours 12-23
NOTE: the above line is a special way of describing what the method should return.
The code @return says the line will describe what the method returns.
*
*/
/*
* Below this comment is an example of how you can interpret the Javadoc comment above.
*
* Notice how the method signature below has a return type of String. For this lab you
* have four options for return types - boolean, int, double, or String, choose an
* appropriate type for each method.
*
* Also in the method signature below, the parameter hourOfDay is of type int.
* In the same way, for the other methods in this class, choose an appropriate type
* for each parameter, whether it be boolean, int, double or String.
*
* If you don't remember what boolean, int, double, or String are, refer to your lecture
* notes.
*/
public String getAMPMString(int hourOfDay){
String a = "am";
String p = "pm";
if (hourOfDay <=11)
{
if (hourOfDay >=0)
return a;
}
else if (hourOfDay <=23)
{
if (hourOfDay >=12)
return p;
}
return "";
} /**
* getGardeningCost
* Returns the cost of hiring a gardener for a certain amount of time.
* The gardener charges $25 per hour, and will always charge for at least
* 2 hours worth of work.
*
* Examples:
Input: 0.5 (hours)
Returns: 50 (dollars)
Input: 2 (hours)
Returns: 50 (dollars)
Input: 2.5 (hours)
Returns: 62.5 (dollars)
Input: 5 (hours)
Returns: 125 (dollars)
*
* @param hoursWorked the number of hours worked - must allow decimal places to be input
* @return the total cost of hiring the gardener
*/
public int getGardeningCost(int hours){
if (hours <=2)
{
if (hours >0)
return 50*1;
}
return hours * 25;
}
/**
* getMovieTicketPrice
* Returns the cost of a movie ticket for a person.
* Movie tickets cost $15 for adults, $12 for students, $8.50 for children
* aged 15 years or under. Children who are also students take the children's
* price.
*
* @param age the age of the person
* @param isStudent true if they're a student, false if not
* @return the movie ticket price
*/
/**
* isOverLimit
* Returns whether someone is over the breath alcohol limit for their age.
* People under 20 have a limit of 150 mg/litre of breath
* People 20 and over have a limit of 400 mg/litre of breath
*
* @param age the age of the person
* @param breathAlcohol the amount of breath alcohol the person has in mg/litre - must allow for decimal places in input
* @return true if they are over the limit, false if they are not
*/
/**
* getFullLicenceTime
* Returns the amount of months someone has to hold their restricted driver's licence
* before they can apply for their full licence, given their age and whether they
* have completed a defensive driving course.
*
* You can apply for your full licence after you've held your restricted licence for:
* at least 18 months if you're under 25 years old
* at least 12 months if you're under 25 years old and have completed a defensive driving course.
* at least six months if you're 25 or older
* at least three months if you're 25 or older and have completed a defensive driving course.
*
* @param age the age of the person
* @param hasDoneDefensiveCourse true if they person has completed a defensive driving course
* @return the minimum number of months that the person must hold their restricted before applying for their full
*/
/**
* getIncomeTax
* Returns the amount of income tax someone owes under New Zealand's tax system,
* given the amount they earn per year.
*
* The first $38,000 a person earns is taxed at 19.5%.
* Income between $38,001 and $60,000 is taxed at 33%.
* Income greater than that is taxed at 39%.
*
* Example 1:
* John earns $65,238 per year. That means he owes $16,712.82 in tax.
* This is how it is calculated:
* $0 to $38,000 @ 19.5% = $7,410.00
* $38,001 to $60,000 @ 33% = $7,260.00
* $60,001 to $65,238 @ 39% = $2,042.82
* Total = $16,712.82
*
* Example 2:
* Sarah earns $45,000 per year. That means he owes $9,720.00 in tax.
* This is how it is calculated:
* $0 to $38,000 @ 19.5% = $7,410.00
* $38,001 to $45,000 @ 33% = $2,310.00
* Total = $9,720.00
*
* @param income the amount of annual income the person is getting. This input must take decimal places.
* @return amount of tax owed per year
*/
}
(我想学编程的,英语都还可以吧!
他这里一共有5个题目,要我按他要求编,前面两个我自己想的,也不知道对不对
还有我用的是BLEUJ)希望大家能帮帮我~
该怎么编~主要是要有例题,好让我学习!谢谢
你写的这个程序没有主函数,下面的是一个简单的实例。
public class Person {
int id; //成员变量
int age = 20;
void Person(int _id, int _age) {//成员方法
id = _id;
age = _age;
}
public static void main(String[] args) {
Person tom = new Person();
tom.Person(1, 25);
//Person jerry = new Person();
Point p = new Point();
}
}class Point {
Point() {}
int x;
int y;
}