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

  Java''s type int has limit onhow large aninteger it can store

Java's type int has a limit on how large an integer it can store. This limit can be circumvented by representing an integer as an array of digits. Write an interactive program that adds two integers of up to 50 digits each.

  Squashes the difference in fruit weight-distribution

Assume that in squashes the difference in fruit weight between a 3-lb type and a 6-lb type results from three independently segregating allelic pairs, A/a, B/b, and C/c. Each capital-letter allele contributes a half pound to the weight of the squash...

  Create a secure parts inventory catalog system

You will create a secure Parts Inventory Catalog system using Model 2 architecture. The application will require a user to have the proper access right to enter the system, and when satisfied, presents the catalog of items currently available in t..

  Design a program to help a videorental store

Design classes (class video, class customer, etc) based on your analysis above, using LINKED LISTS for the database elements read into the main memory.

  Write a program that allows a user to enter a line of text

Write a program that allows a user to enter a line of text, counts number of words and number of vowels in the sentence, and gives the average number of vowels per word in the message

  Program that initializes an array with ten random integers

Write a JAVA program that initializes an array with ten random integers and then prints four lines of output, containing

  Write a java loop

write a java loop ( of your choice ) that produces exactly the following output to the screen: 2-4-6-8-

  Traditionally-nutrition programs were targeted to indigent

Traditionally, nutrition programs were targeted to the indigent and poor populations in developing countries. Many of today's Americans are malnourished also, but they are glutted with a wealth of unhealthy foods and require a multidisciplinary appro..

  Design an abstract data type in java

Design an abstract data type in Java that represents a musical pitch

  Create an array that stores in integers from the keyboard

create an array that stores in integers from the keyboard and then I can scan that array to check numbers in order, if the number I check is greater than the previous then I will set the next number in the array to the higher value.

  Die class that can hold an integer

Design a die class that can hold an integer from 1 to 6. use the dice class to create a dice game. in this game, the user chooses a number between 2 and 12 inclusive

  Write java program to select pine for furniture company

Write down the Java program for the furniture company. Ask user to select P for Pine, O for Oak or M for Mahogany.

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