Overclock.net - Overclocking.net
     
 
Home Gallery Reviews Blogs Register Today's Posts Mark Forums Read Members List


Go Back   Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming

Reply
 
LinkBack Thread Tools
Old 04-27-07   #1 (permalink)
Console Gamer
 
Danavas's Avatar
 
intel nvidia

Join Date: Jul 2005
Location: University of Washington
Posts: 738

Rep: 44 Danavas is acknowledged by some
Unique Rep: 38
FAQs Submitted: 2
Trader Rating: 2
Default Need Coding Help (Java)

Hey, im writing code for my uni class, and im havening a bit of trouble keeping it organized. Its a simple program that takes in scores and returns the score you got in the class.

My problem is splitting the program up into methods. I cant seem to find any way that works well. And my main is becoming cluttered up. The only ways I though of is doing a examMath one and a homeworkMath one, or doing an input, math, output one (doent work). So im stumped.

Heres the expected output.

Quote:
This program accepts your homework and
two exams scores as input and computes
your grade in the course.

Homework and Exam 1 weights? 50 20
Using weights of 50 20 30

Homework:
Number of assignments? 3
Assignment 1 score and max? 14 15
Assignment 2 score and max? 16 20
Assignment 3 score and max? 19 25
Sections attended? 4
Total points = 65 / 80
Weighted score = 40.63

Exam 1:
Score? 81
Curve? 0
Total points = 81 / 100
Weighted score = 16.2

Exam 2:
Score? 95
Curve? 10
Total points = 100 / 100
Weighted score = 30.0

Course grade = 86.83
You will get at least a 3.0
__________________
.999... = 1 Get over it.
Learn to do some bloody math without a calculator.


"Video games don't make people violent, coding video games makes people violent."
3800+ X2 O/C

System: Navi
CPU
Conroe e6400
Motherboard
Gigabyte GA-965P-DS3
Memory
2 GB G.Skill F2-6400PHU2-2GBHZ
Graphics Card
EVGA 7800 GTX KO
Sound Card
Creative X-Fi Fal1ty
Power Supply
PC Power & Cooling 510
Case
Lian Li PC-60 Plus
CPU cooling
Zalman CNPS-9500
GPU cooling
Stock
OS
Moneysoft XP Pro
Monitor
Hyundai L90D+

Last edited by Danavas : 04-27-07 at 10:38 AM.
Danavas is offline   Reply With Quote
Old 04-27-07   #2 (permalink)
Turing Test is Overrated
 
DuckieHo's Avatar
 
intel nvidia

Join Date: Nov 2006
Location: In a Chair.
Posts: 24,173

Rep: 2803 DuckieHo is a legendDuckieHo is a legendDuckieHo is a legendDuckieHo is a legendDuckieHo is a legendDuckieHo is a legendDuckieHo is a legendDuckieHo is a legendDuckieHo is a legendDuckieHo is a legendDuckieHo is a legend
Unique Rep: 1294
Folding Team Rank: 966
Trader Rating: 34
Default

What language? BASIC? What version?
__________________
WANTED: Socket M Core/Core 2 CPU, SUGO-02 Black, quality 802.11b/g PCI Card
To answer most of your questions: (1) a fridge cannot cool a PC (2) 64-bit OS for over 3.4GB (3) If a PCIe card fits, it will work (4) Resolution, not screen size (5) If you have a question, it is not news (6) Report, not respond to Spam (7) Single/Non-Modular Rail PSUs are NOT better than Multi-Rail/Modular

Quote:
catmmm: no wifi? gay
e_dogg: I use both wired and wireless in my house. Does that make me bi?

System: My "DF-DIE" Replacement
CPU
Q6600 (3.7GHz)
Motherboard
Asus P5E X38 (MF1208 BIOS)
Memory
2x2GB OCZ Reaper 1096MHz
Graphics Card
8800GT (729/1836/2088)
Hard Drive
PERC 5/i: 3xRAID0 Raptor 74GB + 7200.10 250GB
Sound Card
X-Fi XtremeMusic
Power Supply
Corsair 620HX
Case
Li Lian PC-V2100 [10x120mm fans]
CPU cooling
FuZion V2 + Quad-Heatercore
GPU cooling
MCW60 + Iandh HS + DDC-3.2
OS
Vista Ultimate 64
Monitor
Samsung 226BW "C" + Sceptre 19"
DuckieHo is offline I fold for Overclock.net Overclocked Account DuckieHo's Gallery   Reply With Quote
Old 04-27-07   #3 (permalink)
Console Gamer
 
Danavas's Avatar
 
intel nvidia

Join Date: Jul 2005
Location: University of Washington
Posts: 738

Rep: 44 Danavas is acknowledged by some
Unique Rep: 38
FAQs Submitted: 2
Trader Rating: 2
Default

Its Java, but I really just need help structuring it into methods, I cant find any good places to break it up Heres a link to the assignment if ya like.

http://www.cs.washington.edu/educati...hw4-grades.pdf

Also this is what I have so far, but its kinda a mess.

Quote:

import java.util.*;

public class Grades {
public static void main(String[] args) {
Scanner console = new Scanner(System.in);

// Asks user for weights
System.out.println("This program accepts your homework and");
System.out.println("two exams scores as imput and computes");
System.out.println("your grade in the course.");
System.out.println();
System.out.print("Homework and Exam 1 weights? ");

// Gets weights from user
int homeworkWeight = console.nextInt();
int exam1Weight = console.nextInt();

// Calculates 3rd weight
int exam2Weight = (100 - (homeworkWeight + exam1Weight));

// Prints out weights being used
System.out.println("Using weights of " + homeworkWeight + " " + exam1Weight + " " + exam2Weight);
System.out.println();

// Calculates homework
double homeworkScore = homework(homeworkWeight);

}

public static double homework(int homeworkWeight) {
Scanner console = new Scanner(System.in);

// Asks for number of assignments
System.out.println("Homework:");
System.out.print("Number of assignments? ");

// Retreives number of assignments from user
int assignments = console.nextInt();

// Totals the assignments
int assignmentTotal = 0;
int assignmentMax = 0;
for (int count = 1; count <= assignments; count++) {
System.out.print("Assignment " + count + " score and max? ");
assignmentTotal = assignmentTotal + console.nextInt();
assignmentMax = assignmentMax + console.nextInt();
}

// Makes sure that a student can not get more points than the max available
if (assignmentTotal > assignmentMax) {
assignmentTotal = assignmentMax;
}

// Asks for how many sections were attended
System.out.println("Sections attended? ");
int attendance = console.nextInt();

// Calculates score for attendance (can not be > 20)
attendance = attendance * 4; //check if this is working
if (attendance > 20) {
attendance = 20;
}

// Calculates the weighted homework score
double homeworkScore = (homeworkWeight * ((assignmentTotal + attendance)/(assignmentMax + 20))); //this needs to be fixed

// Displays points recived over max and weighted score of homework
System.out.println("Total points = " + assignmentTotal + " / " + assignmentMax);
System.out.println("Weighted score = " + round2(homeworkScore));

// Returns weighted homework score
return homeworkScore;
}

public staic main double exam(int examWeight) {



}

// This method returns the value rounded to the nearest hundredth
public static double round2(double number) {
return Math.round(number * 100.0)/100.0;
}
}
__________________
.999... = 1 Get over it.
Learn to do some bloody math without a calculator.


"Video games don't make people violent, coding video games makes people violent."
3800+ X2 O/C

System: Navi
CPU
Conroe e6400
Motherboard
Gigabyte GA-965P-DS3
Memory
2 GB G.Skill F2-6400PHU2-2GBHZ
Graphics Card
EVGA 7800 GTX KO
Sound Card
Creative X-Fi Fal1ty
Power Supply
PC Power & Cooling 510
Case
Lian Li PC-60 Plus
CPU cooling
Zalman CNPS-9500
GPU cooling
Stock
OS
Moneysoft XP Pro
Monitor
Hyundai L90D+

Last edited by Danavas : 04-27-07 at 10:33 AM.
Danavas is offline   Reply With Quote
Old 04-27-07   #4 (permalink)
Turing Test is Overrated
 
DuckieHo's Avatar
 
intel nvidia

Join Date: Nov 2006
Location: In a Chair.
Posts: 24,173

Rep: 2803 DuckieHo is a legendDuckieHo is a legendDuckieHo is a legendDuckieHo is a legendDuckieHo is a legendDuckieHo is a legendDuckieHo is a legendDuckieHo is a legendDuckieHo is a legendDuckieHo is a legendDuckieHo is a legend
Unique Rep: 1294
Folding Team Rank: 966
Trader Rating: 34
Default

Do they want you to use Object Oriented design?

If so, you need to create class and have the different calculation methods within the class.
__________________
WANTED: Socket M Core/Core 2 CPU, SUGO-02 Black, quality 802.11b/g PCI Card
To answer most of your questions: (1) a fridge cannot cool a PC (2) 64-bit OS for over 3.4GB (3) If a PCIe card fits, it will work (4) Resolution, not screen size (5) If you have a question, it is not news (6) Report, not respond to Spam (7) Single/Non-Modular Rail PSUs are NOT better than Multi-Rail/Modular

Quote:
catmmm: no wifi? gay
e_dogg: I use both wired and wireless in my house. Does that make me bi?

System: My "DF-DIE" Replacement
CPU
Q6600 (3.7GHz)
Motherboard
Asus P5E X38 (MF1208 BIOS)
Memory
2x2GB OCZ Reaper 1096MHz
Graphics Card
8800GT (729/1836/2088)
Hard Drive
PERC 5/i: 3xRAID0 Raptor 74GB + 7200.10 250GB
Sound Card
X-Fi XtremeMusic
Power Supply
Corsair 620HX
Case
Li Lian PC-V2100 [10x120mm fans]
CPU cooling
FuZion V2 + Quad-Heatercore
GPU cooling
MCW60 + Iandh HS + DDC-3.2
OS
Vista Ultimate 64
Monitor
Samsung 226BW "C" + Sceptre 19"
DuckieHo is offline I fold for Overclock.net Overclocked Account DuckieHo's Gallery   Reply With Quote
Old 04-27-07   #5 (permalink)
Console Gamer
 
Danavas's Avatar
 
intel nvidia

Join Date: Jul 2005
Location: University of Washington
Posts: 738

Rep: 44 Danavas is acknowledged by some
Unique Rep: 38
FAQs Submitted: 2
Trader Rating: 2
Default

I more need ideas for how i can break up the work. Im really not seeing it on this assignment. I though if i just started writing it id get an idea, but that hasn't been the case. About 5 hours ago the main was a horrible mess. Its still pretty bad as you can see above.
__________________
.999... = 1 Get over it.
Learn to do some bloody math without a calculator.


"Video games don't make people violent, coding video games makes people violent."
3800+ X2 O/C

System: Navi
CPU
Conroe e6400
Motherboard
Gigabyte GA-965P-DS3
Memory
2 GB G.Skill F2-6400PHU2-2GBHZ
Graphics Card
EVGA 7800 GTX KO
Sound Card
Creative X-Fi Fal1ty
Power Supply
PC Power & Cooling 510
Case
Lian Li PC-60 Plus
CPU cooling
Zalman CNPS-9500
GPU cooling
Stock
OS
Moneysoft XP Pro
Monitor
Hyundai L90D+
Danavas is offline   Reply With Quote
Old 04-27-07   #6 (permalink)
Turing Test is Overrated
 
DuckieHo's Avatar
 
intel nvidia

Join Date: Nov 2006
Location: In a Chair.
Posts: 24,173

Rep: 2803 DuckieHo is a legendDuckieHo is a legendDuckieHo is a legendDuckieHo is a legendDuckieHo is a legendDuckieHo is a legendDuckieHo is a legendDuckieHo is a legendDuckieHo is a legendDuckieHo is a legendDuckieHo is a legend
Unique Rep: 1294
Folding Team Rank: 966
Trader Rating: 34
Default

Quote:
Originally Posted by Danavas View Post
I more need ideas for how i can break up the work. Im really not seeing it on this assignment. I though if i just started writing it id get an idea, but that hasn't been the case. About 5 hours ago the main was a horrible mess. Its still pretty bad as you can see above.
Do some research on "Class". For this assignment, you can do it linearly but it is not elegant.

http://www-128.ibm.com/developerwork...ary/j-dyn0429/
In this code, you creat a class or object that can do things. You create and use the class Demo. If you need the class to do more things, you write a method and place the method in class definition.
Code:
public class Demo
{
    public static void main(String[] args) {
        System.out.println("**beginning execution**");
        Greeter greeter = new Greeter();
        System.out.println("**created Greeter**");
        greeter.greet();
    }
}

public class Greeter
{
    private static Message s_message = new Message("Hello, World!");
    
    public void greet() {
        s_message.print(System.out);
    }
}

public class Message
{
    private String m_text;
    
    public Message(String text) {
        m_text = text;
    }
    
    public void print(java.io.PrintStream ps) {
        ps.println(m_text);
    }
}
__________________
WANTED: Socket M Core/Core 2 CPU, SUGO-02 Black, quality 802.11b/g PCI Card
To answer most of your questions: (1) a fridge cannot cool a PC (2) 64-bit OS for over 3.4GB (3) If a PCIe card fits, it will work (4) Resolution, not screen size (5) If you have a question, it is not news (6) Report, not respond to Spam (7) Single/Non-Modular Rail PSUs are NOT better than Multi-Rail/Modular

Quote:
catmmm: no wifi? gay
e_dogg: I use both wired and wireless in my house. Does that make me bi?

System: My "DF-DIE" Replacement
CPU
Q6600 (3.7GHz)
Motherboard
Asus P5E X38 (MF1208 BIOS)
Memory
2x2GB OCZ Reaper 1096MHz
Graphics Card
8800GT (729/1836/2088)
Hard Drive
PERC 5/i: 3xRAID0 Raptor 74GB + 7200.10 250GB
Sound Card
X-Fi XtremeMusic
Power Supply
Corsair 620HX
Case
Li Lian PC-V2100 [10x120mm fans]
CPU cooling
FuZion V2 + Quad-Heatercore
GPU cooling
MCW60 + Iandh HS + DDC-3.2
OS
Vista Ultimate 64
Monitor
Samsung 226BW "C" + Sceptre 19"
DuckieHo is offline I fold for Overclock.net Overclocked Account DuckieHo's Gallery   Reply With Quote
Old 04-27-07   #7 (permalink)
Console Gamer
 
Danavas's Avatar
 
intel nvidia

Join Date: Jul 2005
Location: University of Washington
Posts: 738

Rep: 44 Danavas is acknowledged by some
Unique Rep: 38
FAQs Submitted: 2
Trader Rating: 2
Default

I honestly think my code is garbage too. Normally I sort everything up on my notepad first and then write it having an idea what methods ill write and what they will do. But im not really seeing any kinda pattern. Id rewrite it if I had a better idea of how to accomplish it more efficiently.

Also if I use things we haven't 'learned' yet, I get in trouble. I got yelled at for trying to use an array already.

Were only suppose to have one class I believe.
__________________
.999... = 1 Get over it.
Learn to do some bloody math without a calculator.


"Video games don't make people violent, coding video games makes people violent."
3800+ X2 O/C

System: Navi
CPU
Conroe e6400
Motherboard
Gigabyte GA-965P-DS3
Memory
2 GB G.Skill F2-6400PHU2-2GBHZ
Graphics Card
EVGA 7800 GTX KO
Sound Card
Creative X-Fi Fal1ty
Power Supply
PC Power & Cooling 510
Case
Lian Li PC-60 Plus
CPU cooling
Zalman CNPS-9500
GPU cooling
Stock
OS
Moneysoft XP Pro
Monitor
Hyundai L90D+

Last edited by Danavas : 04-27-07 at 11:02 AM.
Danavas is offline   Reply With Quote
Old 04-27-07   #8 (permalink)
Turing Test is Overrated
 
DuckieHo's Avatar
 
intel nvidia

Join Date: Nov 2006
Location: In a Chair.
Posts: 24,173

Rep: 2803 DuckieHo is a legendDuckieHo is a legendDuckieHo is a legendDuckieHo is a legendDuckieHo is a legendDuckieHo is a legendDuckieHo is a legendDuckieHo is a legendDuckieHo is a legendDuckieHo is a legendDuckieHo is a legend
Unique Rep: 1294
Folding Team Rank: 966
Trader Rating: 34
Default

Quote:
Originally Posted by Danavas View Post
I honestly think my code is garbage too. Normally I sort everything up on my notepad first and then write it having an idea what methods ill write and what they will do. But im not really seeing any kinda pattern. Id rewrite it if I had a better idea of how to accomplish it more efficiently.

Also if I use things we haven't 'learned' yet, I get in trouble. I got yelled at for trying to use an array already.

Were only suppose to have one class I believe.
That one class would be "StudentGrade". It would have the following methods:
Weights
Homework
Exam
FinalGrade
__________________
WANTED: Socket M Core/Core 2 CPU, SUGO-02 Black, quality 802.11b/g PCI Card
To answer most of your questions: (1) a fridge cannot cool a PC (2) 64-bit OS for over 3.4GB (3) If a PCIe card fits, it will work (4) Resolution, not screen size (5) If you have a question, it is not news (6) Report, not respond to Spam (7) Single/Non-Modular Rail PSUs are NOT better than Multi-Rail/Modular

Quote:
catmmm: no wifi? gay
e_dogg: I use both wired and wireless in my house. Does that make me bi?

System: My "DF-DIE" Replacement
CPU
Q6600 (3.7GHz)
Motherboard
Asus P5E X38 (MF1208 BIOS)
Memory
2x2GB OCZ Reaper 1096MHz
Graphics Card
8800GT (729/1836/2088)
Hard Drive
PERC 5/i: 3xRAID0 Raptor 74GB + 7200.10 250GB
Sound Card
X-Fi XtremeMusic
Power Supply
Corsair 620HX
Case
Li Lian PC-V2100 [10x120mm fans]
CPU cooling
FuZion V2 + Quad-Heatercore
GPU cooling
MCW60 + Iandh HS + DDC-3.2
OS
Vista Ultimate 64
Monitor
Samsung 226BW "C" + Sceptre 19"
DuckieHo is offline I fold for Overclock.net Overclocked Account DuckieHo's Gallery   Reply With Quote
Old 04-27-07   #9 (permalink)
Apple Doesn't Love You
 
rabidgnome229's Avatar
 
intel nvidia

Join Date: Feb 2006
Location: Pittsburgh
Posts: 4,975
Blog Entries: 1

Rep: 564 rabidgnome229 is becoming famousrabidgnome229 is becoming famousrabidgnome229 is becoming famousrabidgnome229 is becoming famousrabidgnome229 is becoming famousrabidgnome229 is becoming famous
Unique Rep: 338
FAQs Submitted: 6
Trader Rating: 5
Default

Here is the method I would use. Change whatever your teacher wouldn't like

Put weights into double vars
Get number of homework
Loop and add the score/max to their own respective vars
Calculate HW percentage

For the exams:
Get score
Get curve
Apply curve
Get Exam percentages

Add the three percentages and apply weight
__________________
BIG BROTHER
I put on my robe and wizard hat...

IS WATCHING

System: It goes to eleven
CPU
E6300
Motherboard
DS3
Memory
2GB XMS2 DDR2-800
Graphics Card
EVGA 8600GTS
Hard Drive
1.294 TB
Sound Card
Audigy 2 ZS
Power Supply
Corsair 520HX
Case
Lian-Li v1000B Plus
CPU cooling
TTBT
GPU cooling
Thermalright V2
OS
Arch Linux/XP
Monitor
Samsung 226bw
rabidgnome229 is offline Overclocked Account   Reply With Quote
Old 04-27-07   #10 (permalink)
Console Gamer
 
Danavas's Avatar
 
intel nvidia

Join Date: Jul 2005
Location: University of Washington
Posts: 738

Rep: 44 Danavas is acknowledged by some
Unique Rep: 38
FAQs Submitted: 2
Trader Rating: 2
Default

thanks guys
__________________
.999... = 1 Get over it.
Learn to do some bloody math without a calculator.


"Video games don't make people violent, coding video games makes people violent."
3800+ X2 O/C

System: Navi
CPU
Conroe e6400
Motherboard
Gigabyte GA-965P-DS3
Memory
2 GB G.Skill F2-6400PHU2-2GBHZ
Graphics Card
EVGA 7800 GTX KO
Sound Card
Creative X-Fi Fal1ty
Power Supply
PC Power & Cooling 510
Case
Lian Li PC-60 Plus
CPU cooling
Zalman CNPS-9500
GPU cooling
Stock
OS
Moneysoft XP Pro
Monitor
Hyundai L90D+
Danavas is offline   Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools



All times are GMT -4. The time now is 01:58 PM.


Overclock.net is a Carbon Neutral Site Creative Commons License Internet Security By ControlScan

Terms of Service / Forum Rules | Privacy Policy | Advertising | Become an Official Vendor
Copyright © 2008 Shogun Interactive Development. Most rights reserved.
Page generated in 0.33086 seconds with 8 queries