我卡在java编程上 [英] Im stuck on java programing

查看:105
本文介绍了我卡在java编程上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要为网站类编写名为browserLogin的方法,该方法允许已经具有ID的浏览器登录到该网站.将此方法传递给Browser对象作为参数,该对象使用浏览器的setLoginStatus方法登录"该浏览器到网站.它还需要以以下格式将欢迎消息输出到终端窗口: Wine Direct欢迎使用浏览器6732,您现在已登录.

i need to write method for the website class, called browserLogin, which allows a browser who already has an ID to log in to the site. This method is passed a Browser object as a parameter and which uses the browser's setLoginStatus method to "log in" that browser to the website. It also needs to outputs a welcome message to a terminal window in the format Wine Direct welcomes browser 6732, you are now logged in.

private int yearOfBirth;
private int id;
private String email;
private boolean loggedIn = true;

public Browser(String getEmail, int getId, int getYearOfBirth)
{
    email = getEmail;
    id = getId;
    yearOfBirth = getYearOfBirth;
}

public Browser()
{
    email = "J.Booth@winedirect.com";
    id = 2678;
    yearOfBirth = 1990;
    loggedIn = true;
}

public void yearOfBirth(int getYearOfBirth)
/**
 * 
 */
{
   yearOfBirth = getYearOfBirth; 
}

public void id(int getId)
/**
 * 
 */
{
    id = getId;
}

public void setLoginStatus()
{
    if(loggedIn = true)
    {
        System.out.println("online;" + id);
    }
    else
    {
        System.out.println("Offline");
    }
}

public boolean isLoginStatus()
/**
 * 
 */
{
    return loggedIn;
}

public void email(String getEmail)
/**
 * 
 */
{
    email = getEmail;
    loggedIn = true;
}

public void loggedOut()
/**
 * 
 */
{
    email = "";
    yearOfBirth = 0;
    id = 0;
    loggedIn = false;
}

}

public class Website

// instance variables - replace the example below with your own
private int hits;
private int salesTotal;
private Browser loggedIn;

private void browserLogin()
/**
 * 
 */
{
    loggedIn 
}

推荐答案

好的,让我们开始将您的规范写入Java代码:

Okay so let's start by writing your specifications into java code:

browserLogin method is passed a Browser object as a parameter

您的方法没有任何参数,因此添加它:

Your method doesn't have any parameters, so add it:

private void browserLogin(Browser br){

}

uses the browser's setLoginStatus method to "log in" that browser to the website

您专门说要使用方法..,但是该方法是完全错误的.

You specifically say to use the method, .. but the method is quite wrong.

 if(loggedIn = true)

这段代码的作用是使loggedIn为true,然后返回loginIn的值(始终为true).可能是您的意思:

What this piece of code does is that it makes loggedIn true and then returns the value of loggedIn (which will always be true). Probably you meant:

if(loggedIn == true)

但是无论如何它都不是setter方法.因此,假设您要登录浏览器,当尚未登录时,您可以按照以下步骤进行操作:

However it is not a setter method in any way. So assuming you want to log browser in, when it's not already logged in you could do something along these lines:

private void browserLogin(Browser br){
    if(!br.isLoginStatus()){          
      br.setLoginStatus(true);
    }         
}

并为此编辑方法:

public void setLoginStatus(boolean value)
{
    loggedIn = value;

    if(loggedIn == true)
    {
        System.out.println("online;" + id);
    }
    else
    {
        System.out.println("Offline");
    }
}

据我所知,您只是从Java入手.我建议您阅读oracle教程并从头开始: Oracle教程

From what I see, you just starting with Java. I would suggest reading the oracle tutorials and starting really from the beginning: Oracle Tutorials

这篇关于我卡在java编程上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆