Gostaria que vocês me dessem críticas a respeito da aplicação abaixo o q fiz contra o padrão da convenção e o q pode ser melhorado, obrigado a todos!
// start
// @author Raphael S. Carvalho
public class Rent {
public static void main(String[] args) {
Menu start = new Menu();
start.Menu();
}
}
// main menu
import java.util.Scanner;
public class Menu {
private Functions_Movie movie;
private Functions_Client client;
public void Menu() {
Scanner input = new Scanner(System.in);
movie = new Functions_Movie();
client = new Functions_Client();
System.out.println("Welcome to the rent system!");
System.out.println("\tPlease choose a option\nMovie Functions: [1]\nClient Functions: [2]\nSystem exit[3]");
int menu = input.nextInt();
switch(menu) {
case 1:
movie.Functions_Movie();
break;
case 2:
client.Functions_Client();
break;
case 3:
System.out.println("Thanks for use the system!");
System.exit(0);
default: System.out.println("Invalid option!");
}
}
}
// movie functions
import java.util.Scanner;
public class Functions_Movie {
private int movies_Created = 0;
private Movie[] object = new Movie[100];
private Scanner input = new Scanner(System.in);
private Menu main = new Menu();
public void Functions_Movie() {
System.out.println("\tOptions:\nTo subscribe a new movie: [1]\nMovie List: [2]\nTo search a movie: [3]\nTo remove a movie: [4]\nReturn to main menu: [5]");
int options = input.nextInt();
switch(options) {
case 1:
if (movies_Created >= 100) {
System.out.println("Please talk with programmer to expading the data-base.");
} else {
add_Movie();
break;
}
break;
case 2:
movie_List();
break;
case 3:
search_Movie(options);
break;
case 4:
search_Movie(options); // remove movie;
break;
case 5:
main.Menu();
break;
default: System.out.println("Invalid option!");
}
}
public void add_Movie() {
System.out.println("Please type the new movie:");
String movie = input.next();
System.out.println("Please type the movie category:");
String category = input.next();
object[movies_Created] = new Movie(movie, category, movies_Created, false);
object[movies_Created].toString();
movies_Created++;
Functions_Movie();
}
public void search_Movie(int options) {
System.out.println("Search Name:\nPlease, input the movie name:");
String movie_name = input.next();
int search = 0;
for (search = 0; search < movies_Created; search++){ // search movies.
if (movie_name.equals(object[search].getMovie_Name())){
System.out.println(object[search].toString());
break;
} else if (search == movies_Created){
System.out.println("Sorry, this movie was not found.");
}
}
if (options == 4){
remove_Movie(search);
}
Functions_Movie();
}
public void remove_Movie(int search) {
object[search] = null;
System.out.println("This movie was cleaned with sucess!");
// array sort is here.
Functions_Movie();
}
public void movie_List(){
for (int i = 0; i < movies_Created; i++){ // sort array.
System.out.println(object[i].toString());
}
Functions_Movie();
}
public Movie[] getObject(){
return object;
}
}
// movie
public class Movie {
private String movie_name, category;
private int movie_id;
private boolean rent;
public Movie (String movie_name, String category, int movie_id, boolean rent) {
this.movie_name = movie_name;
this.category = category;
this.movie_id = movie_id;
this.rent = rent;
}
public String toString(){
return "The movie ID["+getMovie_ID()+"]\nName:"+getMovie_Name()+"\nCategory: "+getCategory()+"";
}
public String getMovie_Name(){
return movie_name;
}
public String getCategory(){
return movie_name;
}
public int getMovie_ID(){
return movie_id;
}
public boolean getStatus(){
return rent;
}
}
// client functions
import java.util.Scanner;
public class Functions_Client {
private int clients_Created = 0;
private Functions_Movie function = new Functions_Movie();
private Scanner input = new Scanner(System.in);
private Client[] id = new Client[100];
private Menu main = new Menu();
public void Functions_Client(){
System.out.println("\tOptions:\nTo create a new client: [1]\nClient List: [2]\nTo rent a movie: [3]\nReturn to main menu: [4]");
int options = input.nextInt();
switch(options) {
case 1:
if (clients_Created >= 100) {
System.out.println("Please talk with programmer to expading the data-base.");
} else {
new_Client();
}
break;
case 2:
client_List();
break;
case 3:
rent_Movie();
break;
case 4:
main.Menu();
break;
default: System.out.println("Invalid option!");
}
}
public void new_Client() {
System.out.println("Subscribe a new Client!");
System.out.println("Please type the name:");
String name = input.next();
System.out.println("Please type the age:");
int age = input.nextInt();
System.out.println("Please type the contact number:");
String contact_number = input.next();
id[clients_Created] = new Client(name, age, contact_number, 0, clients_Created);
id[clients_Created].toString();
System.out.println("This client id is: "+clients_Created+".");
clients_Created++;
Functions_Client();
}
public void rent_Movie () {
System.out.println("Please say your ID:");
int x = input.nextInt();
System.out.println("Please say your name:");
String name = input.next();
if (name.equals(id[x].getName())){
System.out.println("You have sure that u wanna a rent this movie? (Y/N)");
String asnwer = input.next();
if(asnwer.equals("Y") || asnwer.equals("y")) {
id[x].setAccount(1.50);
System.out.println("This movie cost a 1.50$.");
} else {
Functions_Client();
}
} else {
Functions_Client();
}
}
public void client_List(){
for (int i = 0; i < clients_Created; i++){ // sort array.
System.out.println(id[i].toString());
}
Functions_Client();
}
public Client[] getID(){
return id;
}
}
// client
public class Client {
private String name, contact_number;
private int age, id;
private double account;
public Client (String name, int age, String contact_number, int account, int id){
this.name = name;
this.age = age;
this.contact_number = contact_number;
this.account = account;
this.id = id;
}
public void setAccount(double price){
this.account += account;
}
public String toString(){
return "Name: "+getName()+"\nAge: "+getAge()+"\nContact Number: "+getContact()+"\nAccount: "+getAccount()+"";
}
// getters.
public String getName(){
return name;
}
public int getAge(){
return age;
}
public String getContact(){
return contact_number;
}
public double getAccount(){
return account;
}
public int getID(){
return id;
}
}