Java BlueJ初学者如何开始

Java BlueJ初学者如何开始,java,bluej,Java,Bluej,我上计算机科学课已经快三个月了,我甚至都不会开始写代码。如果有人能帮我解决这个问题,那就太好了。本作业共有三部分,我只发布了第一部分。我想一旦我理解了第一部分,我就可以理解剩下的部分了 创建类定义 为名为BasketballPlayer的篮球运动员创建类定义 其字段包括: name, a String height (in inches), an int weight (in pounds), an int freeThrowsAttempted, an int freeThrowsMade,

我上计算机科学课已经快三个月了,我甚至都不会开始写代码。如果有人能帮我解决这个问题,那就太好了。本作业共有三部分,我只发布了第一部分。我想一旦我理解了第一部分,我就可以理解剩下的部分了

创建类定义

为名为BasketballPlayer的篮球运动员创建类定义

其字段包括:

name, a String
height (in inches), an int
weight (in pounds), an int
freeThrowsAttempted, an int
freeThrowsMade, an int
twoPointFieldGoalsAttempted, an int
twoPointFfieldGoalsMade, an int
threePointersAttempted, an int
threePointersMade, an int
turnovers, an int
assists, an int
包括创建BasketballPlayer实例的构造函数。构造函数应该只有3个参数:name的值(字符串)和height和weight的值(ints)。它应该将所有其他字段设置为0

包括每个统计类别(罚球成功/罚球未遂、三分球、助攻等)的预期“得分者”和“二传者”

此外,还包括一个getStats()方法,该方法返回如下格式的字符串:

姓名:XXXXXXXX

现场目标百分比:xxxxx.xx%

3指针百分比:xxxxx.xx%

罚球命中率:xxxxx.xx%

协助与离职率:xxx.xx

注:现场目标百分比是使用两点目标和三点目标的总和计算的。 这就是我目前所拥有的

 public class BasketballPlayer extends Team
{
  String name;
int height;
int weight;
int freeThrowsAttempted;
int freeThrowsMade;
int twoPointFieldGoalsAttempted;
int twoPointFieldGoalsMade;
int threePointersAttempted;
int threePointersMade;
int turnovers;
int assists;
public BasketballPlayer(){
    this.name = null;
    this.height = 0;
    this.weight = 0;
    }
 public BasketballPlayer(String name, int weight, int height){
   this.name = name;
   this.height = height;
   this.weight = weight;}
public void setName(String aName){
name = aName;}
public void setHeight(int aHeight){
height = aHeight;}
public void setWeight(int aWeight){
weight = aWeight;}
private void setFreeThrowsAttempted(int aFreeThrowsAttempted){
freeThrowsAttempted = aFreeThrowsAttempted;}
public void setFreeThrowsMade(int aFreeThrowsMade){
freeThrowsMade = aFreeThrowsMade;}
public void setTwoPointFieldGoalsAttempted(int aTwoPointFieldGoalsAttempted){
twoPointFieldGoalsAttempted = aTwoPointFieldGoalsAttempted;}
public void setTwoPointFieldGoalsMade(int aTwoPointFieldGoalsMade){
twoPointFieldGoalsMade = aTwoPointFieldGoalsMade;}
public void setThreePointersAttempted(int aThreePointersAttempted){
threePointersAttempted = aThreePointersAttempted;}
public void setThreePointersMade(int aThreePointersMade){
threePointersMade = aThreePointersMade;}
public void setTurnovers(int aTurnovers){
turnovers = aTurnovers;}
public void setAssists(int aAssists){
assists = aAssists;}
public String getName(){
  return name;}
public int getHeight(){
  return height;}
public int getWeight(){
  return weight;}
public int getFreeThrowsAttempted(){
return freeThrowsAttempted;}
public int getFreeThrowsMade(){
    return freeThrowsMade;}
public int getTwoPointFieldGoalsAttempted(){
return twoPointFieldGoalsAttempted;}
public int getTwoPointFieldGoalsMade(){
return twoPointFieldGoalsMade;}
public int getThreePointersAttempted(){
return threePointersAttempted;}
public int getThreePointersMade(){
return threePointersMade;}
public int getTurnovers(){
return turnovers;}
public int getAssists(){
return assists;}

int FGP = (twoPointFieldGoalsMade + threePointersMade / twoPointFieldGoalsAttempted + threePointersAttempted);
int threePP = (threePointersMade / threePointersAttempted);
int FTP = (freeThrowsMade / freeThrowsAttempted);

public int getStats(){
return
System.out.println("Name: " + this.name);
System.out.println("Field Goal Percentage: " + FGP + "%");
System.out.println("3 Pointer Percentage: " + threePP + "%");
System.out.println("Free Throw Percentage: " + FTP + "%");
System.out.println("Assist-to-Turnover Ratio: " + (assists + ":" + turnovers));}}

对于那些希望否决投票的人:这是为了演示目的,是为了帮助OP。这不是一个合适的答案

一些快速代码(注释中的解释):

这应该在BlueJ中编译并可运行。您可以随意使用main(String[])和class Cat来帮助自己解决所有问题


好的,是的,这看起来/听起来很可笑,但希望能为您指明正确的方向

请从阅读帮助中心开始。您当前提出的问题不适合此网站。@user4582044在问题中发布您的代码,格式化,并显示您尝试过的内容和出现的问题我们已经休息了一段时间,我不记得从哪里开始。到目前为止,我们只使用模板填充填充了空白类型编码,看起来还不错。您需要向构造函数添加一些参数,以允许它将实例变量设置为传入的内容。老实说,我会回去看一些课程,或者尝试搜索java教程。还是一个面向对象的编程教程?我走的是正确的道路@BenKnoble?我真的只是想开始,没人读吗?我得到了否决票,因为我明确表示,这不是我想要的答案。这里的人没有生命。事实上,他们只是疯狂地醒来,寻找理由否决投票。这太可笑了,我猜stack的原创者会感到震惊。再加上我上面的咆哮,这里的版主并没有那么棒,我猜是因为雇佣了不称职的人作为版主,但嘿,这就是生活。不可能每件事都是完美的,哈哈。不过有些还不错。
public class Cat
{
    //instance variables: each object will have its own unique copies with different data
    String name, type, furColor;
    int age;

    //default constructor (basic cats with no info)
    public Cat()
    {
        this.name = null;//default for object types is null, String is object type
        this.type = null;
        this.furColor = null;
        this.age = 0;//default for int types is 0 or equivalent
    }

    //normal constructor: used for most constructions, takes parameters to initialize data 
    //(this is what you need for your basketball guy, although not every instance var needs a parameter in the constructor--refer to task guidelines)
    public Cat(String name, String type, String furColor, int age)
    {
        this.name = name;//if this confuses you, remember, this refers to current object instance,
        //but name will just search in scope, starting with lowest, til it finds reference. So it finds String name in param list first and uses that
        this.type = type;//bad example; type could now technically be "aslkdjf"
        this.furColor = furColor;
        this.age = age;
    }

    //an example getter/setter
    public void setName(String name){this.name = name;}//i'm not making pretty cuz time
    public String getName(){return this.name;}
    //if you decide to actually mess with this, add getters/setters for the rest of the data for the cat to really feel power
    //example cat method(s)--you can add more
    public String Meow(){return (this.name + " says, \"Meow!\"");}//returns string so main can print
    public String Eat(){return (this.name + " licks the bowl greedily...");}

    public static void main(String[] args)
    {
        Cat cat1 = new Cat();//data is blank
        cat1.setName("Jack");//if you comment this line out and run, you should get a null reference error because the name is null
        //please try messing with getters/setters so you can initialize all the data if you have time
        System.out.println(cat1.Meow() + "\n" + cat1.Eat());
        Cat cat2 = new Cat("Boris", "Calico", "White/Blonde", 13);//has actual data now because of constructor
        System.out.println(cat2.getName() + "'s day: \n" + cat2.Meow() + "\n" + cat2.Eat());
    }
}