Write a Java Program that reads the following:
Ask the user for a balance. From the accounts.dat file, display all the accounts that have a balance of at least what the user entered.
accounts.dat is a binary file. Each entry contains a credit card number (long), a balance (double), and a cash back flag (boolean).
Idea is long =8byte in length double is 8 byte in length boolean is 1bit in length package HomeworkLib.job; import javax.xml.transform.stream.StreamSource; import java.io.*; import java.util.Arrays; import java.util.Scanner; public class BinaryFile { private static final int BUFFER_SIZE = 16; // 4KB public static void main(String[] args){ double balance; System.out.println("Enter a balance"); Scanner in; in = new Scanner(System.in); balance =in.nextDouble(); try ( ObjectInputStream inputStream = new ObjectInputStream(new FileInputStream(inputFile); ) { int byteRead; String creditCardNumber; double cardBalance; boolean cashbackFlag; byte[] buffer = new byte[BUFFER_SIZE]; while (inputStream.read(buffer) != -1) { creditCardNumber =new String(buffer, 0, 8); cardBalance =Double.parseDouble(new String(buffer, 8, 8)); cashbackFlag =inputStream.readBoolean(); if(cardBalance>=balance){ String flag =cashbackFlag?"Yes":"No"; System.out.println(creditCardNumber +"\t"+cardBalance +"\t "+flag); } } } catch (IOException ex) { ex.printStackTrace(); } } }
Write a Java Program that reads the following: Ask the user for a balance. From the...
REQUIREMENTS: Write a Graphical User Interface (GUI) program using JavaFX that prompts the user to enter a credit card number. Display whether the number is valid and the type of credit cards (i.e., Visa, MasterCard, American Express, Discover, and etc). The requirements for this assignment are listed below: • Create a class (CreditNumberValidator) that contains these methods: // Return true if the card number is valid. Boolean isValid(String cardNumber); // Get result from Step 2. int sumOfDoubleEvenPlace(String cardNumber); // Return...
Write the following program in Java:
You are to write a Java program that reads an input file containing a list of words and their synonyms. You will repeatedly ask the user if they want to look up the synonyms of a word, add a new synonym for a word, or quit. Here is a sample run of the program (note that the program is expecting the input file, thesaurus.txt to be in the working directory for the code.): Enter...
Validating Credit Card Numbers Write a program named Creditcard.java that prompts the user for a credit card number and determines whether it is valid or not. (Much of this assignment is taken from exercise 6.31 in the book) Credit card numbers follow certain patterns. A credit card number must have between 13 and 16 digits, and must start with: 4 for Visa cards 5 for Master cards 6 for Discover cards 37 for American Express cards The algorithm for determining...
x= Suppose you are building a program for teaching kids' math. Write a java program the does the following: 1. Ask the user if he/she wants to sign-up a. If yes continue to step 2 b. If no Display the message "Thank you, Have a nice Day 2. Ask the user to enter a username. 3. Ask the user to enter a password with at least 8 characters long 4. Write a method with the following header: public static Boolean...
Write a menu based program implementing the following functions: (0) Write a function called displayMenu that does not take any parameters, but returns an integer representing your user's menu choice. Your program's main function should only comprise of the following: a do/while loop with the displayMenu function call inside the loop body switch/case, or if/else if/ ... for handling the calls of the functions based on the menu choice selected in displayMenu. the do/while loop should always continue as long...
use C++ to write the following program.
needs to ask the user for n
The user must put in those 5 values, probably using a for
loop.
NOTE: You can assume the number of values to be entered is
5.
My attempted program below: (not correct, but just a basis)
4. Larger Than n In a program, write a function that accepts three arguments: an array, the size of the array, and a number n. Assume that the array contains...
Program in C++! Thank you in advance! Write a menu based program implementing the following functions: (1) Write a function that prompts the user for the name of a file to output as a text file that will hold a two dimensional array of the long double data type. Have the user specify the number of rows and the number of columns for the two dimensional array. Have the user enter the values for each row and column element in...
In this exercise, write a complete Java program that reads integer numbers from the user until a negative value is entered. It should then output the average of the numbers, not including the negative number. If no non-negative values are entered, the program should issue an error message. You are required to use a do-while loop to solve this problem. Solutions that do not use a do-while loop will be given a zero. Make sure to add appropriate comments to...
This program will ask the user to enter a number of players, then ask the user for each player's name and score. Once all of the players have been entered, the program will display a bar chart with each of their scores scaled as a percentage of the maximum score entered. See below for details on exactly how this should work - an example transcript of how the program should work is shown below (remember that values entered by the...
Problem 1 Write a Python program to do the following: (A) Ask the user to enter as many integers from 1 to 10 as he/she wants. Store the integers entered by the user in a list. Every time after the user has entered an integer, use a yes/no type question to ask whether he/she wants to enter another one. (B) Display the list. (C) Calculate and display the average of the integers in the list. (D) If the average is...