1. Welcome to PHCorner Forums. Take a moment to Sign up and gain unlimited access and extra privileges that guests are not entitled to, such as:

    All that and more! Registration is quick, simple and absolutely free. Join our community today!

C and C++ C# Java Need help optimizing your program code? pasok!

Discussion started by mrHazan, Oct 6, 2018.

  1. mrHazan

    mrHazan Eternal Poster Established

    • Kung may machine problem kayo sa school at nagawa niyo na.
      Baka gusto niyo ipost dito para matulungan ka, hindi lang ako, pati na rin ng iba, na mabigyan ka ng mas efficient o mas optimized na code kung may iimprove pa.

    • Hindi ko gagawin ang machine problems niyo. Bibigyan ko lang kayo ng idea kung paano mas gaganda program code niyo.

    • Pwede rin humingi ng idea kung paano gawin ang assignments and MP niyo.

    • C++, C, C#, Java lang kaya ko. Pero try niyo rin yung iba, I'm willing to learn din naman.
     
    MengHao, gantz012, kaguradapi and 6 others like this.
  2. Sir gumana sya ☺☺☺

    bakit kaya pag if(cinema[0] == cinemaInput && cinema[1] == môviêInput? Hindi gumagana?

    Pero pag if(cinema[0].equals(cinemaInput) && cinema[1].equals(môviêInput) gumagana sya.

    Ang hindi ko nlng ma intindihan sir yun sa total = stoi(cinema[3] * seatInput;

    Nag search ako ang stoi pala sa c++ parang pang palit ng String to integer tama po ba o mali

    Sa java po meron Integer.parseInt kaso pano po kaya yun icoconvert sa Java sir. Nga pala po sir salamat tulong. Sana matulungan nyo po pa ako sa mga susunod na mga katanungan ko. Salamat po.
     
  3. mrHazan

    mrHazan Eternal Poster Established

    value of array string kasi yung isa tapos yung isa string lang.
    Kaya .equals dapat.

    para maging int ang string:
    myInt = Integer.parseInt(myString);

    Bale.. Kukuha ka ng number of seats from user.
    Tapos:
    total = Integer.parseInt(myString) * inputSeat
    lang.
     
  4. mrHazan

    mrHazan Eternal Poster Established

    bale yung myString doon eh yung value dun sa array.
     
  5. Ah Galing Salamat Sir. Pano Kita Message Pag need ko Help mo Hindi pa ako Establish Eh.
     
  6. mrHazan

    mrHazan Eternal Poster Established

    Dito lang.
     
  7. Sir nag error pag total = Integer.parseInt(cinema[3]) * seatInput;
     
  8. mrHazan

    mrHazan Eternal Poster Established

    check mo dapat int ang seatInput. Tapos inputUser.nextInt() ang gamitin mo.
    seatInput lang ang hindi String. int dapat yan.
     
    Last edited: Oct 6, 2018
  9. Sir tama po int po pala dapat bale ang error pala yung sa while loop yung mamimili ng time hindi nya kasi nakukuha yung timeInput = cinema[4].

    Sir pano ba maging marunong sa pag popogram?
     
  10. mrHazan

    mrHazan Eternal Poster Established

    Code:
    import java.util.*;
    
    public class CinemaTickitingMachine{
    
    static String cinemaInput;
    static int cinemaIndex = 1;
    static String môviêInput;
    static String timeInput;
    static String seatInput;
    static boolean successPicking = false;
    static float total;
    static String currentCinemaIndex;
    static Scanner userInput = new Scanner(System.in);
    
    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"}
    
    };
    
    public static void main (String [] args){
    
    displayMenu();
    pickTheCinemaAndmôviê();
    }
    
    static void displayMenu(){
    
    System.out.println("<<<<<<[Welcome to World Cinema]>>>>>>\n");
    System.out.println("Cinema List:\n");
    System.out.println(cinema[0][0] + ":\n");
    currentCinemaIndex = cinema[0][0];
    
    //Show the môviês in each cinema
    for(int i = 0; i < 9; i++)
    {
    if(currentCinemaIndex != cinema[0])
    {
    currentCinemaIndex = cinema[0];
    System.out.println("======================================\n");
    System.out.println(cinema[0] + ":\n");
    }
    
    System.out.println( "[" + cinema[1] + "] " + cinema[2] + "\n");
    }
    
    //Pick what cinema
    System.out.println( "\n\nSelect cinema [1|2|3]: ");
    cinemaInput = userInput.next();
    cinemaInput = "Cinema " + cinemaInput;
    
    //Pick what môviê
    System.out.println( "Select what môviê [A|B|C]: ");
    môviêInput = userInput.next();
    
    System.out.println( "======================================\n");
    System.out.println( "Selected:\n\n");
    
    }
    static void pickTheCinemaAndmôviê(){
    //Search the picked cinema and môviê then output in the screen
    for(int i = 0; i < 9; i++)
    {
    if(cinema[0] == cinemaInput && cinema[0] == môviêInput)
    {
    System.out.println( cinema[2] + "\n");
    System.out.println("Price: P " + cinema[3] + "\n");
    System.out.println( "Time Available: \n");
    System.out.println("[1]" + cinema[4] + "\n");
    System.out.println("[2]" + cinema[5] + "\n");
    System.out.println("[3]" + "CANCEL\n\n");
    
    while (true)
    {
    System.out.println("Select time [1|2]: ");
    timeInput = userInput.next();
    
    if(timeInput == "1")
    {
    timeInput = cinema[4];
    successPicking = true;
    break;
    }
    else if (timeInput == "2")
    {
    timeInput = cinema[5];
    successPicking = true;
    break;
    }
    else if (timeInput == "3")
    {
    //system("cls");
    //ibig sabihin po ba ng system("cls");
    //ganito po ba yan sa Java?
    
    System.exit(0);
    break;
    }
    else
    {
    System.out.println("Invalid input, please try again...");
    }
    }
    if(successPicking)
    {
    System.out.println("How many seats or tickets: ");
    seatInput = userInput.next();
    
    //total = stoi(cinema[3]) * seatInput;
    //hindi ko alam kung ano stoi sa c++ sir
    //kinomment ko hindi ako kasi alam kung pano ko icocovert sa Java yan.
    
    System.out.println("======================================\n");
    System.out.println("môviê\n");
    System.out.println(cinema[2] + "\n");
    System.out.println("Time: " + timeInput + "\n");
    System.out.println("Price: P " + cinema[3] + "\n");
    System.out.println("Seats: " + seatInput + "\n");
    System.out.println("Total: " + total);
    }
    else
    {
    break;
    }
    }
    }
    return;
    }
    }
    Subukan mo ulit na .equals ang gamitin mo.
     
  11. mrHazan

    mrHazan Eternal Poster Established

    practice lang. Hanap ka ng machine problems tapos solve mo.
     
  12. Ang
    Ang galing galing nyo po talaga sir tama yung equal.

    Sir pa help nman ako sa popogram gusto ko kasi talaga matuto yung pag meron nag tanon sayo masasagot mo tulad nyo po lahat po ng tinatanong ko nasasagot nyo po how to be you po sabi nga ng mga bata ngayon ☺
     
  13. S
    Sir meron ka po ba dyan mga exercise na madali lang pang begginner po.
     
  14. mrHazan

    mrHazan Eternal Poster Established

    Wala eh hanap ka nalang sa net. :) Marami dun.
    Buti nakatulong. :)
     
    Donqexote likes this.
  15. pano sir ma call yung q1e() (yung my white circle) gamit yung Switch statement(red circle)?
    bali po kapag nag output na po yung number the mag cacall po siya sa quiestion()

    example: case 1: 1 then call q1e();

    pano po yan di ko po mafix e hehe sana po matulongan nyo po ako :(
     
  16. Sir pwede ako mag suggest hindi ko alam kong tama pero try mo mag enum tapus switch.
     
  17. mag rarandom kasi sir yung number 1-15. the each number ay my naka assign na question. pero di ako marunong kun pano mag call nang question na naka assign per number. hehe
     
  18. mrHazan

    mrHazan Eternal Poster Established

    Sa c++ ang function call:

    Code:
    functionName(parameters);
    bale sa case mo.
    Code:
    q1e();
    Ilagay mo lang sa case block tapos break;
     
  19. try ko po master hehe
     
  20. mrHazan

    mrHazan Eternal Poster Established

    Yan ba instruction sa inyo? Through function ang pagtawag ng question?
    Simple array maaachieve mo yung gusto mo maachieve.
    Kasi sa case na yan, malaki ang possibility na maulit ng maulit yung question.
     
  1. PHCorner uses cookies to help personalise content and tailor your experience. By continuing to use this site, you are consenting to our use of cookies. Accept Learn More
    Dismiss Notice