What's new

Closed Basic: java code refactoring - preview to oop

Status
Not open for further replies.
Ts sample po ito galing po sa binigay nyo na video tinatry ko po e convert sa java tama po ba ang pakaka convert ko?

Code:
public class AverageOf3Intergers
{
    static int a,b,c;
    static float ave;
    static Scanner input;
   
    public static void main (String [] args){
       
        initializeInput();
       
        initializeIntergers();
       
        initializeFloat();
       
        displayQuestion();
       
        getInputAndDisplayAnswer();
       
    }
   
    static void initializeInput(){
       
        input = new Scanner(System.in);
    }
   
    static void initializeIntergers(){
        a = 0;
        b = 0;
        c = 0;
    }
   
    static void initializeFloat(){
        ave = 0;
    }
   
    static void displayQuestion(){
       
        System.out.println("Average Of 3 Integers");
    }   
    static void getInputAndDisplayAnswer(){
       
        System.out.println("\n Input 3 Integers: ");
        System.out.print("a: ");
        a = input.nextInt();
        System.out.print("b: ");
        b = input.nextInt();
        System.out.print("c: ");
        c = input.nextInt();
        ave = a + b + c / 3;
        System.out.println(" The Average Of 3 Integers is " + ave);
       
    }
}
 
Ts sample po ito galing po sa binigay nyo na video tinatry ko po e convert sa java tama po ba ang pakaka convert ko?

Code:
public class AverageOf3Intergers
{
    static int a,b,c;
    static float ave;
    static Scanner input;
 
    public static void main (String [] args){
     
        initializeInput();
     
        initializeIntergers();
     
        initializeFloat();
     
        displayQuestion();
     
        getInputAndDisplayAnswer();
     
    }
 
    static void initializeInput(){
     
        input = new Scanner(System.in);
    }
 
    static void initializeIntergers(){
        a = 0;
        b = 0;
        c = 0;
    }
 
    static void initializeFloat(){
        ave = 0;
    }
 
    static void displayQuestion(){
     
        System.out.println("Average Of 3 Integers");
    } 
    static void getInputAndDisplayAnswer(){
     
        System.out.println("\n Input 3 Integers: ");
        System.out.print("a: ");
        a = input.nextInt();
        System.out.print("b: ");
        b = input.nextInt();
        System.out.print("c: ");
        c = input.nextInt();
        ave = a + b + c / 3;
        System.out.println(" The Average Of 3 Integers is " + ave);
     
    }
}

Yannnnn, excellent! Kuha mo na yung mindset. That's how you should see the "problem" na gusto mo i-solve. Step by step.

In reality talaga, programming is 90% solving the problem in paper and pen.... and 10% coding.

At saka, programming is an "art" also (lalo na sa naming ng methods/functions and flow). Malalaman mo kaagad na GOOD PROGRAMMER ang isang programmer pag unang tingin mo pa lang sa codes niya ay alam mo na kaagad ang ginawa ng codes niya....dahil mababasa mo based sa names ng methods niya and yung flow ay very methodical.

I think you are on the right track na. Keep that up and keep learning ;)

(****....and share your knowledge...turuan mo rin yung nangangamote mong kaklase kung meron....that will solidify your knowledge sa utak mo pag nagtuturo ka...)

;)
 
Yannnnn, excellent! Kuha mo na yung mindset. That's how you should see the "problem" na gusto mo i-solve. Step by step.

In reality talaga, programming is 90% solving the problem in paper and pen.... and 10% coding.

At saka, programming is an "art" also (lalo na sa naming ng methods/functions and flow). Malalaman mo kaagad na GOOD PROGRAMMER ang isang programmer pag unang tingin mo pa lang sa codes niya ay alam mo na kaagad ang ginawa ng codes niya....dahil mababasa mo based sa names ng methods niya and yung flow ay very methodical.

I think you are on the right track na. Keep that up and keep learning ;)

(****....and share your knowledge...turuan mo rin yung nangangamote mong kaklase kung meron....that will solidify your knowledge sa utak mo pag nagtuturo ka...)

;)
Ts ako nga po yung nagangamote classmate eh hahahah sa Last Sample meron daw error pero hindi ko malaman kung alen dun yung error. Nga po pala sir meron po ba kayong way para ma contact ko kayo in near future kung sakali marami pa kasi akong gusto matutunan about sa java programming lalo na sa OOP.
 
Yannnnn, excellent! Kuha mo na yung mindset. That's how you should see the "problem" na gusto mo i-solve. Step by step.

In reality talaga, programming is 90% solving the problem in paper and pen.... and 10% coding.

At saka, programming is an "art" also (lalo na sa naming ng methods/functions and flow). Malalaman mo kaagad na GOOD PROGRAMMER ang isang programmer pag unang tingin mo pa lang sa codes niya ay alam mo na kaagad ang ginawa ng codes niya....dahil mababasa mo based sa names ng methods niya and yung flow ay very methodical.

I think you are on the right track na. Keep that up and keep learning ;)

(****....and share your knowledge...turuan mo rin yung nangangamote mong kaklase kung meron....that will solidify your knowledge sa utak mo pag nagtuturo ka...)

;)
Ts saka ano po yung function na sinasabi mo tungkol sa ginawa mo ordering system about sa kunyari nag order ako ng burger tapus nag bago isip ko fries nlng. clue lang po para po nag iisip din ako. Dami ko na hingi tulong at ang dami nyo na po na bigay or na subo saking isipan at greatful po ako dun samalat po Ts.
 
Ts saka ano po yung function na sinasabi mo tungkol sa ginawa mo ordering system about sa kunyari nag order ako ng burger tapus nag bago isip ko fries nlng. clue lang po para po nag iisip din ako. Dami ko na hingi tulong at ang dami nyo na po na bigay or na subo saking isipan at greatful po ako dun samalat po Ts.

clue on how to delete a product from order list:
- kung sa arraylist, ang paglagay ng product is .add(index number)....ang pag delete .remove(index number)
- so sa order arraylist mo, use .remove and then provide the product's index number
 
clue on how to delete a product from order list:
- kung sa arraylist, ang paglagay ng product is .add(index number)....ang pag delete .remove(index number)
- so sa order arraylist mo, use .remove and then provide the product's index number
Ah salamat po Ts Saka ano po yung database? Kasi sabi ng prof namen diba pina gawa kami ng ordering system simple lang na dun daw kami mag base sa simple na yung kasi gagawa daw kami ng actual na system with database sample na binigay nya samin yung hotel reservation system.
 
Ts ok lang po ba mag tanong pano ko po kukunin naman yung input gamit oop sa multi dimensional array diba mag kaiba yun sa array. Kasi na uunawaan ko na po yung pag kuna ng input sa arraylist pero sa multi dimensional array ayaw gumana. Mag kaiba ang process ng pag kuha nun TS?
 
Ts pano pag ganito mutli 2d array sya

Code:
static String cinema [][] = new String [][] {

        {"Cinema 1", "A", "Avengers Infinity War [PG]", "200", "10:30am - 12:30pm", "12:30pm - 2:30pm"},
        {"Cinema 1", "B", "Ant Man [PG]", "230", "2:30pm - 4:30pm", "4:30pm - 6:30pm"},
        {"Cinema 1", "C", "Rampage [PG]", "250", "6:30pm - 8:30pm", "8:30pm - 10:30pm"},
        {"Cinema 2", "A", "The How's of Us [G]", "210", "10:30am - 12:30pm", "12:30pm - 2:30pm"},
        {"Cinema 2", "B", "How I Met Your Mother [PG]", "220", "2:30pm - 4:30pm", "4:30pm - 6:30pm"},
        {"Cinema 2", "C", "Fifty Shades [SPG]", "215", "6:30pm - 8:30pm", "8:30pm - 10:30pm"},
        {"Cinema 3", "A", "The Nun [SPG]", "220", "10:30am - 12:30pm", "12:30pm - 2:30pm"},
        {"Cinema 3", "B", "Anabelle [SPG]", "225", "2:30pm - 4:30pm", "4:30pm - 6:30pm"},
        {"Cinema 3", "C", "The Purge [SPG]", "190", "6:30pm - 8:30pm", "8:30pm - 10:30pm"}   

    };

Pano ko magagamit yung oop sa kanya
 
Ts tama po ba?

Code:
public class MainApp
{
    static ArrayList<TemplateCinema> mgaMovie;
    static ArrayList<TemplateCinema> orderNgMovie;
    static String cinemaList [][] = new String [][] {

        {"Cinema 1", "A", "Avengers Infinity War [PG]", "200", "10:30am - 12:30pm", "12:30pm - 2:30pm"},
        {"Cinema 1", "B", "Ant Man [PG]", "230", "2:30pm - 4:30pm", "4:30pm - 6:30pm"},
        {"Cinema 1", "C", "Rampage [PG]", "250", "6:30pm - 8:30pm", "8:30pm - 10:30pm"},
        {"Cinema 2", "A", "The How's of Us [G]", "210", "10:30am - 12:30pm", "12:30pm - 2:30pm"},
        {"Cinema 2", "B", "How I Met Your Mother [PG]", "220", "2:30pm - 4:30pm", "4:30pm - 6:30pm"},
        {"Cinema 2", "C", "Fifty Shades [SPG]", "215", "6:30pm - 8:30pm", "8:30pm - 10:30pm"},
        {"Cinema 3", "A", "The Nun [SPG]", "220", "10:30am - 12:30pm", "12:30pm - 2:30pm"},
        {"Cinema 3", "B", "Anabelle [SPG]", "225", "2:30pm - 4:30pm", "4:30pm - 6:30pm"},
        {"Cinema 3", "C", "The Purge [SPG]", "190", "6:30pm - 8:30pm", "8:30pm - 10:30pm"}   

    };
   
    public static void main(String [] args){
       
        initializemgaMovie();
       
        initializemgaOrderNgMovie();
       
        createAndStoreMovie();
       
        displayMovie();
    }
   
    static void initializemgaMovie(){
       
        mgaMovie = new ArrayList<TemplateCinema>();
    }
   
    static void initializemgaOrderNgMovie(){
       
        orderNgMovie = new ArrayList<TemplateCinema>();
    }
   
    static void createAndStoreMovie(){
       
        for(int i = 0; i<cinemaList.length; i++){
           
            TemplateCinema newMovie = new TemplateCinema();
            newMovie.setCinemaName(cinemaList[i][0]);
            newMovie.setMovieName(cinemaList[i][2]);
            newMovie.setCinemaCode(cinemaList[i][1]);
            newMovie.setPrice(Double.parseDouble(cinemaList[i][3]));
            newMovie.setTime(cinemaList[i][5]);
            mgaMovie.add(newMovie);   
        }
    }
   
    static void displayMovie(){
       
        System.out.println("Sm Cinema");
        System.out.println("**Movie**");
        for(TemplateCinema p : mgaMovie){
            System.out.println(p.getCinemaName() + " " + p.getCinemaCode() + " | " + p.getMovieName() + " | " + p.getPrice() + " | " +p.getTime());
        }
    }
   
}
 
Ts pano pag ganito mutli 2d array sya

Code:
static String cinema [][] = new String [][] {

        {"Cinema 1", "A", "Avengers Infinity War [PG]", "200", "10:30am - 12:30pm", "12:30pm - 2:30pm"},
        {"Cinema 1", "B", "Ant Man [PG]", "230", "2:30pm - 4:30pm", "4:30pm - 6:30pm"},
        {"Cinema 1", "C", "Rampage [PG]", "250", "6:30pm - 8:30pm", "8:30pm - 10:30pm"},
        {"Cinema 2", "A", "The How's of Us [G]", "210", "10:30am - 12:30pm", "12:30pm - 2:30pm"},
        {"Cinema 2", "B", "How I Met Your Mother [PG]", "220", "2:30pm - 4:30pm", "4:30pm - 6:30pm"},
        {"Cinema 2", "C", "Fifty Shades [SPG]", "215", "6:30pm - 8:30pm", "8:30pm - 10:30pm"},
        {"Cinema 3", "A", "The Nun [SPG]", "220", "10:30am - 12:30pm", "12:30pm - 2:30pm"},
        {"Cinema 3", "B", "Anabelle [SPG]", "225", "2:30pm - 4:30pm", "4:30pm - 6:30pm"},
        {"Cinema 3", "C", "The Purge [SPG]", "190", "6:30pm - 8:30pm", "8:30pm - 10:30pm"}  

    };

Pano ko magagamit yung oop sa kanya

You need multiple classes kung gusto ng OOP.
1) Cinema class
2) Movie class

Attributes ng Cinema class
- cinemaName
- theatres

Attributes ng Movie class
- movieTitle
- moviePrice
- movieSchedules
- movieRating
 
You need multiple classes kung gusto ng OOP.
1) Cinema class
2) môviê class

Attributes ng Cinema class
- cinemaName
- theatres

Attributes ng môviê class
- môviêTitle
- môviêPrice
- môviêSchedules
- môviêRating
Tapus sundan ko lang po yung ginawa nyo po ordering system getter and setter din po.
 
You need multiple classes kung gusto ng OOP.
1) Cinema class
2) môviê class

Attributes ng Cinema class
- cinemaName
- theatres

Attributes ng môviê class
- môviêTitle
- môviêPrice
- môviêSchedules
- môviêRating
TS ganito po ba.
Code:
public class MainApp
{
    //static Scanner userInput;
    static ArrayList<MovieClass> movie;
    static ArrayList<CinemaClass> cinema;
   
    static String cinemaList [][] = new String [][] {
        {"Cinema 1", "A", "Avengers Infinity War [PG]", "200", "10:30am - 12:30pm", "12:30pm - 2:30pm"},
        {"Cinema 1", "B", "Ant Man [PG]", "230", "2:30pm - 4:30pm", "4:30pm - 6:30pm"},
        {"Cinema 1", "C", "Rampage [PG]", "250", "6:30pm - 8:30pm", "8:30pm - 10:30pm"},
        {"Cinema 2", "A", "The How's of Us [G]", "210", "10:30am - 12:30pm", "12:30pm - 2:30pm"},
        {"Cinema 2", "B", "How I Met Your Mother [PG]", "220", "2:30pm - 4:30pm", "4:30pm - 6:30pm"},
        {"Cinema 2", "C", "Fifty Shades [SPG]", "215", "6:30pm - 8:30pm", "8:30pm - 10:30pm"},
        {"Cinema 3", "A", "The Nun [SPG]", "220", "10:30am - 12:30pm", "12:30pm - 2:30pm"},
        {"Cinema 3", "B", "Anabelle [SPG]", "225", "2:30pm - 4:30pm", "4:30pm - 6:30pm"},
        {"Cinema 3", "C", "The Purge [SPG]", "190", "6:30pm - 8:30pm", "8:30pm - 10:30pm"}   

    };
   
    public static void main (String [] args){
       
        initializeMovieClass();
       
        initializeCinemaClass();
       
        createAndStoreCinemaInArray();   
       
        displayMenu();
       
    }
   
    static void initializeMovieClass(){
       
        movie = new ArrayList<MovieClass>();
    }
   
    static void initializeCinemaClass(){
       
        cinema = new ArrayList<CinemaClass>();
       
    }
   
    static void createAndStoreCinemaInArray(){
       
        for(int i =0; i<cinemaList.length; i++){
           
            CinemaClass newCinema = new CinemaClass();
            newCinema.setCinemaName(cinemaList[i][0]);
            newCinema.setTheatres(cinemaList[i][1]);
           
            cinema.add(newCinema);
           
            MovieClass newMovie = new MovieClass();
            newMovie.setMovieTitle(cinemaList[i][2]);
            newMovie.setMoviePrice(Double.parseDouble(cinemaList[i][3]));
            newMovie.setMovieSchdedules(cinemaList[i][4]);
           
            movie.add(newMovie);
           
        }
    }
   
    static void displayMenu(){
        System.out.println("Welcome To Movie Ng Bayan");
        System.out.println("List Of Movie And Schedule");
        for(CinemaClass c: cinema){
            System.out.println(c.getCinemaName() + c.getTheatres());   
       
        }
    }
}


Heto po isang pang class yung cinemaClass

import java.util.*;
public class CinemaClass
{
    ArrayList<MovieClass> movies;
    private String cinemaName;
    private String theatres;
   
    public CinemaClass(){
        movies = new ArrayList<>();
    }
   
    public void setCinemaName(String cinemaName){
        this.cinemaName = cinemaName;
    }
   
    public void setTheatres(String theatres){
        this.theatres = theatres;
    }
   
    public String getCinemaName(){
        return cinemaName;
    }
   
    public String getTheatres(){
        return theatres;
    }
}


Tapus heto naman po yung movieClass

public class MovieClass
{
    private String movieTitle;
    private double moviePrice;
    private String movieSchedules;
    private String movieRating;
   
    public void setMovieTitle(String movieTitle){
        this.movieTitle = movieTitle;
    }
   
    public void setMoviePrice(double moviePrice){
        this.moviePrice = moviePrice;
    }
   
    public void setMovieSchdedules(String movieSchedules){
        this.movieSchedules = movieSchedules;
    }
   
    public void setMpvieRating(String movieRating){
        this.movieRating = movieRating;
    }
   
    public String getMovieTitle(){
        return movieTitle;
    }
   
    public double getMoviePrice(){
        return moviePrice;
    }
   
    public String getMovieSchedules(){
        return movieSchedules;
    }
   
    public String getMovieRating(){
        return movieRating;
    }
}

Ganito po ba pa guide lang po ako.
 
Ts bale enextends ko si cinemaClass para magamit ko yung getter and setter ng movieClass tama po ba ang ginawa ko?
 
Status
Not open for further replies.
Back
Top