【问题标题】:Java: Lang error "ComSci" cant be resolved to a typeJava:Lang 错误“ComSci”无法解析为类型
【发布时间】:2021-10-07 20:12:36
【问题描述】:

为我的学校制定了一个简单的入学计划。但是收到错误-

线程“main”java.lang.Error 中的异常:未解决的编译问题:

Comsci 无法解析为类型

    at Add.main(Admission.java:104)

我已尝试多次查看代码,但似乎没有发现任何异常。我对 java 有点陌生,而且还在学习。任何帮助将不胜感激。

这里是源代码-

import java.util.*;
import java.io.*;

class Admission{
    String name = new String();
    float phy, che, mat, cs, eng, hin;
    float tot, perc;

    void enter(){
        Scanner ent = new Scanner(System.in);

        System.out.println("\nEnter your name:");
        name = ent.nextLine();

        System.out.println("\nEnter your 12th Std marks (x/100)");
        System.out.print("Physics- ");
        phy= ent.nextInt();
        System.out.print("\nChemistry- ");
        che= ent.nextInt();
        System.out.print("\nMaths- ");
        mat= ent.nextInt();
        System.out.print("\nComputers- ");
        cs= ent.nextInt();
        System.out.print("\nEnglish- ");
        eng= ent.nextInt();
        System.out.print("\nHindi- ");
        hin= ent.nextInt();
    }
}

class ComSci extends Admission{
    void calculate(){
        tot=phy+mat+che+cs+eng+hin;
        perc=(tot/600)*100;

        System.out.println("Your total marks= "+tot +"/600");
        System.out.println("Your percentage= "+perc +"%");

        if(perc>60){
            System.out.println("You are eligible for admission. Please contact Department ffice :)");
        }else{
            System.out.println("You are not eligible. Percentage needed: 60%");
        }
    }
}

class VisCom extends Admission{
    void calculate(){
        tot=phy+mat+che+cs+eng+hin;
        perc=(tot/600)*100;

        System.out.println("Your total marks= "+tot +"/600");
        System.out.println("Your percentage= "+perc +"%");

        if(perc>50){
            System.out.println("You are eligible for admission. Please contact Department ffice :)");
        }else{
            System.out.println("You are not eligible. Percentage needed: 50%");
        }
    }
}

class FoodSci extends Admission{
    void calculate(){
        tot=phy+mat+che+cs+eng+hin;
        perc=(tot/600)*100;

        System.out.println("Your total marks= "+tot +"/600");
        System.out.println("Your percentage= "+perc +"%");

        if(perc>40){
            System.out.println("You are eligible for admission. Please contact Department ffice :)");
        }else{
            System.out.println("You are not eligible. Percentage needed: 40%");
        }
    }
}

class Add{
    public static void main (String[] args){
       
        int choice;

        Scanner ch = new Scanner(System.in);
                                    

        System.out.println("Which course do want to enrol in?");
        System.out.println("1)CS 2)Viscom 3)FSPM");
        choice=ch.nextInt();

        switch(choice){

            case 1:
                ComSci CS = new Comsci();
                CS.enter();
                CS.calculate();
                break;

            case 2:
                VisCom VC = new VisCom();
                VC.enter();
                VC.calculate();
                break;

            case 3:
                FoodSci FSPM = new FoodSci();
                FSPM.enter();
                FSPM.calculate();
                break;

            default:
                System.out.println("Wrong choice entyer again");
            

        }

    }
}

对这个问题有什么建议吗??

【问题讨论】:

  • 你打错了这个Comsci应该是ComSci
  • 感谢您的帮助!真的很感激! @PradeepSimha

标签: java class methods main


【解决方案1】:

您在大写字母上犯了一个简单的错字。 Line 104 应为:

ComSci CS = new ComSci();

…在new Compsci 中更改为大写S

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-12-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-13
    • 2014-03-19
    相关资源
    最近更新 更多