Call class method from another class
So I am creating a Netflix based application for a school assignment. So yes this is homework. I created a userinterface that looks like the following
Code :
import java.io.IOException;
import java.util.Queue;
import java.util.Scanner;
public class UserInterface extends Users {
public UserInterface(String userName, double accountNumber,
Queue<Movie> playList, Queue<Movie> lastMovies) {
super(userName, accountNumber, playList, lastMovies);
}
public static void main(String[] args){
Scanner keyboard = new Scanner(System.in);
while(true){
System.out.println("X) Exit");
System.out.println("0) Create a new movie");
System.out.println("1) Add Movie to your playlist");
System.out.println("2) Upgrade your account");
char c = keyboard.next().charAt(0);
switch(c){
case 'X':
System.exit(0);
case '0':
createMovies;
case '1':
for(int i= 0; i < playList.size(); i++)
System.out.println(playList);
break;
case '2':
System.out.println("Small one time free of $10,000,000!");
break;
}
}
}
}
so now what I am running into is the "case '0'" selection, where I am trying to just call "createMovies;" which is a method inside another class which looks like the following
Code :
import java.util.Date;
import java.util.Scanner;
public class createMovie
{
public Scanner keyboard = new Scanner(System.in);
public static void main(String args[])
{
}
public void createMovies()
{
String password = "adminpassword";
boolean isAdmin = false;
double inputPrice = 0;
String inputMovie;
String inputGenre;
Date inputDate = new Date();
String inputPassword;
System.out.println("Enter Movie Title:");
inputMovie = keyboard.nextLine();
System.out.println("Enter Movie Genre:");
inputGenre = keyboard.nextLine();
System.out.println("Enter Admin Password:");
inputPassword = keyboard.nextLine();
passCheck(inputPassword, password, isAdmin);
adminPower(isAdmin, inputPrice);
Movie movies = new Movie(inputMovie, inputDate, inputGenre, inputPrice);
}
public void passCheck(String inputPassword, String password, boolean isAdmin)
{
if(inputPassword == password)
{
isAdmin = true;
}
else System.out.println("Sorry wrong password");
}
public void adminPower(boolean isAdmin, double inputPrice)
{
if (isAdmin == true)
System.out.println("Enter Movie Price:");
inputPrice = keyboard.nextDouble();
}
}
and without adding more code to this post I will just say this creates a Movie object, that I will later have saved to a Movie selection linked list, and then allow the user to select movies out of that list.
So the problem is I can't get the function to call properly inside my interface class. How would I go about doing this? I tried creating a "createMovie movies = null;" and then passing it through the function like so "movies.createMovies(); but apparently that doesn't actually do anything because it is null.
Re: Call class method from another class
Ever tried "createMovie movies = new createMovie();" and "movies.createMovies()"? That would probably do you good.
Just a heads up, where is the "break;" in case 'X' or case '0'?