Solve computer science java validation problem

Assignment Help JAVA Programming
Reference no: EM13304900

Subject:Computer Science, Operating Systems - Year 1Description:java validationProblem:

Using NetBeans 7.2

Please run the code to check for errors.

ValidatedInvoiceApp.java compiles

Application accepts only r and c customer type codes

Display error message on invalid code and request re-entry

static getValidCustomerType method performs validation

getValidCustomerType has Scanner parameter

getValidCustomerType returns valid customer code

try-catch block for subtotal entry with error message and continue statement in main

static getValidSubtotal method performs validation

getValidSubtotal has Scanner parameter

getValidSubtotal returns valid subtotal

getValidSubtotal limits valid subtotal to range > 0 and

getValidSubtotal prevents exception in main

Discard multiple entries when asked to continue

import java.text.NumberFormat;

import java.util.Scanner;

public class InvoiceApp

{

public static void main(String[] args)

{

Scanner sc = new Scanner(System.in);

String choice = "y";

while (!choice.equalsIgnoreCase("n"))

{

// get the input from the user

System.out.print("Enter customer type (r/c): ");

String customerType = sc.next();

System.out.print("Enter subtotal: ");

double subtotal = sc.nextDouble();

// get the discount percent

double discountPercent = 0;

if (customerType.equalsIgnoreCase("R"))

{

if (subtotal

discountPercent = 0;

else if (subtotal >= 100 && subtotal

discountPercent = .1;

else if (subtotal >= 250)

discountPercent = .2;

}

else if (customerType.equalsIgnoreCase("C"))

{

if (subtotal

discountPercent = .2;

else

discountPercent = .3;

}

else

{

discountPercent = .1;

}

// calculate the discount amount and total

double discountAmount = subtotal * discountPercent;

double total = subtotal - discountAmount;

// format and display the results

NumberFormat currency = NumberFormat.getCurrencyInstance();

NumberFormat percent = NumberFormat.getPercentInstance();

System.out.println("Discount percent: " + percent.format(discountPercent) + "n" + "Discount amount: " + currency.format(discountAmount) + "n" + "Total: " + currency.format(total) + "n");

// see if the user wants to continue

System.out.print("Continue? (y/n): ");

choice = sc.next();

System.out.println();

}

}

}

Reference no: EM13304900

Questions Cloud

Determine the dimensions of the best hydraulic section : A semicircular open channel to be made of concrete is to be designed to carry 1.5 m^3/s at a slope of 0.00085. Manning's roughness coefficient is 0.015. Determine the dimensions of the best hydraulic section.
Do you believe stock is undervalued and should be purchased : Your report should introduce and discuss the approaches and models you use, clearly identify any assumptions you are making, and clearly list the values and sources of input data.
What are the values of the lowest eight eigenvalues : Consider an electron in a square infinite well whose sides have length 0.05 nm. What are the values of the lowest eight eigenvalues
How many loom operators should be employed to minimize cost : A room has 10 cotton spinning looms. Once the looms are set up, they run automatically. The setup time is exponentially distributed, with mean 10 minutes. The machines run for an average of 40 minutes, also exponentially distributed.
Solve computer science java validation problem : Computer Science, Operating Systems - Year 1Description:java validationProblem: Using NetBeans 7.2
What do you list for the focal length : Youâ€TMre writing specifications for a new line of magnifying glasses that have double-convex lenses with equal 22.0cm curvature radii, What do you list for the focal length
How can these be factored into an investment decision : The book notes that some benefits and costs cannot be quantified. What kinds of benefits and costs elude quantification and how can these be factored into an investment decision?
Calculate the predetermined overhead rate : Bubba's Crawfish Processing Company uses a traditional overhead allocation based on direct labor hours. For the current year overhead is estimated at $2,250,000 and direct labor hours are budgeted at 415,000 hours.
Determine best hydraulic section for min wetted perimeter : A flume discharges 42.0 cfs on a slope of 0.50 ft in 1000 ft. The section is rectangular, and Manning's roughness coefficient is 0.012. Determine the best hydraulic section, i.e., the dimension for minimum wetted perimeter.

Reviews

Write a Review

JAVA Programming Questions & Answers

  Small computer system interface-standard computer disk

How many primary drive partitions are supported on computers that still conform to the standard established by MS-DOS? How many total partitions can a standard computer disk [Intergrated Drive Electronics (IDE)/Serial Advanced Technology Attachment (..

  Implement a game called bunko-poker

Implement a game called Bunko-Poker. The gameplay is an easily programmed version of the popular game Yahtzee. Your program will make use of the supplied static functions Dice.roll() and, in cases where you might need the string ordered, Dice.ordered..

  Mutant bacterium-synthesize the amino acid tyrosine

Consider a mutant bacterium you have isolated which is unable to synthesize the amino acid tyrosine. You grow it in the presence of a chemical mutagen and isolate a single revertant, which is now able to grow in the absence of tyrosine

  Java program by array

Write a program that reads in a file that contains one integer per line. Each integer represents one location in the image. Assume that there are 64 rows and 64 columns in the image

  The game of pig

Write a program that allows a single player to practice the game (that is, there will be no opponent, just a single player). Play 5 turns in the game to get a total score for the player. Refer to the sample output below for a detailed example.

  An infix to postfix method for my java program.

an infixToPostFix method for my java program. The method must work with stacks and it should take a string as parameter. The method should be able to convert to postfix mathematic expressions such as: (12 + 4) - 23(9-6)/12. Treat the parenthesis as l..

  Palindrome by doing character replacement

A palindrome is a string that reads the same from both the ends. Given a string S convert it to a palindrome by doing character replacement.

  Java program that will add the corresponding elements

Develop a Java program that will add the corresponding elements of two 1-dimensional arrays X and Y to produce the 1-dimensional array Z. Arrays X, Y, Z have the same dimension [M].

  Program that allows a user to input coordinates

In Java make a program that allows a user to input coordinates as to make a Hexagon via an array, and my professor has set the standards of: Write a class Polygon which draws a hexagon for a set of numbers given by the user.

  Class sorter which contains methods for selection sort

Write a class Sorter which contains methods for selection sort, insertion sort and bubble sort (start with the code below). Then create a client class which asks user to enter ten numbers using arrays. Then the program asks user which sorting algo..

  Print the number of lines the number of words

a java program where im supposed to print the number of lines the number of words and the longest line in a text file!

  Design a class named large integers

Design a class named largeIntegers such that an object of this class can store an integer of any number of digits.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd