i am truly a beginner.please can anyone assume and help me define main method in this parameterized constructor programme

import java.io.*;
class studentmarks
{
String name;
double engmarks,phymarks,chemmarks;
double tot,avg;
public studentmarks(String s,double p,double e,double c)
{
name=s;
engmarks=e;
phymarks=p;
chemmarks=c;
}
void compute()
{
tot=engmarks+phymarks+chemmarks;
avg=tot/3;
}
void display()
{
System.out.println("nameis:"+name);
System.out.println("totalis:"+tot);
}
}

please...please...
thank you

Every java program needs a main method like this:

public static void main(String[] args) {
   // your program startup code goes here
}

The code in the main method is what gets executed when your program starts. For example you could call your constructor (passing in some test data), then call compute(), then call display() to see if it all works properly

Member Avatar for hfx642

Also, Line 2 should read

public class studentmarks

And don't forget that your file should be named studentmarks.java (case sensitive!)

There's no requirement for the class with the main method to be public, although it often is.
The file name is case sensitive inside a jar file and in Linux, but not Windows; don't know about MacOS.

Every java program needs a main method like this:

public static void main(String[] args) {
   // your program startup code goes here
}

The code in the main method is what gets executed when your program starts. For example you could call your constructor (passing in some test data), then call compute(), then call display() to see if it all works properly

import java.io.*;
public class studentmarks
{
String name;
double engmarks,phymarks,chemmarks;
double tot,avg;
public static void main(String[] args)
{
public studentmarks(String s,double p,double e,double c)
{
name=s;
engmarks=e;
phymarks=p;
chemmarks=c;
}
void compute()
{
tot=engmarks+phymarks+chemmarks;
avg=tot/3;
}
void display()
{
System.out.println("nameis:"+name);
System.out.println("totalis:"+tot);
}
}
}
i did it this way.i get a error illegal start of the expression.please can you edit it.
thank you

import java.io.*;
public class studentmarks
{
String name;
double engmarks,phymarks,chemmarks;
double tot,avg;
public static void main(String[] args)
{
public studentmarks(String s,double p,double e,double c)
{
name=s;
engmarks=e;
phymarks=p;
chemmarks=c;
}
void compute()
{
tot=engmarks+phymarks+chemmarks;
avg=tot/3;
}
void display()
{
System.out.println("nameis:"+name);
System.out.println("totalis:"+tot);
}
}
}
i did it this way.i get a error illegal start of the expression.please can you edit it.
thank you

in public student marks

You put the definition for the studentmarks constructor inside the main method. That's not legal - you can't define one method inside another like that.
You main method is just like any other method, it should call those other methods, that's all.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.