0

I need to get the inputs for movie, row n seat, I which isn't getting accepted in below code. Where's I'm wrong

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) { movie = getMovie(); row = getRow(); seat = getSeat(); } public String getMovie() { return movie; } public int getRow() { return row; } public int getSeat() { return seat; } }

12th May 2021, 6:26 PM
Swapnil Kamdi
Swapnil Kamdi - avatar
6 odpowiedzi
+ 1
The constructor is wrong. Do it like this: this.movie = movie;
12th May 2021, 6:39 PM
Benjamin Jürgens
Benjamin Jürgens - avatar
12th May 2021, 6:39 PM
Atul [Inactive]
+ 1
Jatinder Kumar I think you should go through the Q&A session and moreover sololearn policy of it before posting such. This is not the place where you could post your promotion. A problem for which I had been stucked for more than my 25 to 30 minutes, I asked here to get the resolution. Please remove what you have posted.
13th May 2021, 6:06 AM
Swapnil Kamdi
Swapnil Kamdi - avatar
0
Use this keyword so that it will take the current objects and store it in parameter variables
12th May 2021, 6:40 PM
Atul [Inactive]
0
The problem in the constructor u can't assign a parametter to a method . Try : this.movie = movie and so on ..
12th May 2021, 6:45 PM
‎Abdul Jalil
‎Abdul Jalil - avatar