Answer to Question #257070 in Java | JSP | JSF for Shan

Question #257070
Create a class called Date that has separate int member data for date, month and year. One member function should take the input from the user. Another member function should contain fixed values. Another member function should display the date, in 26-10-2021 format.
1
Expert's answer
2021-10-27T00:25:46-0400
import java.util.Scanner;
class  Date{
    private int  date;
    private int month;
    private int  year;
    public void input(){
        Scanner scan = new Scanner(System.in);
        System.out.println("Enter date: ");
        int d= scan.nextInt();
        System.out.println("Enter month: ");
        int m= scan.nextInt();
        System.out.println("Enter year: ");
        int y= scan.nextInt();
        date = d;
        month = m;
        year = y;
    }
    String fixed(){
        String s = date+"-"+month+"-"+year;
        return s;
    }
    void output(){
        System.out.println(fixed());
    }
    
}
public class Main
{
	public static void main(String[] args) {
		Date d= new Date();
		d.input();
		d.output();
		
	}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS