Answers for "ticket sales java program"

0

ticket sales java program

int grid[][] = new int[12][8];   // a 12×8 grid of int
grid[0][0] = 8;
grid[1][1] = 5;
System.out.println(grid.length);      // 12
System.out.println(grid[0].length);   // 8
System.out.println(grid[11].length);  // 8
Posted by: Guest on October-03-2020
0

ticket sales java program

Enter the taxable income: $41000
The income tax payable is: $2200.00
Enter the taxable income: $62000
The income tax payable is: $6600.00
Enter the taxable income: $73123
The income tax payable is: $9936.90
Enter the taxable income: $84328
The income tax payable is: $13298.40
Enter the taxable income: $-1
bye!
Posted by: Guest on October-03-2020
0

ticket sales java program

import java.util.Scanner;
/**
 * Prompt user for an int, and print its equivalent hexadecimal number.
 */
public class Dec2Hex {
   public static void main(String[] args) {
      // Declare variables
      int dec;              // The input decimal number in "int"
      String hexStr = "";   // The equivalent hex String, to accumulate from an empty String
      int radix = 16;       // Hex radix
      char[] hexChars =     // Use this array as lookup table for converting 0-15 to 0-9A-F
         {'0','1','2','3', '4','5','6','7', '8','9','A','B', 'C','D','E','F'};
      Scanner in = new Scanner(System.in);
   
      // Prompt and read input as "int"
      System.out.print("Enter a decimal number: ");
      dec = in.nextInt();
   
      // Repeated modulus/division and get the hex digits (0-15) in reverse order
      while (dec > 0) {
         int hexDigit = dec % radix;   // 0-15
         hexStr = hexChars[hexDigit] + hexStr;  // Append in front of the hex string corresponds to reverse order
         dec = dec / radix;
      }
      System.out.println("The equivalent hexadecimal number is " + hexStr);
      in.close();
   }
}
Posted by: Guest on October-03-2020
0

ticket sales java program

import java.util.Scanner;   // For keyboard input
/**
 * 1. Prompt user for the taxable income in integer.
 * 2. Read input as "int".
 * 3. Compute the tax payable using nested-if in "double".
 * 4. Print the values rounded to 2 decimal places.
 */
public class IncomeTaxCalculator {
   public static void main(String[] args) {
      // Declare constants first (variables may use these constants)
      final double TAX_RATE_ABOVE_20K = 0.1;
      final double TAX_RATE_ABOVE_40K = 0.2;
      final double TAX_RATE_ABOVE_60K = 0.3;

      // Declare variables
      int taxableIncome;
      double taxPayable;
      Scanner in = new Scanner(System.in);

      // Prompt and read inputs as "int"
      System.out.print("Enter the taxable income: $");
      taxableIncome = in.nextInt();

      // Compute tax payable in "double" using a nested-if to handle 4 cases
      if (taxableIncome <= 20000) {         // [0, 20000]
         taxPayable = 0;
      } else if (taxableIncome <= 40000) {  // [20001, 40000]
         taxPayable = (taxableIncome - 20000) * TAX_RATE_ABOVE_20K;
      } else if (taxableIncome <= 60000) {  // [40001, 60000]
         taxPayable = 20000 * TAX_RATE_ABOVE_20K
                      + (taxableIncome - 40000) * TAX_RATE_ABOVE_40K;
      } else {                              // >=60001
         taxPayable = 20000 * TAX_RATE_ABOVE_20K
                      + 20000 * TAX_RATE_ABOVE_40K
                      + (taxableIncome - 60000) * TAX_RATE_ABOVE_60K;
      }

      // Alternatively, you could use the following nested-if conditions
      // but the above follows the table data
      //if (taxableIncome > 60000) {          // [60001, ]
      //   ......
      //} else if (taxableIncome > 40000) {   // [40001, 60000]
      //   ......
      //} else if (taxableIncome > 20000) {   // [20001, 40000]
      //   ......
      //} else {                              // [0, 20000]
      //   ......
      //}

      // Print result rounded to 2 decimal places
      System.out.printf("The income tax payable is: $%.2f%n", taxPayable);
      in.close();  // Close Scanner
   }
}
Posted by: Guest on October-03-2020
0

ticket sales java program

Enter a decimal number: 1234
The equivalent hexadecimal number is 4D2
Posted by: Guest on October-03-2020
0

ticket sales java program

public class EgMethodGetArea {
   // The entry main method
   public static void main(String[] args) {
      double r = 1.1, area, area2;
      // Call (Invoke) method getArea() and return
      area = getArea(r);
      System.out.println("area is " + area);
      // Call method getArea() again and return
      area2 = getArea(2.2);
      System.out.println("area 2 is " + area2);
      // Call method getArea() one more time and return
      System.out.println("area 3 is " + getArea(3.3));
   }
 
   // Method getArea() Definition.
   // Compute and return the area (in double) of circle given its radius (in double).
   public static double getArea(double radius) {
      return radius * radius * Math.PI;
   }
}
Posted by: Guest on October-03-2020
0

ticket sales java program

import java.util.Arrays;   // Needed to use Arrays.toString()
/**
 * Use Arrays.toString() to print an array in the form of [a1, a2, ..., an]
 */
public class TestArrayToString {
   public static void main(String[] args) {
      // Declare and allocate test arrays
      int[] a1 = {6 ,1, 3, 4, 5};   // Allocate via initialization
      int[] a2 = {};                // Empty array with length = 0
      double[] a3 = new double[1];  // One-Element array, init to 0.0

      System.out.println(Arrays.toString(a1));  //[6, 1, 3, 4, 5]
      System.out.println(Arrays.toString(a2));  //[]
      System.out.println(Arrays.toString(a3));  //[0.0]
      a3[0] = 2.2;
      System.out.println(Arrays.toString(a3));  //[2.2]
   }
}
Posted by: Guest on October-03-2020
0

ticket sales java program

import java.util.Scanner;
/**
 * Guess a secret number between 0 and 99.
 */
public class NumberGuess {
   public static void main(String[] args) {
      // Define variables
      int secretNumber;     // Secret number to be guessed
      int numberIn;         // The guessed number entered
      int trialNumber = 0;  // Number of trials so far
      boolean done = false; // boolean flag for loop control
      Scanner in = new Scanner(System.in);
   
      // Set up the secret number: Math.random() generates a double in [0.0, 1.0)
      secretNumber = (int)(Math.random()*100);

      // Use a while-loop to repeatedly guess the number until it is correct
      while (!done) {
         ++trialNumber;
         System.out.print("Enter your guess (between 0 and 99): ");
         numberIn = in.nextInt();
         if (numberIn == secretNumber) {
            System.out.println("Congratulation");
            done = true;
         } else if (numberIn < secretNumber) {
            System.out.println("Try higher");
         } else {
            System.out.println("Try lower");
         }
      }
      System.out.println("You got in " + trialNumber +" trials");
      in.close();
   }
}
Posted by: Guest on October-03-2020
0

ticket sales java program

Enter a Hexadecimal string: 1bE3
The equivalent binary for "1bE3" is "0001101111100011"
Posted by: Guest on October-03-2020
0

ticket sales java program

public class Array2DTest {
   public static void main(String[] args) {
      int[][] grid = new int[12][8];   // A 12x8 grid, in [row][col] or [y][x]
      int numRows = grid.length;       // 12
      int numCols = grid[0].length;    // 8
   
      // Fill in grid
      for (int row = 0; row < numRows; ++row) {
         for (int col = 0; col < numCols; ++col) {
            grid[row][col] = row*numCols + col + 1;
         }
      }
   
      // Print grid
      for (int row = 0; row < numRows; ++row) {
         for (int col = 0; col < numCols; ++col) {
            System.out.printf("%3d", grid[row][col]);
         }
         System.out.println();
      }
   }
}
Posted by: Guest on October-03-2020

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language