Java:Lang 错误“ComSci”无法解析为类型

Posted

技术标签:

【中文标题】Java:Lang 错误“ComSci”无法解析为类型【英文标题】:Java: Lang error "ComSci" cant be resolved to a type 【发布时间】: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 【参考方案1】:

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

ComSci CS = new ComSci();

…在new Compsci 中更改为大写S

【讨论】:

以上是关于Java:Lang 错误“ComSci”无法解析为类型的主要内容,如果未能解决你的问题,请参考以下文章

解析为对象而不是数组时出现Json错误:JSONObject中的getJSONObject(java.lang.String)无法应用于(int)

java.lang.Enum 类型无法解析 - 在 Eclipse 中导入 Java 项目后出现错误

java.lang.RuntimeException:无法解析 Oracle 数据库版本

JSON java.lang.String 无法转换为 JSONObject

IntelliJ System.out.println() - 无法解析方法 println(java.lang.String)

JSONException:java.lang.String 类型的值无法转换为 JSONObject