Reputation: 21
I am new to java and have been set a task to create a class called Manual along with some properties shown in the question below:
"1. Design a class Manual with the following properties:
serial number - string, - default:??????
title - string, - default: Untitled
author - string, - default: Unknown
Write a constructor and a method to print details of a Manual on the console. "
I have been working on this task and so far I have this:
public class Manual {
String serialNumber, title, author;
public Manual(){
serialNumber = "??????";
title = "Untitled";
author = "Unknown";
}
}
Would anyone be able to let me know if my working so far is correct and also how I might be able to complete the last line referring to a constructor / print method.
Thank you
Upvotes: 1
Views: 237
Reputation: 122006
Other than that print, you need to have a main method to run.
public class Manual {
String serialNumber, title, author;
public Manual(){
serialNumber = "??????";
title = "Untitled";
author = "Unknown";
}
public void printDetails(){
System.out.println("S.no= " +serialNumber+" Title= "+ title+"author= "+author)
}
public static void main(String [] args){
Manual man= new Manual();
man.printDetails();
}
}
Edit after comment:
I just tried to give a mock code and , you must aware of the access modifiers to your members in the class. This is what your actual task. Learn them and experiment with them.
I wrote a small tutorial on the same, try to read and understand. Default access modifier in Java (or) No access modifier in Java
Good luck.
Upvotes: 1
Reputation: 5087
You are correct so far. For the printing you should use
System.out.println("Manual details : ");
System.out.println("Serial Number : "+serialNumber);
System.out.println("Author : "+author);
System.out.println("Title : "+title);
Upvotes: 1