+ 2

Help with the Constructor Java question

Your friend is a cashier at a movie theater. He knows that you are an awesome java developer so he asked you to help him out and create a program that gets movie title, row, and seat information and prints out a new ticket. Complete the existing code by adding a constructor to Ticket class so that it can be correctly initialized. Sample Input Jaws 5 1 Sample Output Movie: Jaws Row: 5 Seat: 1 import java.util.Scanner; class Main { public static void main(String[] args) { Scanner read = new Scanner(System.in); String movie = read.nextLine(); int row = read.nextInt(); int seat = read.nextInt(); Ticket ticket = new Ticket(movie, row, seat); System.out.println("Movie: " + ticket.getMovie()); System.out.println("Row: " + ticket.getRow()); System.out.println("Seat: " + ticket.getSeat()); } } public class Ticket { private String movie; private int row; private int seat; //complete the constructor Ticket(){ this.setMovie(""); this.setRow(); this.setSeat(); } Ticket(String m){ this.setMovie(m); } Ticket(int row){ this.setRow(r); } Ticket(int seat){ this.setSeat(s); } public void setMovie(String m){ this.movie = m; } public void setRow(int r){ this.row = r; } public void setSeat(int s){ this.seat = s; } public String getMovie() { return movie; } public int getRow() { return row; } public int getSeat() { return seat; } }

30th Apr 2021, 1:55 AM
韩韵萌
韩韵萌 - avatar
6 Respostas
+ 6
import java.util.Scanner; class Main { public static void main(String[] args) { Scanner read = new Scanner(System.in); String movie = read.nextLine(); int row = read.nextInt(); int seat = read.nextInt(); Ticket ticket = new Ticket(movie, row, seat); System.out.println("Movie: " + ticket.getMovie()); System.out.println("Row: " + ticket.getRow()); System.out.println("Seat: " + ticket.getSeat()); } } //Please Subscribe to My Youtube Channel //Channel Name: Fazal Tuts4U class Ticket { private String movie; private int row; private int seat; //complete the constructor public Ticket(String movie, int row, int seat) { this.movie = movie; this.row = row; this.seat = seat; } public String getMovie() { return movie; } public int getRow() { return row; } public int getSeat() { return seat; } }
4th Sep 2021, 7:20 AM
Fazal Haroon
Fazal Haroon - avatar
+ 1
import java.util.Scanner; class Main { public static void main(String[] args) { Scanner read = new Scanner(System.in); String movie = read.nextLine(); int row = read.nextInt(); int seat = read.nextInt(); Ticket ticket = new Ticket(movie, row, seat); System.out.println("Movie: " + ticket.getMovie()); System.out.println("Row: " + ticket.getRow()); System.out.println("Seat: " + ticket.getSeat()); } } class Ticket { private String movie; private int row; private int seat; //complete the constructor public Ticket(String movie,int row, int seat) { this.movie = movie; this.row = row; this.seat = seat; } public String getMovie() { return movie; } public int getRow() { return row; } public int getSeat() { return seat; } }
11th Nov 2022, 3:05 PM
Just Skiper
Just Skiper - avatar
0
i am facing problem in movie ticket practice question. i have used constructor correctly as well as getters and setters but still i am getting 2 errors-> incompatible types: int cannot be converted to String this.setmovie(r); ^ incompatible types: int cannot be converted to String this.setmovie(s); plz help https://code.sololearn.com/ca12A12A3a11
14th Jul 2021, 1:01 PM
Ishan saxena
0
Всё гениальное просто: import java.util.Scanner; class Main { public static void main(String[] args) { Scanner read = new Scanner(System.in); String movie = read.nextLine(); int row = read.nextInt(); int seat = read.nextInt(); System.out.println("Movie: " + movie); System.out.println("Row: " + row); System.out.println("Seat: " + seat); } }
16th Nov 2021, 7:03 PM
Фёдор
0
import java.util.Scanner; class Main { public static void main(String[] args) { Scanner read = new Scanner(System.in); String movie = read.nextLine(); int row = read.nextInt(); int seat = read.nextInt(); Ticket ticket = new Ticket(movie, row, seat); System.out.println("Movie: " + ticket.getMovie()); System.out.println("Row: " + ticket.getRow()); System.out.println("Seat: " + ticket.getSeat()); } } class Ticket { private String movie; private int row; private int seat; //complete the constructor public Ticket(String movie, int row, int seat) { this.movie = movie; this.row = row; this.seat = seat; } public String getMovie() { return movie; } public int getRow() { return row; } public int getSeat() { return seat; } }
15th Nov 2022, 7:51 AM
Pooja Patel
Pooja Patel - avatar
- 1
The only constructor you seem to need is; Ticket(String movie, int row, int seat) { this.movie = movie; this.row = row; this.seat = seat; }
30th Apr 2021, 2:12 AM
ChaoticDawg
ChaoticDawg - avatar