When I try to run the following Java code on netbeans IDE, it says "erroneous tree type:scanner" and doesn't work. How to fix?
When I try to run the following Java code on netbeans IDE, it says "erroneous tree type:scanner" and doesn't work. How to fix?
import java.util.*;
import java.text.*;
import java.util.Date;
class coursework{
String name,fgrade;
float ass1;
float ass2;
float prac;
float finalm;
double overall;
coursework(String name,float ass1,float ass2,float prac, float finalm)
{
this.name=name;
this.ass1=ass1;
this.ass2=ass2;
this.prac=prac;
this.finalm=finalm;
this.overall = 0.25*ass1+0.25*ass2+0.2*prac+0.3*finalm;
this.fgrade=finalgrade(this.overall);
}
String finalgrade(double m)
{
String g;
if(m>=80)
{
g="HD";
}
else if((m>=70)&&(m<80))
{
g="D";
}
else if((m>=60)&&(m<70)){
g="C";
}
else if((m>=50)&&(m>60))
{
g="P";
}else{
g="N";
}
return g;
}}
class researchstudent{
String name,fgrade;
float proposal;
float oral;
float thesis;
double overall;
researchstudent(String name,float proposal,float oral,float thesis)
{
this.name=name;
this.proposal=proposal;
this.oral=oral;
this.thesis=thesis;
this.overall = 0.3*proposal+0.1*oral+0.6*thesis;
this.fgrade=finalgrade(this.overall);
}
String finalgrade(double m)
{
String g;
if(m>=80)
{
g="HD";
}
else if((m>=70)&&(m<80))
{
g="D";
}
else if((m>=60)&&(m<70)){
g="C";
}
else if((m>=50)&&(m>60))
{
g="P";
}else{
g="N";
}
return g;
}
}
class Main{
public static void main(String[] args) {
int n,i,c,k=0,l=0;
String na;
float m1,m2,m3,m4,m5;
coursework w[] = new coursework[20];
researchstudent r[] = new researchstudent[20];
Scanner s= new Scanner(System.in);
System.out.println("Enter the number of students:\n");
n=s.nextInt();
for(i=0;i<n;i++)
{
System.out.println("Enter \n1.course work\n2.research student:\n");
c=s.nextInt();
if(c==1)
{
System.out.println("Enter the name\n");
na=s.next();
System.out.println("Enter the mark for assignment 1\n");
m1=s.nextInt();
System.out.println("Enter the mark for assignment 2\n");
m2=s.nextInt();
System.out.println("Enter the mark for practical\n");
m3=s.nextInt();
System.out.println("Enter the mark for final exam\n");
m4=s.nextInt();
w[k]=new coursework(na,m1,m2,m3,m4);
k++;
}
if(c==2)
{
System.out.println("Enter the name\n");
na=s.next();
System.out.println("Enter the mark proposal\n");
m1=s.nextInt();
System.out.println("Enter the mark for oral\n");
m2=s.nextInt();
System.out.println("Enter the mark for thesis\n");
m3=s.nextInt();
r[l]=new researchstudent(na,m1,m2,m3);
l++;
}
}
System.out.println("Results:\n");
if(k!=0)
{
for(int j=0;j<l;j++)
{
System.out.println("Name:"+ w[j].name+ " Grade : "+ w[j].fgrade);
}
}
if(l!=0)
{
for(int j=0;j<l;j++)
{
System.out.println("Name:"+ r[j].name+ " Grade : "+ r[j].fgrade);
}
}
}
}
Trending now
This is a popular solution!
Step by step
Solved in 2 steps