对于下面的java演示,我将如何使其不成为静态的方法?
当我试图简单地删除对于下面的java演示,我将如何使其不成为静态的方法?,java,methods,static,Java,Methods,Static,当我试图简单地删除static时,它给了我错误消息,我不知道如何创建demo类的实例。 代码如下: import java.util.Scanner; public class FilmDemo { public static void main(String[] args) { // TODO Auto-generated method stub Scanner keyboard = new Scanner(System.in); F
static
时,它给了我错误消息,我不知道如何创建demo类的实例。
代码如下:
import java.util.Scanner;
public class FilmDemo {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner keyboard = new Scanner(System.in);
Film[] filmArray = new Film[10];
int numberOfFilms = 0;
int option;
do {
System.out.println("Press 1 to create a Film");
System.out.println("Press 2 to create a Foreign Film");
System.out.println("Press 3 to create a Bollywood Film");
System.out.println("Press 4 to view all the films");
System.out.println("Press 5 to exit");
option = keyboard.nextInt();
if(option == 1) {
Film currentFilm = new Film();
enterInformation(currentFilm);
boolean alreadyInTheArray = checkForDuplicate(filmArray,numberOfFilms,currentFilm);
if(!alreadyInTheArray) {
numberOfFilms = insertIntoArray(filmArray,numberOfFilms,currentFilm);
}
else {
System.out.println("This film already exists in the system");
}
}
else if(option == 2) {
ForeignFilm currentForeignFilm = new ForeignFilm();
enterInformation(currentForeignFilm);
boolean alreadyInTheArray = checkForDuplicate(filmArray,numberOfFilms, currentForeignFilm);
if(!alreadyInTheArray) {
numberOfFilms = insertIntoArray(filmArray,numberOfFilms,currentForeignFilm);
}
else {
System.out.println("This film already exists in the system.");
}
}
else if(option == 3) {
BollywoodFilm currentBollywoodFilm = new BollywoodFilm();
enterInformation(currentBollywoodFilm);
boolean alreadyInTheArray = checkForDuplicate(filmArray,numberOfFilms, currentBollywoodFilm);
if(!alreadyInTheArray) {
numberOfFilms = insertIntoArray(filmArray,numberOfFilms,currentBollywoodFilm);
}
else {
System.out.println("This film already exists in the system");
}
}
else if(option == 4) {
print(filmArray,numberOfFilms);
}
else if(option == 5) {
System.out.println("Thank you for using the Film Library prototype.");
}
else {
System.out.println("Error. Invalid entry");
}
}while(option != 5);
}
public static boolean checkForDuplicate(Film [] array, int numberOfFilms, Film newFilm) {
boolean alreadyInTheArray = false;
for(int i=0; i < numberOfFilms; i++) {
if(array[i].equals(newFilm)) {
alreadyInTheArray = true;
}
}
return alreadyInTheArray;
}
public static int insertIntoArray(Film [] array, int numberOfFilms, Film newFilm) {
array[numberOfFilms] = newFilm;
numberOfFilms++;
return numberOfFilms;
}
public static void print(Film [] array, int numberOfFilms) {
for(int i=0; i < numberOfFilms; i++) {
System.out.println(array[i]);
}
}
public static void enterInformation(Film newFilm) {
Scanner keyboard = new Scanner(System.in);
if(newFilm != null) {
System.out.println("Enter the name of the film");
String name = keyboard.nextLine();
System.out.println("Enter the director of the film");
String director = keyboard.nextLine();
System.out.println("Enter the year of the film");
int year = keyboard.nextInt();
keyboard.nextLine();
newFilm.setName(name);
newFilm.setDirector(director);
newFilm.setYear(year);
if(newFilm instanceof ForeignFilm) {
System.out.println("Enter the native language the film is: ");
String nativeLanguage = keyboard.nextLine();
System.out.println("Enter translation of the name in English");
String translationOfNameInEnglish = keyboard.nextLine();
System.out.println("How many subtitles does this film have?");
int number = keyboard.nextInt();
keyboard.nextLine();
ForeignFilm newForeignFilm = (ForeignFilm)newFilm;
newForeignFilm.setNativeLanguage(nativeLanguage);
newForeignFilm.setTranslationOfNameInEnglish(translationOfNameInEnglish);
for(int i =0; i < number; i++) {
System.out.println("Enter the next subtitle");
String nextSubtitle = keyboard.nextLine();
if(newForeignFilm.getNumberOfSubtitles() < ForeignFilm.getMaxSubtitles()) {
newForeignFilm.addSubtitle(nextSubtitle);
}
}
if(newFilm instanceof BollywoodFilm) {
BollywoodFilm newBollywoodFilm = (BollywoodFilm)newFilm;
System.out.println("How many secondary languages does this film have?");
int secondary = keyboard.nextInt();
keyboard.nextLine();
for(int i=0; i < secondary; i++) {
System.out.println("Enter the next secondary language");
String nextSecondaryLanguage = keyboard.nextLine();
if(newBollywoodFilm.getNumberOfSecondaryLanguages() < BollywoodFilm.getMaxSecondaryLanguages()) {
newBollywoodFilm.addSecondaryLanguage(nextSecondaryLanguage);
}
}
System.out.println("How many songs does this film have?");
int songs = keyboard.nextInt();
keyboard.nextLine();
for(int i=0; i < songs; i++) {
System.out.println("Enter the next song");
String nextSong = keyboard.nextLine();
if(newBollywoodFilm.getNumberOfSongs() < BollywoodFilm.getMaxSongs()) {
newBollywoodFilm.addSong(nextSong);
}
}
}
}
}
}
}
import java.util.Scanner;
公共类电影演示{
公共静态void main(字符串[]args){
//TODO自动生成的方法存根
扫描仪键盘=新扫描仪(System.in);
胶片[]胶片阵列=新胶片[10];
int numberOfFilms=0;
int选项;
做{
System.out.println(“按1创建胶片”);
System.out.println(“按2键创建外文胶片”);
System.out.println(“按3键制作宝莱坞电影”);
System.out.println(“按4键查看所有影片”);
System.out.println(“按5退出”);
option=keyboard.nextInt();
如果(选项==1){
当前胶片=新胶片();
输入信息(currentFilm);
布尔值alreadyInTheArray=checkForDuplicate(filmArray、numberOfFilms、currentFilm);
如果(!已准备就绪阵列){
numberOfFilms=插入阵列(filmArray,numberOfFilms,currentFilm);
}
否则{
System.out.println(“此胶片已存在于系统中”);
}
}
否则如果(选项==2){
ForeignFilm currentForeignFilm=新的ForeignFilm();
输入信息(currentForeignFilm);
布尔值alreadyInTheArray=checkForDuplicate(filmArray、numberOfFilms、currentForeignFilm);
如果(!已准备就绪阵列){
numberOfFilms=插入阵列(filmArray,numberOfFilms,currentForeignFilm);
}
否则{
System.out.println(“系统中已存在此胶片”);
}
}
否则如果(选项==3){
宝莱坞电影当前宝莱坞电影=新宝莱坞电影();
输入信息(当前宝莱坞电影);
布尔值alreadyInTheArray=checkForDuplicate(filmArray、numberOfFilms、currentBollywoodFilm);
如果(!已准备就绪阵列){
numberOfFilms=插入阵列(filmArray,numberOfFilms,currentBollywoodFilm);
}
否则{
System.out.println(“此胶片已存在于系统中”);
}
}
否则如果(选项==4){
打印(胶片阵列、胶片数量);
}
否则如果(选项==5){
System.out.println(“感谢您使用电影库原型”);
}
否则{
System.out.println(“错误.无效条目”);
}
}while(选项!=5);
}
公共静态布尔校验重复(Film[]数组、int numberOfFilms、Film newFilm){
布尔值alreadyInTheArray=false;
对于(int i=0;ipublic static void main(String[] args) {
FilmDemo filmDemo = new FilmDemo(args);
filmDemo.doSomething();
}
public FilmDemo(String[] args) {
// Init anything here
}
public void doSomething() {
// Do something here
}