Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Next, create an application that prompts the user for data for a delivery. Keep

ID: 3906690 • Letter: N

Question

Next, create an application that prompts the user for data for a delivery. Keep prompting the user for each of the following values until they are valid: A four-digit year between 2001 and 2025 inclusive A delivery number for the year between 1 and 9999 inclusive A package weight between 0.10 pound and 100 pounds inclusive A delivery distance code that is either 1 or 2 When all the data entries are valid, construct a Delivery object, and then display its values. Save the file as CreateDelivery.java.

Explanation / Answer

import java.util.Scanner;  

public class CreateDelivery{

public static void main(String []args){
Scanner sc=new Scanner(System.in);  
int yearNo = 0;
int delNo = 0;
float wght = 0;
int distCode = 0;
do{
System.out.println("Please input a year between 2001 and 2025: ");
yearNo = sc.nextInt();
}while(yearNo < 2001 || yearNo > 2025);
  
do{
System.out.println("Please input a delivery Number between 1 and 9999: ");
delNo = sc.nextInt();
}while(delNo < 0 || delNo > 9999);
  
do{
System.out.println("Please input a package weight between 0.1 and 100 pounds: ");
wght = sc.nextFloat();
}while(wght < 0.1 || wght > 100);
  
do{
System.out.println("Please print a delivery code of either 1 or 2: ");
distCode = sc.nextInt();
}while(distCode != 1 && distCode != 2);
  
sc.close();
  
System.out.println(yearNo);
System.out.println(delNo);
System.out.println(wght);
System.out.println(distCode);
  
//Delivery x = new Delievery(yearNo, delNo, wght, distCode);
  
}
}

Output:

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote