Get the answers you've been searching for with IDNLearn.com. Discover reliable and timely information on any topic from our network of knowledgeable professionals.

Please Tell Me How To Code This

A supermarket wants to install a computerized weighing system in its produce department. This system produces a label for fruits and vegetables (see below).
Input Screen: Ask the following questions for input. You will be using the Scanner Class for this step.
- Please enter each of the following: - Date in the form of MM/DD/YY
- Description of Item (accept a string as input, but you will only print the first 3 letters from the String. Ex. Input: banana and Output: ban)
- Weight of item (accept a decimal as input)
- Price per pound if item (accept a decimal as input) o Output Screen: Print the output exactly as you see if below.
- Things to note: For the date use the replace command to replace /'s with -'s.
- The description of the item, use the substring command to print only the first 3 letters.​


Sagot :

The program is an illustration of string manipulations.

String manipulation involves splitting and replacing characters of a string.

The program in Java, where comments are used to explain each line is as follows:

import java.util.*;

public class Main{

public static void main(String[] args) {

    //The next two lines declare all variables, as strings and double

 String ddate,desc;

 double weight, price;

 //This creates a scanner object

 Scanner input = new Scanner(System.in);

 //This prompts the user for date, and also gets its input

 System.out.print("Date (MM/DD/YY): ");  ddate = input.nextLine();

 //This prompts the user for item description, and also gets its input

 System.out.print("Description: ");  desc = input.nextLine();

 //This prompts the user for price per pound, and also gets its input

 System.out.print("Price per pound: ");  price = input.nextDouble();

 //This prompts the user for weight, and also gets its input

 System.out.print("Weight: ");  weight = input.nextDouble();

 

 //This replaces all slashes (/) in the date by dash (-)

 ddate = ddate.replace("/", "-");

 

 //This prints the first three characters of the item description

 System.out.println("Description: "+desc.substring(0, 3));

 //This prints the date

 System.out.println("Date: "+ddate);

 //This prints the item price per pound

 System.out.println("Price per pound: "+price);

 //This prints the item weight

 System.out.println("Weight: "+weight);

 //This prints the total price of the item

 System.out.println("Total: "+(weight*price));

}

}

At the end of the program, all user inputs are printed

See attachment for sample run.

Read more about similar programs at:

https://brainly.com/question/15520075

View image MrRoyal