473,779 Members | 1,921 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Trouble with output.

Steel546
25 New Member
This program is used to calculate GPA. I'm having trouble actually getting an output. Alright, I KNOW that I don't have an output statement, but I don't know where to put it... heh. Netbeans keeps telling me it's wrong. So, here's my two classes.

Expand|Select|Wrap|Line Numbers
  1.  
  2. package KyleTaylorGPA;
  3.  
  4. public class GPA {
  5.  
  6.     private double theGPA;
  7.     private int gradePointsSum;
  8.     private int numHours;
  9.  
  10.     public GPA(double theGPA, int gradePointsSum, int numHours){
  11.  
  12.         theGPA = 0;
  13.         gradePointsSum = 0;
  14.         numHours = 0;
  15.  
  16.  
  17.     }
  18.     public double returnGPA() {
  19.  
  20.     theGPA = (double) gradePointsSum/ (double) numHours;
  21.     return theGPA;
  22.     }
  23.  
  24.     public void addCourse(int letterGrade, int currentNumHours) {
  25.  
  26.         // A would be represented by 1
  27.         // B would be represented by 2
  28.         // C would be represented by 3
  29.         // D would be represented by 4
  30.         // F would be represented by 5
  31.  
  32.         switch (letterGrade) {
  33.             case 1:  gradePointsSum = gradePointsSum + 4 ; break;
  34.             case 2:  gradePointsSum = gradePointsSum + 3 ; break;
  35.             case 3:  gradePointsSum = gradePointsSum + 2 ; break;
  36.             case 4:  gradePointsSum = gradePointsSum + 1 ; break;
  37.             case 5:  gradePointsSum = gradePointsSum + 0 ; break;
  38.  
  39.         }
  40.  
  41.         numHours = numHours + currentNumHours;
  42.  
  43.     }
  44.  
  45.    public void addCourse(double transferGPA, int numTransferHours) {
  46.  
  47.     double x = 0;
  48.     x = transferGPA * (double) numTransferHours;
  49.  
  50.     gradePointsSum = gradePointsSum + (int) x;
  51.     numHours = numHours + numTransferHours;
  52.  
  53.     }
  54.  
  55.    public void addCourse(int currentNumHours, double percentageGrade) {
  56.  
  57. int percentage;
  58. percentage = (int) percentageGrade;
  59.  
  60. switch (percentage/10) {
  61.             case 10: gradePointsSum = gradePointsSum + 4;
  62.             case 9: gradePointsSum = gradePointsSum + 4;
  63.             break;
  64.             case 8: gradePointsSum = gradePointsSum + 3;
  65.             break;
  66.             case 7: gradePointsSum = gradePointsSum + 2;
  67.             break;
  68.             case 6: gradePointsSum = gradePointsSum + 1;
  69.             break;
  70.             case 5: gradePointsSum = gradePointsSum + 0;
  71.             break;
  72.             case 4: gradePointsSum = gradePointsSum + 0;
  73.             break;
  74.             case 3: gradePointsSum = gradePointsSum + 0;
  75.             break;
  76.             case 2: gradePointsSum = gradePointsSum + 0;
  77.             break;
  78.             case 1: gradePointsSum = gradePointsSum + 0;
  79.             break;
  80.         }
  81.  
  82. numHours = numHours + currentNumHours;
  83.  
  84.     }
  85. }
  86.  
Expand|Select|Wrap|Line Numbers
  1. package KyleTaylorGPA;
  2.  
  3. public class KyleTaylorGPA {
  4.  
  5.      public static void main(String[] args) {
  6.  
  7.          GPA calcGPA = new GPA(0,0,0);
  8.          calcGPA.addCourse(1, 4);
  9.          calcGPA.addCourse(2, 4);
  10.          calcGPA.addCourse(3.5, 12);
  11.          calcGPA.addCourse(3.2, 9);
  12.          calcGPA.addCourse(4, 95);
  13.          calcGPA.addCourse(6, 89);
  14.          calcGPA.returnGPA();
  15.  
  16.      }
  17. }
  18.  

Any ideas? It's supposed to run with my returnGPA() statement.
Mar 31 '09 #1
9 2001
r035198x
13,262 MVP
1.) What error message do you get?
2.) Don't use Netbeans (or any IDE) if you are still learning Java.
3.) See the "Read this first" thread at the top of these forums. It has links to tutorials that you must read.
Apr 1 '09 #2
Steel546
25 New Member
It's alright. I got it. I actually had some problems with my switch statement, but I just couldn't get returnGPA to print, but then I fixed it. Thanks again though.

Oh, and our school requires us to use Netbeans or Eclipse.
Apr 1 '09 #3
r035198x
13,262 MVP
@Steel546
But you are still learning Java and IDEs make you get the work done without knowing how to do the work. Use the IDE at school then and use a plain text editor at home when you are really learning Java?

P.S What do they do to you if you insist on using notepad (or textpad) until you have leaned all the basics properly?
Apr 6 '09 #4
Steel546
25 New Member
Hm. I don't think they would actually do anything. There is a webCompiler on the CSE website, as if you were looking at notepad or somthing, then you can run it and see if it works.

I think it's because they want a high rate of passing for students, since not everyone in Computer Science will be programming/software engineering, etc. (I would actually be one of those people).
Apr 6 '09 #5
Jasonrodrigues
3 New Member
@Steel546
I also have same problem but I didnt get whats the problem when I run the program -- nothing comes up. Can you tell me whats wrong with swtich or any coding?
thanks
Jul 18 '10 #6
Steel546
25 New Member
@Jasonrodrigues
Wow this was old.

Just post the code you have and we can see what's going on.
Jul 21 '10 #7
Jasonrodrigues
3 New Member
@Steel546
its the same code as posted above about GPA. My vlaues are different but it doesn't matter. So I also have same code as above

Thanks for reply!!!
Jul 21 '10 #8
TheServant
1,168 Recognized Expert Top Contributor
Is this homework?
Jul 22 '10 #9
Jasonrodrigues
3 New Member
@TheServant
No!!! I just confuse there.
Jul 22 '10 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

9
4964
by: Penn Markham | last post by:
Hello all, I am writing a script where I need to use the system() function to call htpasswd. I can do this just fine on the command line...works great (see attached file, test.php). When my webserver runs that part of the script (see attached file, snippet.php), though, it doesn't go through. I don't get an error message or anything...it just returns a "1" (whereas it should return a "0") as far as I can tell. I have read the PHP...
4
1640
by: Rembrandt Q Einstein | last post by:
I am running an external command and I need to know a) when it is done and b) what it wrote to both stdout and stderr. After a little searching, I found the popen2 module and used the Popen3 class. I'm having trouble with it hanging, though. Here is a very well put (by someone else) posting that describes some background: http://mail.python.org/pipermail/python-list/2004-July/230837.html
2
5780
by: Jeff | last post by:
/* -------------------------------------------------------------------------- Hello, I was experimenting with class templates and specializing member functions and came across a simple problem which I can't figure out. I have a simple class C with 2 template member objects, and a function print() that prints the value of these objects. I defined a specialization of print() for C<string, char> which is called correctly. Then I wanted...
1
13297
by: Andre Ranieri | last post by:
I'm having trouble programatically inserting an Excel file into an Image column in our CRM package's SQL 2000 database. The function appears to work ok, but when I attempt to access the file through the application's front end the file appears to be corrupt. The front-end application has a way of inserting files to the column, however when I analyze this in SQL Profiler the contents of the Byte array appear to be quite different than the one...
1
1528
by: drife | last post by:
Hello, I use the Python Numeric package extensively, and had been an avid user of the "old" scipy. In my view, both pieces of software are truly first rate, and have greatly improved my productivity in the area of scientific analysis. Thus, I was excited to make the transition to the new scipy core (numpy). Unfortunately, I am experiencing a problem that I cannot sort out. I am running Python 2.4.2 on a Debian box (V3.1), using
0
1194
by: tenaka2k | last post by:
OK I have poked around and have not found an answer to my problem . I have a repeater that in it's <ItemTemplate> calls a function I want to pass the current values from the repeater to the function. I have yet to Figgure out how to get the Evals Data to goto the function as the current code does not work. Producing an error of : "System.InvalidOperationException: Databinding methods such as Eval(), XPath(), and Bind() can only be used...
1
2068
by: ferraro.joseph | last post by:
Hi, I'm querying Salesforce.com via their AJAX toolkit and outputting query results into a table. Currently, their toolkit does not possess the ability to do table joins via their structured query language, which forces me to do the join manually via arrays. Right now, I'm having trouble getting these query results (which are in
3
4541
by: sab | last post by:
Hello, I have been working on a python script to parse a continuously growing log file on a UNIX server. The input is the standard in, piped in from the log file. The application works well for the most part, but the problem is when attempting to continuously pipe information into the application via the tail -f command. The command line looks something like this: tail -f <logfile| grep <search string| python parse.py
1
2614
by: meLlamanJefe | last post by:
I have a set of values that need to be output to a text file. The output includes both text and numbers so I'd like to line up the floating point numbers on the list so it is easy to read. The output to the file is handled through a std::ofstream. The output comes from a 3 x 3 matrix and for testing purposes, each floating point value in the matrix is preceded by the string "value = " when it is output to the stream. As you can see below from...
0
9471
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10071
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9925
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8958
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7478
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6723
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5372
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3631
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2867
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.