Java Problem Source code with populate results

Hey guys... including JoshAH.. i have this program called MovieBooking and the problem is i cant populate the final result to show onto the JTextArea.. If u have MSN.. i would like to share my Java source code to solve the problem...my submission for the project is tomorrow.. i only wan to populate the final result but i tried many times by my own...even look through some examples on the net...

[404 byte] By [mzbarz1986a] at [2007-11-26 18:26:53]
# 1
1. Don't post on this forum trying to get people to use MSN.Just post your code.2. Your period key sticks. Get it fixed.3. Please use correct English, that includes capitalization.
zadoka at 2007-7-9 6:00:58 > top of Java-index,Java Essentials,Java Programming...
# 2

> Hey guys... including JoshAH.. i have this program

> called MovieBooking and the problem is i cant

> populate the final result to show onto the

> JTextArea.. If u have MSN.. i would like to share my

> Java source code to solve the problem...my submission

> for the project is tomorrow.. i only wan to populate

> the final result but i tried many times by my

> own...even look through some examples on the net...

Sounds related to your other post:

http://forum.java.sun.com/thread.jspa?threadID=5136250&messageID=9496088#9496088

You should be replying to that post. Also, stop trying to hijack other people topics by asking for JosAH so respond to you.

zadoka at 2007-7-9 6:00:58 > top of Java-index,Java Essentials,Java Programming...
# 3

alright zadok..

Yeah.. sorry about hijacking

Here are my Codes:

MovieBooking.java

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

public class MovieBooking extends JFrame

{

private JPanel p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11;

private JLabel titleLabel,movieLabel,timeLabel,ticketLabel,priceLabel;

private JTextField ticketField;

private JButton calculateButton,clearButton;

private JComboBox movieComboBox,timeComboBox;

private JScrollPane scrollPane;

private Object movie, time;

private MovieCon mc = new MovieCon();

public static void main (String [] args)

{

MovieBooking p=new MovieBooking();

p.setVisible(true);

p.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

public MovieBooking()

{

mc = new MovieCon();

setSize(400,550);

setTitle("");

p1=new JPanel(); //declare all the JPanel

p2=new JPanel();

p3=new JPanel();

p4=new JPanel();

p5=new JPanel();

p6=new JPanel();

p7=new JPanel();

p8=new JPanel();

p9=new JPanel();

p10=new JPanel();

p11=new JPanel();

titleLabel=new JLabel("Movie Booking"); //declare a label for title

movieLabel=new JLabel("Choose a movie"); //declare a label for choose movie

timeLabel=new JLabel("Choose a show time"); //declare a label for time label

ticketLabel=new JLabel("Enter no. tickets"); //declare a label for ticket label

priceLabel=new JLabel("Total Price:"); //declare a label for price total price

ticketField=new JTextField(2); //textfield for user to enter no. of ticket

calculateButton=new JButton("Calculate"); //button for the calculate

clearButton=new JButton("Clear"); // button to clear

String[] MovieString = { "Choose movie", "Flags of Our Father", "Casino Royale", "Tanaclous D" };

movieComboBox=new JComboBox(MovieString); //comboBox for the movie slot

String[] TimeString = { "Choose Time", "2.30pm Week days", "12.30pm Week ends", "11.30pm Weeks Night" };

timeComboBox=new JComboBox(TimeString); //comboBox for the time

JTextArea area1=new JTextArea("Movie" + "\tTime" + "\t#Tkt"+ "\t$\n"); //declare the textarea

area1.setEditable(false); //set uneditable

JScrollPane scrollPane = new JScrollPane(area1,

JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,

JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);

p1.setLayout(new FlowLayout());

p1.add(titleLabel);

p2.setLayout(new FlowLayout());

p2.add(movieLabel);

p2.add(movieComboBox);

p3.setLayout(new FlowLayout());

p3.add(timeLabel);

p3.add(timeComboBox);

p4.setLayout(new FlowLayout());

p4.add(ticketLabel);

p4.add(ticketField);

p5.setLayout(new FlowLayout());

p5.add(calculateButton);

p5.add(clearButton);

p7.setLayout(new GridLayout(1,1));

p7.add(scrollPane);

p8.setLayout(new FlowLayout());

p8.add(priceLabel);

getContentPane().setLayout(new GridLayout(7,1)); //Panel to reflect on the HTML

getContentPane().add(p1);

getContentPane().add(p2);

getContentPane().add(p3);

getContentPane().add(p4);

getContentPane().add(p5);

getContentPane().add(p7);

getContentPane().add(p8);

calculateButton.addActionListener(new calculateTicket());

clearButton.addActionListener(new clearTicket());

movieComboBox.addItemListener(new movieListener());

timeComboBox.addItemListener(new timeListener());

}

public class clearTicket implements ActionListener

{

public void actionPerformed(ActionEvent a)

{

movieComboBox.setSelectedIndex(0);

timeComboBox.setSelectedIndex(0);

ticketField.setText("");

}

}

public class calculateTicket implements ActionListener

{

public void actionPerformed(ActionEvent a)

{

String[] rec = new String[90];

String ticket=mc.getTic(ticketField.getText());

movie = mc.getMovie(movie);

mc.getDtime(time);

//mc.getMovie(movie);

double price=mc.getPrice(dTime,ticket);

mc.createAcc(movie,time,ticketField.getText(),price);

//rec=

}

}

class movieListener implements ItemListener {

// This method is called only if a new item has been selected.

public void itemStateChanged(ItemEvent evt) {

movieComboBox = (JComboBox)evt.getSource();

// Get the affected item

movie = evt.getItem();

if (evt.getStateChange() == ItemEvent.SELECTED)

{

// Item was just selected

} else if (evt.getStateChange() == ItemEvent.DESELECTED) {

// Item is no longer selected

}

// System.out.println(item); //monitor item

}

}

class timeListener implements ItemListener {

// This method is called only if a new item has been selected.

public void itemStateChanged(ItemEvent evt) {

timeComboBox = (JComboBox)evt.getSource();

// Get the affected item

time = evt.getItem();

if (evt.getStateChange() == ItemEvent.SELECTED)

{

// Item was just selected

} else if (evt.getStateChange() == ItemEvent.DESELECTED) {

// Item is no longer selected

}

// System.out.println(item); //monitor item

}

}

}

MovieCon.java

public class MovieCon

{

private MovieData md;

private MovieSec ms ;

private String movie, time,ticket;

private double price;

private String mth;

public MovieCon()

{

md=new MovieData();

}

public void createAcc(String movie,String time, String ticket, double price)

{

md.storeData(new MovieSec(movie,time,ticket,price));

}

/*public String[] getAcc(String name)

{

String[] recInfo =new String[6];

sel=db.getAccRec(name);

if(sel==null) // we could not locate this name in our DataStorage

{

recInfo[0]=null;

recInfo[1]=null;

recInfo[2]=null;

recInfo[3]=null;

recInfo[4]=null;

recInfo[5]=null;

}

else

{

recInfo[0]=sel.getName();

recInfo[1]=sel.getDate();

recInfo[2]=sel.getMth();

recInfo[3]=sel.getYear();

recInfo[4]=sel.getDays();

recInfo[5]=sel.getPremium();

}

return recInfo;

}*/

public String getDtime(Object time)

{

float dtime=0;

mth= new String();

mth=time.toString();

if(mth=="2.30pm Week days")

{

dtime=6.5f;

}

else if(mth=="12.30pm Week ends")

{

dtime=7.5f;

}

else if(mth=="11.30pm Weeks Night")

{

dtime=8.5f;

}

return mth;

}

public String getMovie(Object movie)

{

String pmovie= new String();

pmovie=movie.toString();

return pmovie;

}

public String getTime(Object time)

{

String ptime= new String();

ptime=time.toString();

return ptime;

}

public String getTic(Object ticket)

{

String ptic= new String();

ptic=ticket.toString();

//float dtic=(String)ptic;

return ptic;

}

public double getPrice(String dtime,String ticket)

{

double price=0.0f;

double dtime2 = Double.parseDouble(dtime);

double ticket2 = Double.parseDouble(ticket);

price=(dtime2*ticket2);

return price;

}

}

MovieData.java

import java.util.Vector;

public class MovieData

{

private Vector user;

public MovieData()

{

user= new Vector(1,1);

}

public void storeData(MovieSec movieD)

{

user.add(movieD); // store an address record into DataBase

}

/*public MovieSec getAccRec(String name) // Linear Search of a Vector

{

Selection returnObj=null; // we will return a null if name is not FOUND in vector

for(int i=0;i<cus.size();i++) // loop through the entire vector to find a match

{

returnObj=(Selection)cus.get(i); // fetch the Nth element

if(returnObj.getName().equals(name))

{

break;

} // end if

} //end for

return returnObj;

}*/

}

MovieSec.java

public class MovieSec

{

private String movie,time,ticket;

private double price;

//

public MovieSec(String m,String t, String ti, double p)

{

movie=m;

time=t;

ticket=ti;

price=p;

}

public void setMovie(String m)

{

movie=m;

}

public String getMovie()

{

return movie;

}

public void setTime(String t)

{

time=t;

}

public String getTime()

{

return time;

}

public void setTicket(String ti)

{

ticket=ti;

}

public String getTicket()

{

return ticket;

}

public void setPrice(double p)

{

price=p;

}

public double getPrice()

{

return price;

}

}

Message was edited by:

mzbarz1986>

mzbarz1986a at 2007-7-9 6:00:58 > top of Java-index,Java Essentials,Java Programming...
# 4

> alright zadok..

>

> Here are my Codes:

No one want to read through that. If you post code try to make it a Short,Self Contained, Compilable and Executable.Also ask a specific question, I still don't know what you are trying to do? What your problem is? If you are getting error messages?

If you want a better response to your questions I would suggest you stop cross posting and read over this:

http://catb.org/esr/faqs/smart-questions.html

zadoka at 2007-7-9 6:00:58 > top of Java-index,Java Essentials,Java Programming...
# 5

alright.. here is my error

Folder\MovieBooking.java:135: cannot find symbol

symbol : variable dTime

location: class MovieBooking.calculateTicket

double price=mc.getPrice(dTime,ticket);

^

Folder\MovieBooking.java:136: createAcc(java.lang.String,java.lang.String,java.lang.String,double) in MovieCon cannot be applied to (java.lang.Object,java.lang.Object,java.lang.String,double)

mc.createAcc(movie,time,ticketField.getText(),price);

^

2 errors

mzbarz1986a at 2007-7-9 6:00:58 > top of Java-index,Java Essentials,Java Programming...
# 6

> alright.. here is my error

Why didn't you say this to begin with?

> Folder\MovieBooking.java:135: cannot find symbol

> symbol : variable dTime

> location: class MovieBooking.calculateTicket

> double price=mc.getPrice(dTime,ticket);

> ^

Well you are trying use dTime but it appears you have not declared it anywhere.

> cc(java.lang.String,java.lang.String,java.lang.String,

> double) in MovieCon cannot be applied to

> (java.lang.Object,java.lang.Object,java.lang.String,do

> uble)

>

> c.createAcc(movie,time,ticketField.getText(),price);

>^

createAcc() doesn't accept the parameters that you are trying to give it.

zadoka at 2007-7-9 6:00:58 > top of Java-index,Java Essentials,Java Programming...
# 7
I'm currently have headache now.... i've been doing this since 3 weeks.. and still i cant get to know the problem with the 2nd error.... if u mind compile the codes.. it would be appreciated...
mzbarz1986a at 2007-7-9 6:00:58 > top of Java-index,Java Essentials,Java Programming...
# 8
> if u mind compile the> codes.. it would be appreciated...Do your own homework!
zadoka at 2007-7-9 6:00:58 > top of Java-index,Java Essentials,Java Programming...
# 9
Awww. man
mzbarz1986a at 2007-7-9 6:00:58 > top of Java-index,Java Essentials,Java Programming...
# 10
> Awww. manCheating will hurt you in the long run and your classmates in the short term. Why do you think anyone would want to help you cheat?EDIT: the real question is why do you even want someone to help you cheat?
zadoka at 2007-7-9 6:00:58 > top of Java-index,Java Essentials,Java Programming...
# 11

You defineprivate Object movie, time;

Then you call mc.createAcc(movie,time,ticketField.getText(),price);

and expect time to be of type String.

You also have thismc.getDtime(time);

double price=mc.getPrice(dTime,ticket);

I guess what you wanted to do is

String dTime = mc.getDtime(time);

//mc.getMovie(movie);

double price=mc.getPrice(dTime,ticket);

mc.createAcc(movie,dTime,ticketField.getText(),price);

but I'm not sure since I'm not gonna spend some hours digging into what you wrote there...

Peetzorea at 2007-7-9 6:00:58 > top of Java-index,Java Essentials,Java Programming...
# 12
ITS NOT CHEAT.... if i were to change the 2nd error... other parts in the program have errors too.......... IM NOT CHEATING OK
mzbarz1986a at 2007-7-9 6:00:58 > top of Java-index,Java Essentials,Java Programming...
# 13
i'm only asking a tiny help in solving my problem in the java program... most of my friends have done theirs... this program... i've been doing it alone ok......
mzbarz1986a at 2007-7-9 6:00:58 > top of Java-index,Java Essentials,Java Programming...
# 14
thanks for the tip PeetZore..... i will make changes to the program now... if i have other problems.. i post here ok.....Message was edited by: mzbarz1986
mzbarz1986a at 2007-7-9 6:00:58 > top of Java-index,Java Essentials,Java Programming...
# 15

> ITS NOT CHEAT.... if i were to change the 2nd

> error... other parts in the program have errors

> too.......... IM NOT CHEATING OK

Looks like.... it's time to drop.... that course now.... before it's too late. Surely there's.... something else.... you can major in.... ?

warnerjaa at 2007-7-21 17:21:00 > top of Java-index,Java Essentials,Java Programming...
# 16

> ITS NOT CHEAT.... if i were to change the 2nd

> error... other parts in the program have errors

> too.......... IM NOT CHEATING OK

Having someone else fix compile errors for you on an assignment is Cheating. What do you define as cheating? (Or more importantly what does your professor define as cheating?)

zadoka at 2007-7-21 17:21:00 > top of Java-index,Java Essentials,Java Programming...
# 17
I can tell you have been working really hard and long on this code. Your right hand is so tired it falls on the dot-key all the time, even in the middle of a sentence!
Peetzorea at 2007-7-21 17:21:00 > top of Java-index,Java Essentials,Java Programming...