What's new

Closed Need help optimizing your program code? pasok!

Status
Not open for further replies.

mrHazan

Forum Veteran
Elite
Joined
Mar 21, 2016
Posts
1,929
Reaction
1,946
Points
722
  • 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.
 
Sir gumana sya ☺☺☺

bakit kaya pag if(cinema[0] == cinemaInput && cinema[1] == movieInput? Hindi gumagana?

Pero pag if(cinema[0].equals(cinemaInput) && cinema[1].equals(movieInput) 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.
 
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.
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.
 
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.
bale yung myString doon eh yung value dun sa array.
 
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.
Ah Galing Salamat Sir. Pano Kita Message Pag need ko Help mo Hindi pa ako Establish Eh.
 
Sir nag error pag total = Integer.parseInt(cinema[3]) * seatInput;
check mo dapat int ang seatInput. Tapos inputUser.nextInt() ang gamitin mo.
seatInput lang ang hindi String. int dapat yan.
 
Last edited:
check mo dapat int ang seatInput. Tapos inputUser.getInt() ang gamitin mo.
seatInput lang ang hindi String. int dapat yan.
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?
 
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?
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.
 
Ang
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.
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 ☺
 
S
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 ☺
Sir meron ka po ba dyan mga exercise na madali lang pang begginner po.
 
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 :(
 

Attachments

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 :(
Sir pwede ako mag suggest hindi ko alam kong tama pero try mo mag enum tapus switch.
 
Sir pwede ako mag suggest hindi ko alam kong tama pero try mo mag enum tapus switch.
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
 
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
Sa c++ ang function call:

Code:
functionName(parameters);
bale sa case mo.
Code:
q1e();

Ilagay mo lang sa case block tapos break;
 
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 :(
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.
 
Status
Not open for further replies.

Similar threads

Back
Top