Question

I have this java program that I need to add an abstract method and polymorphism to...

I have this java program that I need to add an abstract method and polymorphism to it :

import java.util.Scanner;

//class and encapsulation
class BookTheTicket {

private String movieName;
private String theatreName;

private int ticketCost;

void myAllmovies() {

System.out.println("-------Listing the movies:------");
System.out.println(" 1.DDLJ ------------ $40 \n 2.kkr---------$.50 \n 3.game-movie --------$60 \n 4.fun movie ----- $.70 ");


}

}
// inheritence
class theater extends BookTheTicket{
private int numOfTickets;
void theater() {
System.out.println("*******Listing the theatre:******* \n 1.coco cola tld \n 2.koi gandhi kr");
int k;
int an;
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
if (n == 1) {
System.out.println("*******coco cola tld theater*******");
System.out.println("*******choose a movie name*******");
System.out.println("------Listing the movie:------\n 1.DDLJ \n 2.kkr ");
int monum = sc.nextInt();
if (monum == 1) {
System.out.println("DDLJ new movie @ coco cola tld theater");
System.out.println("Enter how many ticket to be booked:---");
int r = sc.nextInt();
int left= numOfTickets-r;
int amount=40*r;
System.out.println("press 1 to continue booking ticket----");
int h = sc.nextInt();
System.out.println("\n\n\n");
if (h == 1) {
System.out.println("******************************************************");
System.out.println("theater ------------------- coco cola tld theater");
System.out.println("movie --------------------- DDLJ");
System.out.println("cost ---------------------- $"+amount);
System.out.println("******************************************************");
}

}
if (monum == 2) {
System.out.println("kkr @ coco cola tld theater");
System.out.println("Enter how many ticket to be booked:---");
int r = sc.nextInt();
int left= numOfTickets-r;
int amount=50*r;
System.out.println("press 1 to continue booking ticket----");

int h = sc.nextInt();
System.out.println("\n\n\n");
if (h == 1) {
System.out.println("******************************************************");
System.out.println("theater ------------------- coco cola tld");
System.out.println("movie --------------------- kkr");
System.out.println("cost ---------------------- Rs"+amount);
System.out.println("******************************************************");
}

}

}
if (n == 2) {
System.out.println("*******koi gandhi kr theater*******");
System.out.println("*******choose a movie name*******");
System.out.println("------Listing the movie:------\n 1.DDLJ \n 2.kkr ");
int p = sc.nextInt();
int monum = sc.nextInt();
if (monum == 1) {
System.out.println("game-movie @ koi gandhi kr theater");
System.out.println("Enter how many ticket to be booked:---");

int r = sc.nextInt();
int left= numOfTickets-r;
int amount=60*r;
System.out.println("press 1 to continue booking ticket----");

int h = sc.nextInt();
System.out.println("\n\n\n");
if (h == 1) {
System.out.println("******************************************************");
System.out.println("theater ------------------- koi gandhi kr");
System.out.println("movie --------------------- game-movie");
System.out.println("cost ---------------------- Rs."+amount);
System.out.println("******************************************************");
}

}
if (monum== 2) {
System.out.println("fun movie @ koi gandhi kr theater");
System.out.println("Enter how many ticket to be booked:---");

int r = sc.nextInt();
int left= numOfTickets-r;
int amount=70*r;
System.out.println("press 1 to continue booking ticket----");

int h = sc.nextInt();
System.out.println("\n\n\n");
if (h == 1) {
System.out.println("******************************************************");
System.out.println("theater ------------------- koi gandhi kr ");
System.out.println("movie --------------------- fun movie");
System.out.println("cost ---------------------- Rs."+amount);
System.out.println("******************************************************");
}

}
}

}
}

public class Main {

public static void main(String[] args) {
BookTheTicket ob1 = new BookTheTicket();

BookTheTicket [] moviename = new BookTheTicket[2];
moviename[0] = ob1;
theater ob2 = new theater();
moviename[1] = ob2;

System.out.println("@@@@@@@@@@ hello @@@@@@@@@@@@@ customer @@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n");
System.out.println("---------1.list of movies and their prices--------- \n-------2.acces and book tickets through theaters---");

System.out.println("\n@@@@@@@@@@ thanks @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
Scanner d = new Scanner(System.in);
int h = d.nextInt();
switch (h) {
case 1: {
ob1.myAllmovies();
break;
}
case 2: {

ob2.theater();
}
}

}

}

for my final project I'm supposed to make a java program that must have:
oop objects and classes
abstract class
encapsulation
inheritance
polymorphism

and I have this code so far which I think it is missing an abstract class and polymorphism

0 0
Add a comment Improve this question Transcribed image text
Answer #1

//i did modifications in the above code

abstract class BookTheTicket {//abstract class

private String movieName;
private String theatreName;

private int ticketCost;

abstract void viewAvailablerefreshments();//abstract method

void myAllmovies() {

System.out.println("-------Listing the movies:------");
System.out.println(" 1.DDLJ ------------ $40 \n 2.kkr---------$.50 \n 3.game-movie --------$60 \n 4.fun movie ----- $.70 ");


}

}

class theater extends BookTheTicket{
private int numOfTickets;
void theater() {
System.out.println("*******Listing the theatre:******* \n 1.coco cola tld \n 2.koi gandhi kr");
int k;
int an;
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
if (n == 1) {
System.out.println("*******coco cola tld theater*******");
System.out.println("*******choose a movie name*******");
System.out.println("------Listing the movie:------\n 1.DDLJ \n 2.kkr ");
int monum = sc.nextInt();
if (monum == 1) {
System.out.println("DDLJ new movie @ coco cola tld theater");
System.out.println("Enter how many ticket to be booked:---");
int r = sc.nextInt();
int left= numOfTickets-r;
int amount=40*r;
System.out.println("press 1 to continue booking ticket----");
int h = sc.nextInt();
System.out.println("\n\n\n");
if (h == 1) {
System.out.println("******************************************************");
System.out.println("theater ------------------- coco cola tld theater");
System.out.println("movie --------------------- DDLJ");
System.out.println("cost ---------------------- $"+amount);
System.out.println("******************************************************");
}

}
if (monum == 2) {
System.out.println("kkr @ coco cola tld theater");
System.out.println("Enter how many ticket to be booked:---");
int r = sc.nextInt();
int left= numOfTickets-r;
int amount=50*r;
System.out.println("press 1 to continue booking ticket----");

int h = sc.nextInt();
System.out.println("\n\n\n");
if (h == 1) {
System.out.println("******************************************************");
System.out.println("theater ------------------- coco cola tld");
System.out.println("movie --------------------- kkr");
System.out.println("cost ---------------------- Rs"+amount);
System.out.println("******************************************************");
}

}

}
if (n == 2) {
System.out.println("*******koi gandhi kr theater*******");
System.out.println("*******choose a movie name*******");
System.out.println("------Listing the movie:------\n 1.DDLJ \n 2.kkr ");
int p = sc.nextInt();
int monum = sc.nextInt();
if (monum == 1) {
System.out.println("game-movie @ koi gandhi kr theater");
System.out.println("Enter how many ticket to be booked:---");

int r = sc.nextInt();
int left= numOfTickets-r;
int amount=60*r;
System.out.println("press 1 to continue booking ticket----");

int h = sc.nextInt();
System.out.println("\n\n\n");
if (h == 1) {
System.out.println("******************************************************");
System.out.println("theater ------------------- koi gandhi kr");
System.out.println("movie --------------------- game-movie");
System.out.println("cost ---------------------- Rs."+amount);
System.out.println("******************************************************");
}

}
if (monum== 2) {
System.out.println("fun movie @ koi gandhi kr theater");
System.out.println("Enter how many ticket to be booked:---");

int r = sc.nextInt();
int left= numOfTickets-r;
int amount=70*r;
System.out.println("press 1 to continue booking ticket----");

int h = sc.nextInt();
System.out.println("\n\n\n");
if (h == 1) {
System.out.println("******************************************************");
System.out.println("theater ------------------- koi gandhi kr ");
System.out.println("movie --------------------- fun movie");
System.out.println("cost ---------------------- Rs."+amount);
System.out.println("******************************************************");
}

}
}

}

void viewAvailableRefreshments() //implemented abstraction

{

System.out,println("Coca Cola");

System.out,println("Spicy Popcorn");

System.out,println("Butter Popcorn");

System.out,println("Caramel Popcorn");

System.out,println("Samosa");

System.out,println("Sandwich");

}


}

publc class calculaterefreshmentbill /*class to take care of the refreshment bill calculation(example of  polymorphism)*/

{

 double out (int a) //one coca cola { return a*50; } double out (int a, int b) //one coca cola and one sandwich { return a*50+b*80; } double out(int a,int b,int c) //one coca cola,one sandwich and one samosa   { return a*50+b*90+c*10; }

}

public class Main {

public static void main(String[] args) {
BookTheTicket ob1 = new BookTheTicket();

BookTheTicket [] moviename = new BookTheTicket[2];
moviename[0] = ob1;
theater ob2 = new theater();
moviename[1] = ob2;

System.out.println("@@@@@@@@@@ hello @@@@@@@@@@@@@ customer @@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n");
System.out.println("---------1.list of movies and their prices--------- \n-------2.acces and book tickets through theaters---");

System.out.println("\n@@@@@@@@@@ thanks @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
Scanner d = new Scanner(System.in);
int h = d.nextInt();
switch (h) {
case 1: {
ob1.myAllmovies();
break;
}
case 2: {

ob2.theater();
}
}

System.out.println("Press 1 for adding refreshments");

int h=d.nextInt();

if(h==1)

{

calculaterefreshmentbill ob=new calculaterefreshmentbill();

System.out.println("Enter the quantity of cocacola");

int c=d.nextInt();

System.out.println("Enter the quantity of sandwich");

int sd=d.nextInt();

System.out.println("Enter the quantity of Samosa");

int sa=d.nextInt();

if(c==1 && sd==0 && sa==0)

{

double cost1=ob.out(c);

System.out.println("Cost="+cost1);//calculating cost for one coca cola

}

else if(c==1 && sd==1 && sa==0)//calculating cost for one coca cola and one sandwich

{

double cost2=ob.out(c,sd);

System.out.println("Cost="+cost2);

}

else if(c==1 && sd==1 && sa==1)//calculating cost for one coca cola ,one sandwich and one samosa

{

double cost3=ob.out(c,sd,sa);

System.out.println("Cost="+cost2);

}

}

else

{

System.out.println("Thankyou for visiting");

}

}

}

Add a comment
Know the answer?
Add Answer to:
I have this java program that I need to add an abstract method and polymorphism to...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Add Encapsulation , Set and get to this program: import java.util.*; abstract class BookTheTicket {//abstract class...

    Add Encapsulation , Set and get to this program: import java.util.*; abstract class BookTheTicket {//abstract class private String movieName; private String theatreName; private int ticketCost; abstract void viewAvailablerefreshments();//abstract method void myAllmovies() { System.out.println("-------Listing the movies:------"); System.out.println(" 1.Men in Black ------------ $40 \n 2.Toy story---------$.50 \n 3.Harry Potter --------$60"+ "\n 4.lord of the rings ----- $.70 \n 5.the hobbit ----- $.80 "); } } import java.util.Scanner; class theater extends BookTheTicket{ private int numOfTickets; void theater() { System.out.println("*******Listing the theatre:******* \n 1.VOX...

  • Hi I need help with a java program that I need to create a Airline Reservation...

    Hi I need help with a java program that I need to create a Airline Reservation System I already finish it but it doesnt work can someone please help me I would be delighted it doesnt show the available seats when running the program and I need it to run until someone says no for booking a seat and if they want to cancel a seat it should ask the user to cancel a seat or continue booking also it...

  • need help editing or rewriting java code, I have this program running that creates random numbers...

    need help editing or rewriting java code, I have this program running that creates random numbers and finds min, max, median ect. from a group of numbers,array. I need to use a data class and a constructor to run the code instead of how I have it written right now. this is an example of what i'm being asked for. This is my code: import java.util.Random; import java.util.Scanner; public class RandomArray { // method to find the minimum number in...

  • I need this java program to contain methods that do some of the work that can...

    I need this java program to contain methods that do some of the work that can be modularized. It must logically be the same as this loop program but instead the logic will be modularized into Java Methods. Continue to take input for every employee in a company, and display their information until a sentinel value is entered, that exits the loop and ends the program. import java.util.Scanner; public class SalaryCalc { double Rpay = 0, Opay = 0; void...

  • ******** IN JAVA ********* I have a program that I need help debugging. This program should...

    ******** IN JAVA ********* I have a program that I need help debugging. This program should ask a user to input 3 dimensions of a rectangular block (length, width, and height), and then perform a volume and surface area calculation and display the results of both. It should only be done using local variables via methods and should have 4 methods: getInput, volBlock, saBlock, and display (should be void). I have most of it written here: import java.util.*; public class...

  • I need to add a method high school student, I couldn't connect high school student to...

    I need to add a method high school student, I couldn't connect high school student to student please help!!! package chapter.pkg9; import java.util.ArrayList; import java.util.Scanner; public class Main { public static Student student; public static ArrayList<Student> students; public static HighSchoolStudent highStudent; public static void main(String[] args) { int choice; Scanner scanner = new Scanner(System.in); students = new ArrayList<>(); while (true) { displayMenu(); choice = scanner.nextInt(); switch (choice) { case 1: addCollegeStudent(); break; case 2: addHighSchoolStudent(); case 3: deleteStudent(); break; case...

  • I have this program that works but not for the correct input file. I need the...

    I have this program that works but not for the correct input file. I need the program to detect the commas Input looks like: first_name,last_name,grade1,grade2,grade3,grade4,grade5 Dylan,Kelly,97,99,95,88,94 Tom,Brady,100,90,54,91,77 Adam,Sandler,90,87,78,66,55 Michael,Jordan,80,95,100,89,79 Elon,Musk,80,58,76,100,95 output needs to look like: Tom Brady -------------------------- Assignment 1: A Assignment 2: A Assignment 3: E Assignment 4: A Assignment 5: C Final Grade: 82.4 = B The current program: import java.io.File; import java.io.FileNotFoundException; import java.io.FileWriter; import java.io.IOException; import java.util.Scanner; public class main {    public static void main(String[]...

  • Java Programming: Hi, I need help Modifying my code that will throw an IllegalArgumentException. for the...

    Java Programming: Hi, I need help Modifying my code that will throw an IllegalArgumentException. for the following data entry error conditions: A number less than 1 or greater than 12 has been entered for the month A negative integer has been entered for the year utilizes a try and catch clause to display an appropriate message when either of these data entry errors exceptions occur. Thank you let me know if you need more info import java.util.*; //Class definition public...

  • I have the following java-program, that creates a random walk starting at (0,0) and continuing until...

    I have the following java-program, that creates a random walk starting at (0,0) and continuing until x or y is greater than abs(n). First: I get an error, when I try closing the Scanner by inserting "reader.close(); " in line 28. It says "Unreachable code". How can I fix that? Second: Is it possible to create a different colour for the StdDraw.point when it reaches a point on one of the edges "n+1" or "n-1" ? 1 import java.util.*; 3...

  • I need to write a program in java that reads a text file with a list...

    I need to write a program in java that reads a text file with a list of numbers and sorts them from least to greatest. This is the starter file. import java.util.*; import java.io.*; public class Lab3 { static final int INITIAL_CAPACITY = 5; public static void main( String args[] ) throws Exception { // ALWAYS TEST FOR REQUIRED INPUT FILE NAME ON THE COMMAND LINE if (args.length < 1 ) { System.out.println("\nusage: C:\\> java Lab3 L3input.txt\n"); System.exit(0); } //...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT