Q:

Write a java class called Products that reads product information and extracts products information and print it to the user

0

Write a java class called Products that reads product information and extracts products information and print it to the user.

The product code consists of the country initials, the product code followed by the product serial number, product code example: UK-001-176

Your class should contain One Method plus the main method.ExtractInfo that receives a product code as a String.

The method should extract the origin country of the product, its code and then the product serial number and prints out the result and then saves the same result into a file called “Info.txt” as shown below

ExtractInfo(“UK-001-176”) prints and saves the result as

Country: UK, Code:001, Serial: 176

 

In the main method:

  • Ask the user to enter a product code.
  • Then,call ExtractInfo method to extract, print,and save the product information.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

import java.util.Scanner;

public class Products
{
    static String country;
    static String code;
    static String serial;
    
    public static void ExtractInfo(String productCode)
    {
        country=Character.toString(productCode.charAt(0))+Character.toString(productCode.charAt(1));
        code=Character.toString(productCode.charAt(3))+Character.toString(productCode.charAt(4))+Character.toString(productCode.charAt(5));
        serial=Character.toString(productCode.charAt(7))+Character.toString(productCode.charAt(8))+Character.toString(productCode.charAt(9));
        System.out.println("Country:"+country+", Code: "+code+", Serial: "+serial);
    }
	public static void main(String[] args) {
	    Scanner input=new Scanner(System.in);
	    System.out.println("please enter product code: ");
	    ExtractInfo(input.next());
	}
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now