Question

Using Java please help me return the total to getTicketData() so it will display in my...

Using Java please help me return the total to getTicketData() so it will display in my displayTicketData() function. Everything in my display function is a sent to a display class that works well for strings already.

import java.util.Scanner;

public class ticketing {
   //Declaring variables for strings and integers

   private int ticketNum;

   //Using the Scanner to scan in data input by user
   Scanner s = new Scanner(System.in);
  
   void getTicketData() {
      
       //Methods taking in information using display messages and the Java scanner
       System.out.println("Please enter number of tickets sold: ");
       ticketNum = s.nextInt();
      

   }
  
   public int ticketPrice(int ticketNum) {
       int price = 17;
       int total;
      
       total = price * ticketNum;
       return total;
   }

  
   void displayTicketData() {
      
      
       System.out.println("Number of tickets sold: " + ticketNum);
       System.out.println("Total value of tickets sold is: " + total);
   }
   }

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

// Here is the code in java change the class name as required.

import java.util.Scanner;

// name of class should follow CamelCase
public class Ticketing {

//Declaring variables for strings and integers
   private int ticketNum;

//Using the Scanner to scan in data input by user
   Scanner s = new Scanner(System.in);

//Methods taking in information using display messages and the Java scanner
void getTicketData() {
System.out.println("Please enter number of tickets sold: ");
ticketNum = s.nextInt();
}
  
// method taking number of tickets as parameter and returning totalPrice
public int ticketPrice(int ticketNum) {
int price = 17;
   int total;
total = price * ticketNum;
return total;
}

  
void displayTicketData() {
   //printing number of tickets
System.out.println("Number of tickets sold: " + ticketNum);
   //printing total price of tickets
System.out.println("Total value of tickets sold is: " + ticketPrice(ticketNum));
}
  
   //main method
   public static void main(String[] args){
      
       // created object for calling instance methods
       Ticketing ticket = new Ticketing();
       ticket.getTicketData();
       ticket.displayTicketData();
      
   }
        
}

//output


*If you have any problem with the answer or want me to edit the answer just let me know in the comments and i will try to get on it as soon as possible. Do give a plus if this answer helps.

Add a comment
Know the answer?
Add Answer to:
Using Java please help me return the total to getTicketData() so it will display in my...
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
  • Please edit my following JAVA code so that there is no main function. I would like...

    Please edit my following JAVA code so that there is no main function. I would like one function in this class that completes what the current program is trying to do so that I can call this class in my main class which will be separate. import java.math.RoundingMode; import java.text.DecimalFormat; import java.util.Scanner; public class enterwklyincme { private static DecimalFormat df = new DecimalFormat("0.00"); public static float readFloat(Scanner reader) { float num; while (true) { try { num = Float.parseFloat(reader.nextLine()); return...

  • JAVA HELP: Directions Write a program that will create an array of random numbers and output...

    JAVA HELP: Directions Write a program that will create an array of random numbers and output the values. Then output the values in the array backwards. Here is my code, I am having a problem with the second method. import java.util.Scanner; import java.util.Random; public class ArrayBackwards { public static void main(String[] args) { genrate(); print(); } public static void generate() { Scanner scanner = new Scanner(System.in);    System.out.println("Seed:"); int seed = scanner.nextInt();    System.out.println("Length"); int length = scanner.nextInt(); Random random...

  • In Java, write JUnit tests to verify various question-type objects for the following below: public interface...

    In Java, write JUnit tests to verify various question-type objects for the following below: public interface IAnswer {    public String getAnswer();    } import java.util.Scanner; YesNo class: public class YesNo implements IAnswer{            private String question;            public YesNo(String q){                this.question = q;            }                       //This function returns question text            public String getQuestionText() {                return question;...

  • Write a java programm that calculates the total of a retail sale should ask the user...

    Write a java programm that calculates the total of a retail sale should ask the user for the following: The retail price of the item being purchased The sales tax rate Once these items have been entered, the program should calculate and display the following: The sales tax for the purchase The total of the sale I tried doing it here. but it is not giving me the right answer. kindly help correct the errors. import java.util.Scanner; public class SalesTax...

  • Write one JUnit test in Java for the following: Essay class: import java.util.Scanner; public class Essay implements IAn...

    Write one JUnit test in Java for the following: Essay class: import java.util.Scanner; public class Essay implements IAnswer{ private String question; public Essay(String q){ this.question = q; } //This function returns question text public String getQuestionText() {    return question; } //This function takes answer from user public void answer(String userAnswer) {    // Take care of answer } @Override public String getAnswer() { System.out.println(question); Scanner scan = new Scanner(System.in); System.out.print("Answer: "); String ans =scan.nextLine(); scan.close(); if(ans.length() <=140){ return ans; }else{ return...

  • JAVA Modify the code to create a class called box, wherein you find the area. I...

    JAVA Modify the code to create a class called box, wherein you find the area. I have the code in rectangle and needs to change it to box. Here is my code. Rectangle.java public class Rectangle { private int length; private int width;       public void setRectangle(int length, int width) { this.length = length; this.width = width; } public int area() { return this.length * this.width; } } // CONSOLE / MAIN import java.awt.Rectangle; import java.util.Scanner; public class Console...

  • Hi everyone! I need help on my Java assignment. I need to create a method that...

    Hi everyone! I need help on my Java assignment. I need to create a method that is called sumIt that will sum two values and will return the value.It should also invoke cubeIt from the sum of the two values. I need to change the currecnt program that I have to make it input two values from the console. The method has to be called sumIt and will return to the sum that will produce the cube of the sum...

  • I am currently doing homework for my java class and i am getting an error in...

    I am currently doing homework for my java class and i am getting an error in my code. import java.util.Scanner; import java.util.Random; public class contact {       public static void main(String[] args) {        Random Rand = new Random();        Scanner sc = new Scanner(System.in);        System.out.println("welcome to the contact application");        System.out.println();               int die1;        int die2;        int Total;               String choice = "y";...

  • Can you help me with this code in Java??? import java.util.Scanner; public class Main { public...

    Can you help me with this code in Java??? import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int rows = 3; int columns = 4; int[][] arr = new int[rows][columns]; for(int i = 0; i < rows; ++i) { for(int j = 0; j < columns; ++j) { System.out.println("Enter a value: "); arr[i][j] = scan.nextInt(); } } System.out.println("The entered matrix:"); for(int i = 0; i < rows; ++i) { for(int j...

  • Java. Java is a new programming language I am learning, and so far I am a...

    Java. Java is a new programming language I am learning, and so far I am a bit troubled about it. Hopefully, I can explain it right. For my assignment, we have to create a class called Student with three private attributes of Name (String), Grade (int), and CName(String). In the driver class, I am suppose to have a total of 3 objects of type Student. Also, the user have to input the data. My problem is that I can get...

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