Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Java  Access control modifiers and Constructors

Posted on 2007-07-22
2
Medium Priority
?
326 Views
Last Modified: 2013-11-23
Good afternoon,

I am try to write the code for a program that calls for the following information:

A class, Cinema has the following features:

Fields:

public static String theatre;
private String title;
private String kind; // Drama, comedy, family, ..
private String actor;
private String actress;
private int ticketPrice;

Constructors::

Cinema()

No-arg constructor. Does not initialize to anything.

Cinema(String titl, String knd, String actr, String actrs, int tp)

Initializes fields respectively.

Methods:

public void display()

Displays all field values- title, kind, actor and actress.

public int totalTicketPrice(int num)

Computes the total ticket price for num, tickets
Write a main class and create an object of the Movie class. Use the methods to print
results. Give your own values. Also, print the value of the static field

Here is the code that I have already written so far:
class Cinema
{
public static void main(String[] args)
{
Cinema cinema1=new cinema();
cinema1.title="Star Wars";
cinema1.kind="Drama";
cinema1.actor="Mark Hamill";
cinema1.actress="Carrie Fisher";
cinema1.ticketPrice=8;
cinema1.display();
System.out.println("Total cost is:" +cinema1.ticketPrice*(3));
}
}
class cinema1
{      
private String title;
private String kind;
private String actor;
private String actress;
private int ticketPrice;
cinema1(String titl, String knd, String actr, String actrs, int tp)
{
title = titl;
kind = knd;
actor = actr;
actress = actrs;
ticketPrice = tp;
}
}
I keep getting the errors saying cannot find the symbols I have created. Can someone point me in the right direction? Thank you.
0
Comment
Question by:jachill98
2 Comments
 

Author Comment

by:jachill98
ID: 19543752
anyone out there?
0
 
LVL 92

Accepted Solution

by:
objects earned 2000 total points
ID: 19544160
public class Cinema
{
private String title;
private String kind;
private String actor;
private String actress;
private int ticketPrice;

public Cinema()
{
}

public Cinema(String titl, String knd, String actr, String actrs, int tp)
{
title = titl;
kind = knd;
actor = actr;
actress = actrs;
ticketPrice = tp;
}

public static void main(String[] args)
{
Cinema cinema1=new Cinema();
cinema1.title="Star Wars";
cinema1.kind="Drama";
cinema1.actor="Mark Hamill";
cinema1.actress="Carrie Fisher";
cinema1.ticketPrice=8;
cinema1.display();
System.out.println("Total cost is:" +cinema1.ticketPrice*(3));
}
}
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses
Course of the Month14 days, 11 hours left to enroll

578 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question