简体   繁体   English

如何让用户在代码中设置自己的订单号?

[英]What should I do to have the user set their own order number with in my code?

I am a beginner programmer and I don't understand why I can not set the orderNum in my driver. 我是一个初学者程序员,我不明白为什么不能在驱动程序中设置orderNum。 I want the user to be able to set the orderNum on their own because there is no orderNum the is predisposed. 我希望用户能够自行设置orderNum,因为不存在预先设置的orderNum。

public class Cafe 
{
    private int orderNum;
    private String cafeName, cafeID;

    public Cafe()
    {
        int orderNum;
        String cafeName = null, cafeID;
    }
    public String setName(String cafeID)
    {
        if(cafeID.equals("101"))
            cafeName = "Essex Cafe";
        else if(cafeID.equals("252"))
            cafeName = "White Marsh Cafe";
        else
            cafeName = "Towson Cafe";
        return cafeName;
    }
    public String toString()
    {

        return "\t" + cafeName + "\nOrder Number = " + orderNum;
    }
}

import java.util.Scanner;
public class CafeProject 
{
    public static void main(String[] args)
    {
    Scanner scan = new Scanner(System.in);
    Cafe Emp = new Cafe();

    System.out.print("Enter Cafe Identifier:    ");
    Emp.setName(scan.next());




    System.out.print(Emp);
    }
}

Change your program like this you can set order no manually 像这样更改程序,您可以手动设置订单号

import java.util.Scanner;
class Cafe
{
    private int orderNum;
    private String cafeName, cafeID;

    public Cafe()
    {        int orderNum;
        String cafeName = null, cafeID;
    }
    public String setName(String cafeID)
    {
        if(cafeID.equals("101"))
            cafeName = "Essex Cafe";
        else if(cafeID.equals("252"))
            cafeName = "White Marsh Cafe";
        else
            cafeName = "Towson Cafe";
        return cafeName;
    }
    public void setOrderNo(int orderNo){
        orderNum=orderNo;
    }
    public String toString()
    {

        return "\t" + cafeName + "\nOrder Number = " + orderNum;
    }
}

public class CafeProject
{
    public static void main(String[] args)
    {
    Scanner scan = new Scanner(System.in);
    Cafe Emp = new Cafe();

    System.out.print("Enter Cafe Identifier:    ");
    Emp.setName(scan.next());
    System.out.print("Enter Order No:    ");
    Emp.setOrderNo(scan.nextInt());



    System.out.print(Emp);
    }
}

You just need a function to set order 您只需要设置命令的功能

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 TDD:我必须定义我的代码不应该做的所有事情吗? - TDD: Do I have to define everything my code should NOT do? 我应该在我的代码中做什么,以便在 Processing 3 (Java) 中检测 PNG 精灵和绘制的圆圈之间的碰撞? - What should I do in my code in order to make a collision detection between a PNG sprite and a drawn circle occur in Processing 3 (Java)? 我正在尝试实现自己的HashSet,但我不知道应该返回什么iterator()方法? - I am trying to implement my own HashSet and I do not know what iterator() method should return? 什么是AssertionError?在哪种情况下我应该从我自己的代码中抛出它? - What is an AssertionError? In which case should I throw it from my own code? 处理我的代码上没有发生的异常,我该怎么办? - Handling an exception not happening on my code, what should I do? 我试图自己解决这个问题,但没有得到任何很好的结果,还附上了我的代码与问题 - i have tried to do the problem on my own, but not getting any great results, also attaching my code with the problem 为了让程序绘制图 1 中看到的图像,我应该对代码进行哪些更改? - What should I change to my code in order that the program draws the image seen in picture 1? 我必须以哪种顺序编码? - In which order do I have to code? 我想通过编写自己的JNI代码来学习如何做JNA的工作 - I want to learn how to do what JNA does by writing my own JNI code 我应该在这段代码中更改哪些内容才能设置保存文件的路径? - What exactly should I change in this snip of code to have ability set a path to a save file?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM