我试图创建一个餐厅系统,将从菜单中创建食品等.
我很快就会学习jdbc而且我相信这会有所帮助但是现在我觉得最简单的方法就是在记事本中创建我的菜单.
什么是排队和从菜单等记事本文件中读取的最佳方式.
请尽量说清楚,我不完全确定所有术语.
这个看起来很有希望,但我不知道什么是最重要的.
////////////////////////////////////////////////// ///////////////////
我仍然坚持这一点.
香港专业教育学院决定也制作一个单独的方法来阅读文件.
香港专业教育学院尝试了我能想到的每个例子 有人可以告诉我一个如何定义文件类路径的例子.
如果我输入menu.txt它只是不起作用.
从现在开始工作以来改变了项目.有点儿.图像仍然没有改变.
package icnon;
import javax.imageio.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class FrameIconExample extends JFrame implements ActionListener {
JLabel j;
JPanel p, l, k;
JButton picOne, picTwo;
Container cPane;
public FrameIconExample() {
JButton picOne = new JButton("picOne");
JButton picTwo = new JButton("picTwo");
picOne.setName("picOne");
picTwo.setName("picTwo");
picOne.addActionListener(this);
picTwo.addActionListener(this);
p = new JPanel(new GridLayout(2, 1));
l = new JPanel(new FlowLayout());
k = new JPanel(new FlowLayout());
cPane = getContentPane();
j = new JLabel(new ImageIcon(
"../meet/src/images/beautiful-closeup-portrait-photography.jpg"));
l.add(j);
k.add(picOne);
k.add(picTwo);
p.add(l);
p.add(k);
add(p);
}
public …Run Code Online (Sandbox Code Playgroud) 我是一名学生,上周刚开始学习C++,所以这个问题可能很低,但我无法弄明白.
我搜索了一下但找不到任何结果,或者我正在寻找错误的东西.
有两个cin部分.一个接受循环外的int,另一个接受循环内的字符串.
我收到一个编译错误,说""错误没有操作符匹配这些命令"即使我刚刚使用它们5行之前.
救命?
#include <fstream>
#include <iostream>
using namespace std;
int main()
{
// variable declaration
const double payIncrease = 7.6;
string employeeName;
double initialSalary;
double backPay;
double employeeAnnualSalary;
double employeeMonthlySalary;
int numEmployees;
// streams of information
ofstream outStream;
outStream.open("employeeRecords.txt");
// console io's
cout<<"Enter how many employees you have:";
cin>>numEmployees;
for(int i = 0; i <numEmployees;i++)
{
cout<<"What is Employee number: "<<i<<"'s name:";
cin>>employeeName;
cout<<"How much does that employee earn now: ";
cin>>initialSalary;
}
outStream <<"annual salary was: …Run Code Online (Sandbox Code Playgroud) public static void main(String[] args){
Employee [] employeeList =
{
// build your list here
};
}
Run Code Online (Sandbox Code Playgroud)
我究竟如何构建我的数组.
数组只是在另一个类中定义的2个字符串.
class Employee
{
protected String name;
protected String jobTitle;
Employee(String n, String title)
{
name = n;
jobTitle = title;
}
}
Run Code Online (Sandbox Code Playgroud) 我也主要使用Scanner,也想尝试使用缓冲读卡器:到目前为止我所拥有的
import java.util.*;
import java.io.*;
public class IceCreamCone
{
// variables
String flavour;
int numScoops;
Scanner flavourIceCream = new Scanner(System.in);
// constructor
public IceCreamCone()
{
}
// methods
public String getFlavour() throws IOexception
{
try{
BufferedReader keyboardInput;
keyboardInput = new BufferedReader(new InputStreamReader(System.in));
System.out.println(" please enter your flavour ice cream");
flavour = keyboardInput.readLine();
return keyboardInput.readLine();
}
catch (IOexception e)
{
e.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud)
我相当肯定会得到一个你可以说的int
Integer.parseInt(keyboardInput.readLine());
Run Code Online (Sandbox Code Playgroud)
但如果我想要一个字符串怎么办?
我现在已经在这一点了.我有一个空指针异常所以我猜测某些事情没有被初始化.
AdminMessages.inbox1.setText(messageRsetArray[0]);
Run Code Online (Sandbox Code Playgroud)
这是我的代码所针对的代码.但我找不到里面的东西.它尚未初始化.
AdminMessages是一个包含JTextField被调用的类inbox1,messageRsetArray是一个从数组中获取变量的数组.
也是inbox1静态的.我无法让吸气剂和二传手工作.我知道这是不好的做法.
Exception in thread "main" java.lang.NullPointerException
at project.AdminMessages.fillInboxGui(AdminMessages.java:587)
at project.AdminMessages.<init>(AdminMessages.java:156)
at project.AdminUser.createAdminMessages(AdminUser.java:31)
at project.AdminUser.<init>(AdminUser.java:17)
at project.AdminUser.main(AdminUser.java:45)
Run Code Online (Sandbox Code Playgroud) 我可能以错误的方式看待枚举,但想确保我在如何使用它们方面拥有正确的理论。
假设我们有一个名为 Colour 的枚举。
enum Colour { Red, Green, Blue };
Run Code Online (Sandbox Code Playgroud)
红、绿、蓝用 0-255 的值表示。我正在尝试在类形状内初始化此枚举,但我不太确定如何进行。
public class Shape
{
Colour colour;
public Shape(Colour c)
{
//Some attempts at initialization.
//Treating It like an object
this.colour =
c{
255,255,255
};
//Again
this.colour.Red = c.Red
this.colour.Blue = c.Blue
this.colour.Green = c.Green
Colour.red = c.red?
}
}
}
Run Code Online (Sandbox Code Playgroud)
我对枚举的看法可能还很遥远。有人能给我一些指点吗?
真的不明白这里出了什么问题?
这只是一个数组越界的简单异常.
public class Days
{
public static void main (String args[])
{
String[] dayArray = new String [4];
{
dayArray [0] = "monday";
dayArray [1] = "tuesday";
dayArray [2] = "wednesday";
dayArray [3] = "Thursday";
dayArray [4] = "Friday";
try
{
System.out.println("The day is " + dayArray[5]);
}
catch(ArrayIndexOutOfBoundsException Q)
{
System.out.println(" invalid");
Q.getStackTrace();
}
System.out.println("End Of Program");
}
}
}
Run Code Online (Sandbox Code Playgroud)
有没有人有任何想法,为什么这不会运行?我收到错误:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 4
at Days.main(Days.java:14)
Run Code Online (Sandbox Code Playgroud)