English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

System.out.println ("Please enter your quiz grade: ");
sQuiz = br.readLine();
dQuiz = Double.parseDouble(sQuiz);
System.out.println ("Please enter your grade in seatwork: ");
sSeatwork = br.readLine();
dSeatwork = Double.parseDouble(sSeatwork);
System.out.println ("Please enter your grade in Laboratory Exercises: ");
sLab = br.readLine();
dLab = Double.parseDouble(sLab);
System.out.println ("Please enter your grade in assignment: ");
sAssign = br.readLine();
dAssign = Double.parseDouble(sAssign);
System.out.println ("Please enter your grade in Prelim exam: ");
sPrelimExam = br.readLine();
dPrelimExam = Double.parseDouble(sPrelimExam);
dPrelimGrade = dQuiz*.25 + dSeatwork*.10 + dLab*.20 + dAssign*.05 + dPrelimExam*.40;
System.out.println ("Your grade is: " + dPrelimGrade );

the error said 'incompatibe types'

2006-11-28 14:10:29 · 3 answers · asked by bonjing 2 in Computers & Internet Programming & Design

3 answers

Assuming you declare all of your variables beforehand, sQuiz, sSeatWork, sLab, sAssign, sPrelimExam, would be of type String. dQuiz, dSeatWork, dLab, dAssign, dPrelimExam and dPrelimGrade should be of type double.

Tip: use the Scanner to take in those values--
first, include this import statement at the beginning of the class-
import java.util.Scanner;

Then make an instance of the Scanner class in this way:
Scanner variableName = new Scanner(System.in);
variableName can be whatever you want.

Then you could say
dQuiz = variableName.nextDouble();
It will throw an exception if a double isn't put in
There is no need to parse it then.

here's a way to do it:

import java.util.Scanner;
public class Grades
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
System.out.println ("Please enter your quiz grade: ");
double dQuiz = keyboard.nextDouble();
System.out.println ("Please enter your grade in seatwork: ");
double dSeatwork = keyboard.nextDouble();
System.out.println ("Please enter your grade in Laboratory Exercises: ");
double dLab = keyboard.nextDouble();
System.out.println ("Please enter your grade in assignment: ");
double dAssign = keyboard.nextDouble();
System.out.println ("Please enter your grade in Prelim exam: ");
double dPrelimExam = keyboard.nextDouble();

double dPrelimGrade = dQuiz*.25 + dSeatwork*.10 + dLab*.20 + dAssign*.05 + dPrelimExam*.40;
System.out.println ("Your grade is: " + dPrelimGrade );
}
}

2006-11-28 14:24:52 · answer #1 · answered by j 4 · 0 0

I am not sure (it has been a few years since i last played with java) but the though in my mind is that your additions in

dPrelimGrade = dQuiz*.25 + dSeatwork*.10 + dLab*.20 + dAssign*.05 + dPrelimExam*.40;

is trying to perform string operations (concatenating) instead of mathematical operations.

I could be totally wrong but that is what i was thinking

may i suggest picking up a copy of the Java Black Book or other manuals also might want to poke around java.sun.com site...lots of info and examples to help sort it out.

hope this helps and good luck

2006-11-28 22:39:52 · answer #2 · answered by Rod R 2 · 0 0

Off the top of my head, the only thing I can think of is the dPrelimGrade may need to be a string before you can print it.

2006-11-28 22:15:21 · answer #3 · answered by Bryan A 5 · 0 0

fedest.com, questions and answers