• Create Account

### #ActualDarego

Posted 16 December 2012 - 01:05 PM

Just had an exam in college. I was asked to write a program to calculate the details of tickets sold at concerts. this was the required output(which i managed to get but without using the inner class which was required so i assume i lost marks for that)

[source lang="java"]Enter the performer of conecrt 1whamEnter the capacity of concert 1100Is ticket 1 seated? Y or NYEnter the performer of conecrt 2BAMEnter the capacity of concert 2200Is ticket 1 seated? Y or NYIs ticket 2 seated? Y or NYIs ticket 3 seated? Y or NYEnter the performer of conecrt 3BrosEnter the capacity of concert 3300Is ticket 1 seated? Y or NYIs ticket 2 seated? Y or NYIs ticket 3 seated? Y or NNConcert 1 performed by: wham€100.0, seated ticketThe total sales for this concert is: 100Concert 2 performed by: BAM€100.0, seated ticket€100.0, seated ticket€100.0, seated ticketThe total sales for this concert is: 300Concert 3 performed by: Bros€100.0, seated ticket€100.0, seated ticket€80.0, standing ticketThe total sales for this concert is: 280The highest sales of all 3 concerts is: BAM at 300[/source]
so one part of the exam which i didn't do fully was: "Create a fillList() method that takes a reference variable of type Ticket as a parameter and adds it to the list" how would i go about passing an object of an inner class as a paramitar to a method in the outer class? i managed to manipulate the question and get the required output by not even using the inner class

here is my code

Concert class with inner class Ticket:
[source lang="java"]import java.util.ArrayList;import java.util.Random;import java.util.Scanner;class Concert { Scanner input = new Scanner(System.in); Random generator = new Random(); private String performer; private int cap; private int numTickets; private int totalSales; ArrayList< String > tickets = new ArrayList< String > (); public Concert(String performer, int cap) { this.performer = performer; this.cap = cap; } public void fillList() { numTickets = 1+generator.nextInt(3); for(int i=0;i<numTickets;i++) { System.out.println("Is ticket "+(i+1)+" seated? Y or N"); String seated1 = input.next(); char seated = seated1.charAt(0); if(seated == 'Y') { String ifseated = "€100.0, seated ticket"; this.tickets.add(ifseated); totalSales = totalSales +100; } else { String ifnotseated = "€80.0, standing ticket"; this.tickets.add(ifnotseated); totalSales = totalSales +80; } } StaticFields.caclBiggestConcert(totalSales, performer); } public void displayList() { if(StaticFields.conNumber == 0) { System.out.println("Concert "+1+" performed by: "+performer); } else if(StaticFields.conNumber == 1) { System.out.println("Concert "+2+" performed by: "+performer); } else { System.out.println("Concert "+3+" performed by: "+performer); } for(int i =0; i < tickets.size();i++) { System.out.print(tickets.get(i)+"\n"); } StaticFields.conNumber++; } public void showTotalSales() { System.out.println("The total sales for this concert is: "+totalSales); } public class Ticket { private double price; private boolean seated; public Ticket(double price, boolean seated) { this.seated = seated; if(seated == true) { this.price = 100; } else { this.price = 80; } } }}[/source]
Test class:
[source lang="java"]import java.util.Scanner;public class Test { public static void main(String[] args) { Scanner input = new Scanner(System.in); Concert con[] = new Concert[3]; for(int i =0;i < con.length;i++) { System.out.println("Enter the performer of conecrt "+(i+1)); String name = input.next(); System.out.println("Enter the capacity of concert "+(i+1)); int cap = input.nextInt(); con[i] = new Concert(name, cap); con[i].fillList(); } for(int i =0;i < con.length;i++) { con[i].displayList(); con[i].showTotalSales(); } System.out.println("The highest sales of all 3 concerts is: "+StaticFields.highestConcert+" at "+StaticFields.highestSales); }}[/source]

also had a staticfield class to handle static variables and methods

cheers guys,
D

### #3Darego

Posted 16 December 2012 - 01:04 PM

Just had an exam in college. I was asked to write a program to calculate the details of tickets sold at concerts. this was the required output(which i managed to get but without using the inner class which was required so i assume i lost marks for that)

[source lang="java"]Enter the performer of conecrt 1whamEnter the capacity of concert 1100Is ticket 1 seated? Y or NYEnter the performer of conecrt 2BAMEnter the capacity of concert 2200Is ticket 1 seated? Y or NYIs ticket 2 seated? Y or NYIs ticket 3 seated? Y or NYEnter the performer of conecrt 3BrosEnter the capacity of concert 3300Is ticket 1 seated? Y or NYIs ticket 2 seated? Y or NYIs ticket 3 seated? Y or NNConcert 1 performed by: wham€100.0, seated ticketThe total sales for this concert is: 100Concert 2 performed by: BAM€100.0, seated ticket€100.0, seated ticket€100.0, seated ticketThe total sales for this concert is: 300Concert 3 performed by: Bros€100.0, seated ticket€100.0, seated ticket€80.0, standing ticketThe total sales for this concert is: 280The highest sales of all 3 concerts is: BAM at 300[/source]
so one part of the exam which i didn't do fully was: "Create a fillList() method that takes a reference variable of type Ticket as a parameter and adds it to the list" how would i go about passing an object of an inner class as a paramitar to a method in the outer class? i managed to manipulate the question and get the required output by not even using the inner class

here is my code

Concert class with inner class Ticket:
[source lang="java"]import java.util.ArrayList;import java.util.Random;import java.util.Scanner;class Concert { Scanner input = new Scanner(System.in); Random generator = new Random(); private String performer; private int cap; private int numTickets; private int totalSales; ArrayList< String > tickets = new ArrayList< String > (); public Concert(String performer, int cap) { this.performer = performer; this.cap = cap; } public void fillList() { numTickets = 1+generator.nextInt(3); for(int i=0;i<numTickets;i++) { System.out.println("Is ticket "+(i+1)+" seated? Y or N"); String seated1 = input.next(); char seated = seated1.charAt(0); if(seated == 'Y') { String ifseated = "€100.0, seated ticket"; this.tickets.add(ifseated); totalSales = totalSales +100; } else { String ifnotseated = "€80.0, standing ticket"; this.tickets.add(ifnotseated); totalSales = totalSales +80; } } StaticFields.caclBiggestConcert(totalSales, performer); } public void displayList() { if(StaticFields.conNumber == 0) { System.out.println("Concert "+1+" performed by: "+performer); } else if(StaticFields.conNumber == 1) { System.out.println("Concert "+2+" performed by: "+performer); } else { System.out.println("Concert "+3+" performed by: "+performer); } for(int i =0; i < tickets.size();i++) { System.out.print(tickets.get(i)+"\n"); } StaticFields.conNumber++; } public void showTotalSales() { System.out.println("The total sales for this concert is: "+totalSales); } public class Ticket { private double price; private boolean seated; public Ticket(double price, boolean seated) { this.seated = seated; if(seated == true) { this.price = 100; } else { this.price = 80; } } }}[/source]
Test class:
[source lang="java"]import java.util.Scanner;public class Test { public static void main(String[] args) { Scanner input = new Scanner(System.in); Concert con[] = new Concert[3]; for(int i =0;i < con.length;i++) { System.out.println("Enter the performer of conecrt "+(i+1)); String name = input.next(); System.out.println("Enter the capacity of concert "+(i+1)); int cap = input.nextInt(); con[i] = new Concert(name, cap); con[i].fillList(); } for(int i =0;i < con.length;i++) { con[i].displayList(); con[i].showTotalSales(); } System.out.println("The highest sales of all 3 concerts is: "+StaticFields.highestConcert+" at "+StaticFields.highestSales); }}[/source]

also had a staticfield class to handle static variables and methods

cheers guys,
D

### #2Darego

Posted 16 December 2012 - 01:02 PM

Just had an exam in college. I was asked to write a program to calculate the details of tickets sold at concerts. this was the required output(which i managed to get but without using the inner class which was required so i assume i lost marks for that)

[source lang="java"]Enter the performer of conecrt 1whamEnter the capacity of concert 1100Is ticket 1 seated? Y or NYEnter the performer of conecrt 2BAMEnter the capacity of concert 2200Is ticket 1 seated? Y or NYIs ticket 2 seated? Y or NYIs ticket 3 seated? Y or NYEnter the performer of conecrt 3BrosEnter the capacity of concert 3300Is ticket 1 seated? Y or NYIs ticket 2 seated? Y or NYIs ticket 3 seated? Y or NNConcert 1 performed by: wham€100.0, seated ticketThe total sales for this concert is: 100Concert 2 performed by: BAM€100.0, seated ticket€100.0, seated ticket€100.0, seated ticketThe total sales for this concert is: 300Concert 3 performed by: Bros€100.0, seated ticket€100.0, seated ticket€80.0, standing ticketThe total sales for this concert is: 280The highest sales of all 3 concerts is: BAM at 300[/source]
so one part of the exam which i didn't do fully was: "Create a fillList() method that takes a reference variable of type Ticket as a parameter and adds it to the list" how would i go about doing this? i managed to manipulate the question and get the required output by not even using the inner class

here is my code

Concert class with inner class Ticket:
[source lang="java"]import java.util.ArrayList;import java.util.Random;import java.util.Scanner;class Concert { Scanner input = new Scanner(System.in); Random generator = new Random(); private String performer; private int cap; private int numTickets; private int totalSales; ArrayList< String > tickets = new ArrayList< String > (); public Concert(String performer, int cap) { this.performer = performer; this.cap = cap; } public void fillList() { numTickets = 1+generator.nextInt(3); for(int i=0;i<numTickets;i++) { System.out.println("Is ticket "+(i+1)+" seated? Y or N"); String seated1 = input.next(); char seated = seated1.charAt(0); if(seated == 'Y') { String ifseated = "€100.0, seated ticket"; this.tickets.add(ifseated); totalSales = totalSales +100; } else { String ifnotseated = "€80.0, standing ticket"; this.tickets.add(ifnotseated); totalSales = totalSales +80; } } StaticFields.caclBiggestConcert(totalSales, performer); } public void displayList() { if(StaticFields.conNumber == 0) { System.out.println("Concert "+1+" performed by: "+performer); } else if(StaticFields.conNumber == 1) { System.out.println("Concert "+2+" performed by: "+performer); } else { System.out.println("Concert "+3+" performed by: "+performer); } for(int i =0; i < tickets.size();i++) { System.out.print(tickets.get(i)+"\n"); } StaticFields.conNumber++; } public void showTotalSales() { System.out.println("The total sales for this concert is: "+totalSales); } public class Ticket { private double price; private boolean seated; public Ticket(double price, boolean seated) { this.seated = seated; if(seated == true) { this.price = 100; } else { this.price = 80; } } }}[/source]
Test class:
[source lang="java"]import java.util.Scanner;public class Test { public static void main(String[] args) { Scanner input = new Scanner(System.in); Concert con[] = new Concert[3]; for(int i =0;i < con.length;i++) { System.out.println("Enter the performer of conecrt "+(i+1)); String name = input.next(); System.out.println("Enter the capacity of concert "+(i+1)); int cap = input.nextInt(); con[i] = new Concert(name, cap); con[i].fillList(); } for(int i =0;i < con.length;i++) { con[i].displayList(); con[i].showTotalSales(); } System.out.println("The highest sales of all 3 concerts is: "+StaticFields.highestConcert+" at "+StaticFields.highestSales); }}[/source]

also had a staticfield class to handle static variables and methods

cheers guys,
D

### #1Darego

Posted 16 December 2012 - 12:52 PM

Just had an exam in college. I was asked to write a program to calculate the details of tickets sold at concerts. this was the required output(which i managed to get but without using the inner class which was required so i assume i lost marks for that)

[source lang="java"]Enter the performer of conecrt 1whamEnter the capacity of concert 1100Is ticket 1 seated? Y or NYEnter the performer of conecrt 2BAMEnter the capacity of concert 2200Is ticket 1 seated? Y or NYIs ticket 2 seated? Y or NYIs ticket 3 seated? Y or NYEnter the performer of conecrt 3BrosEnter the capacity of concert 3300Is ticket 1 seated? Y or NYIs ticket 2 seated? Y or NYIs ticket 3 seated? Y or NNConcert 1 performed by: wham€100.0, seated ticketThe total sales for this concert is: 100Concert 2 performed by: BAM€100.0, seated ticket€100.0, seated ticket€100.0, seated ticketThe total sales for this concert is: 300Concert 3 performed by: Bros€100.0, seated ticket€100.0, seated ticket€80.0, standing ticketThe total sales for this concert is: 280The highest sales of all 3 concerts is: BAM at 300[/source]
so one part of the exam which i didn't do fully was: "Create a fillList() method that takes a reference variable of type Ticket as a parameter and adds it to the list" how would i go about doing this? i managed to manipulate the question and get the required output by not even using the inner class

here is my code

Concert class with inner class Ticket:
[source lang="java"]import java.util.ArrayList;import java.util.Random;import java.util.Scanner;class Concert { Scanner input = new Scanner(System.in); Random generator = new Random(); private String performer; private int cap; private int numTickets; private int totalSales; ArrayList< String > tickets = new ArrayList< String > (); public Concert(String performer, int cap) { this.performer = performer; this.cap = cap; } public void fillList() { numTickets = 1+generator.nextInt(3); for(int i=0;i<numTickets;i++) { System.out.println("Is ticket "+(i+1)+" seated? Y or N"); String seated1 = input.next(); char seated = seated1.charAt(0); if(seated == 'Y') { String ifseated = "€100.0, seated ticket"; this.tickets.add(ifseated); totalSales = totalSales +100; } else { String ifnotseated = "€80.0, standing ticket"; this.tickets.add(ifnotseated); totalSales = totalSales +80; } } StaticFields.caclBiggestConcert(totalSales, performer); } public void displayList() { if(StaticFields.conNumber == 0) { System.out.println("Concert "+1+" performed by: "+performer); } else if(StaticFields.conNumber == 1) { System.out.println("Concert "+2+" performed by: "+performer); } else { System.out.println("Concert "+3+" performed by: "+performer); } for(int i =0; i < tickets.size();i++) { System.out.print(tickets.get(i)+"\n"); } StaticFields.conNumber++; } public void showTotalSales() { System.out.println("The total sales for this concert is: "+totalSales); } public class Ticket { private double price; private boolean seated; public Ticket(double price, boolean seated) { this.seated = seated; if(seated == true) { this.price = 100; } else { this.price = 80; } } }}[/source]
Test class:
[source lang="java"]import java.util.Scanner;public class Test { public static void main(String[] args) { Scanner input = new Scanner(System.in); Concert con[] = new Concert[3]; for(int i =0;i < con.length;i++) { System.out.println("Enter the performer of conecrt "+(i+1)); String name = input.next(); System.out.println("Enter the capacity of concert "+(i+1)); int cap = input.nextInt(); con[i] = new Concert(name, cap); con[i].fillList(); } for(int i =0;i < con.length;i++) { con[i].displayList(); con[i].showTotalSales(); } System.out.println("The highest sales of all 3 concerts is: "+StaticFields.highestConcert+" at "+StaticFields.highestSales); }}[/source]

also had a staticfield class to handle static variables and methods

cheers guys,
D

PARTNERS