Я знаю, что java обычно не может возвращать два значения, но я пытаюсь вернуть значение как метод. Оттуда я хочу использовать значения score1 и maxScore1 в строка в основном методе. getHwGrades - это метод, с которым у меня проблемы. Я получаю «ошибка: не могу найти символ». Мне не разрешено использовать массивы для этой программы. На другой ноте, я также не должны использовать какие-либо если/другое заявления, но я не мог найти какой-либо другой способ ограничить значение discussionGrade 20. Приветствуется любая помощьКак вернуть два значения в Java
import java.util.Scanner;
public class Grades
{
public static void main(String[] args)
{
Scanner getG = new Scanner(System.in);
int weight1;
int weight2;
int weight3;
int score2 = 0;
int maxScore2 = 0;
int sections;
int discussionGrade;
System.out.println("What is the weight for the HW and Exam 1?");
weight1 = getG.nextInt();
weight2 = getG.nextInt();
weight3 = getWeight(weight1, weight2);
System.out.println("Using weights of " + weight1 + " " + weight2 + " " + weight3);
getHwGrades();
sections = numberSections();
discussionGrade = calcDGrade(sections);
System.out.println("What is your grade for exam1?"); //move under hw total points and final grade, add curve
score2 = getG.nextInt();
maxScore2 = getG.nextInt();
System.out.println("Total Points =" + (score1+ discussionGrade) + "/ "(maxScore1 + 20));
}
public static int getHwGrades()//method for asking and storing hw grades
{
int score1;
int maxScore1;
int nOfA;
Scanner getG = new Scanner(System.in);
System.out.println("How many HW assignments are there?");
nOfA = getG.nextInt();
for (int i = 1; i <= nOfA; i++) //loop that asks for the grades corresponding to the amount of hw assignments there were
{
System.out.println("What is your grade and then the max grade for assignment " + i + "?");
score1 += getG.nextInt();
maxScore1 += getG.nextInt();
}
return new getHwGrade(score1, maxScore1); //returns results of inputs into method holding the 2 variables
}
public static int numberSections() //finds out how many sections the student attended
{
Scanner getG = new Scanner(System.in);
System.out.println("How many sections did you attend?");
return getG.nextInt();
}
public static int calcDGrade(int sections) //method to calculate the grade for the students sections
{
int maxDGrade = ((sections*4)); if (maxDGrade > 20) //limits total score to 20
{
return 20;
}
else
{
return maxDGrade;
}
}
public static int getWeight(int weight1, int weight2)//returns the weight that will be used for weight3
{
return (100-(weight1 + weight2));
}
public static double round2(double number)
{
return Math.round(number * 100.0)/100.0;
}
}
Пожалуйста, приложите больше усилий для форматирования кода. Ваш код не имеет отступов последовательно, у вас есть 'if' statements * следующие * другие операторы в одной строке, несколько пустых строк без видимых и больше кода, чем я подозреваю, вам действительно нужно продемонстрировать проблему. –
AFAIK метод может возвращать только одно значение, поэтому лучшее, что я мог бы посоветовать, - это согласовать оба значения с разделителем и разделить их позже. – Satya
Что вы ожидаете от 'return new getHwGrade', btw? У вас нет класса под названием 'getHwGrade', насколько я могу видеть ... –