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

  Recursive factorial program

Write a class Array that encapsulates an array and provides bounds-checked access. Create a recursive factorial program that prompts the user for an integer N and writes out a series of equations representing the calculation of N!.

  Hunt the wumpus game

Reprot on Hunt the Wumpus Game has Source Code listing, screen captures and UML design here and also, may include Javadoc source here.

  Create a gui interface

Create GUI Interface in java programing with these function: Sort by last name and print all employees info, Sort by job title and print all employees info, Sort by weekly salary and print all employees info, search by job title and print that emp..

  Plot pois on a graph

Write a JAVA program that would get the locations of all the POIs from the file and plot them on a map.

  Write a university grading system in java

University grading system maintains number of tables to store, retrieve and manipulate student marks. Write a JAVA program that would simulate a number of cars.

  Wolves and sheep: design a game

This project is designed a game in java. you choose whether you'd like to write a wolf or a sheep agent. Then, you are assigned to either a "sheep" or a "wolf" team.

  Build a graphical user interface for displaying the image

Build a graphical user interface for displaying the image groups (= cluster) in JMJRST. Design and implement using a Swing interface.

  Determine the day of the week for new year''s day

This assignment contains a java project. Project evaluates the day of the week for New Year's Day.

  Write a java windowed application

Write a Java windowed application to do online quiz on general knowledge and the application also displays the quiz result.

  Input pairs of natural numbers

Java program to input pairs of natural numbers.

  Create classes implement java interface

Interface that contains a generic type. Create two classes that implement this interface.

  Java class, array, link list , generic class

These 14 questions covers java class, Array, link list , generic class.

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