Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 CSCI Student in need!
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
gully3




PostPosted: Thu Jan 24, 2013 10:38 am   Post subject: CSCI Student in need!

I need desperate help with assignments I will post my current one here.
I am a computer science student using NX Client for compiling, writing etc.
PLEASE HELP!

I Want Cake!
CSCI 1227: Assignment 1
Tami Meredith, Stavros Konstantinidis, Yasushi Akiyami

Overview
Cake is yummy, particularly New York cheesecake with chocolate drizzled all over it! So, when I went out with three friends, we ordered one and cut it into four slices. However, the Merlot had taken its toll and the four slices were not exactly equal. To be fair, we decided to just go around the table and let each person select a slice of cake. Of course, being greedy, the first person took the largest, and so on until the fourth person was left with the smallest piece of cake. Your job is to write a program that prints out which slice of cake each person took.

Your task is to write a Java program that successfully compiles and executes the following algorithm:
1. Ask the user for 4 integer values. Each one of these is the percent, of the total cake, that each slice represents.
2. Verify that the 4 integers of Step 1 add up to 100 (i.e., the four slices make up the whole cake; nothing less, nothing more). If they do not add up to 100, print an error message of some form and exit the program (Hint: In main() the return; statement will cause the program to exit).
3. Identify which slice each person took assuming everyone is greedy and takes the largest remaining slice (none of us were on a diet at the time).

That's it! Hopefully this is pretty clear and not confusing. However, you will quickly discover that while the idea is simple, programming this in a concise and elegant manner WITHOUT using loops and arrays is challenging.

Example of Use

Please enter sizes of the four slices:
20 30 24 26
Person 1 took slice 2 (30%)
Person 2 took slice 4 (26%)
Person 3 took slice 3 (24%)
Person 4 took slice 1 (20%)

Requirements
1. You must email your solution as an attachment, which must be called cake.java, to the course account, csci1227@gmail.com, before the end of the lab class that is one week from the day you received this assignment. Late assignments, as determined by the time stamp of the received email, will not be accepted. Incomplete solutions will earn you partial marks -- that is, ANYTHING IS BETTER THAN NOTHING.
2. The file must compile, execute, and correctly perform the algorithm. We don't care if the algorithm is exactly the same as in the overview, provided it sorts the slices from largest to smallest and produces the desired output.
3. The code must be adequately formatted and contain some comments. One comment must contain your name.
4. You may NOT use loops and arrays (that would make it too easy).

Hints
You will need to figure out some sort of algorithm for solving this problem. The main goal of this assignment is to practice problem solving. You will only use conditional (if) statements and variables. Our main concern is that you can come up with a solution to this problem (it's non-trivial even though it looks simple) - Coding the solution elegantly is a secondary issue on this assignment. Try and get it to work for 3 slices first. Or, if you are really stuck, just try and get the program to print out the sizes of the four slices, from largest to smallest, without worrying about which was slice 1, slice 2, slice 3, and slice 4.

"Real programmers use paper and pencil." -- Its better to make notes and know what you are doing before you sit down at keyboard and start typing. A good friend often says, "First to the keyboard equals last to finish."
Good luck and have fun!
Sponsor
Sponsor
Sponsor
sponsor
DemonWasp




PostPosted: Thu Jan 24, 2013 11:34 am   Post subject: RE:CSCI Student in need!

Okay, what have you done so far, and what part are you having trouble with?

We won't do your work for you, but if you get stuck we can point you in the right direction.
gully3




PostPosted: Thu Jan 24, 2013 11:39 am   Post subject: RE:CSCI Student in need!

import java.util.Scanner;
public static void main(String[] args)
{

int a;
int b;
int c;
int d;
int x;
int y;
System.out.println("Please enter sizes of four slices" );
Scanner keyboard = new Scanner(System.in);
a = keyboard.nextInt();
b = keyboard.nextInt();
c = keyboard.nextInt();
d = keyboard.nextInt();

if (a+b+c+d = 100);
System.out.println('the entered values add upto 100 percent");
else
System.out.println("entered values are wrong");
x = max(a,b,c,d);
y = min(a,b,c,d);
System.out.println('person 1 takes" +x);
System.out.println('person 4 takes" +y);
Comments
Panphobia




PostPosted: Thu Jan 24, 2013 12:30 pm   Post subject: Re: CSCI Student in need!

I can see problems in your code already, when you doing an if you need to use the boolean operator == not = and you do not end an if in a semicolon, the proper syntax for an if in java is
code:
       if(true == true)
           dostuff;
       else
           dootherstuff;
     
or
code:
       if(true == true){
           dostuff;
       }else{
           dootherstuff
       }
           
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: