Urgent Help: Basic Level Java Programming
Hi,
I am a student taking Java classes, and I need help for a few questions of our Christmas Homework. They are pretty basic stuff and not that hard to do, given that you have the required knowledge. It is really urgent and important, so I would really appreciate it if someone can help.
I am putting here the hardest question in the homework as an example. As I have said, if you are easily able to do this question, please contact me.
"Write a java application that prints the following diamond shape. You may use output statements that print a single asterisk (*), a single space or a single newline character. Maximize your use of repetition (with nested for statements) and minimize the number of output statements."
I cannot draw the diamond here but it goes like this: First line 1 star, second line 3 stars, third line 5 stars, fourth line 7 stars, fifth line 9 stars, and it descends the same way (9 7 5 3 1) to complete the diamond.
Thank you.
Hi,
I am a student taking Java classes, and I need help
for a few questions of our Christmas Homework. They
are pretty basic stuff and not that hard to do, given
that you have the required knowledge. It is really
urgent and important, Not to anyone else but you. We're volunteers, as you should know.
so I would really appreciate it
if someone can help.Isn't that cheating?
Better that you take a shot at it and let people advise you on how to correct problems.
I am putting here the hardest question in the
homework as an example. As I have said, if you are
easily able to do this question, please contact me.Yes, it's easy to do. Hints: Think System.out.println for the stars and two for loops.
"Write a java application that prints the following
diamond shape. You may use output statements that
print a single asterisk (*), a single space or a
single newline character. Maximize your use of
repetition (with nested for statements) and minimize
the number of output statements."
I cannot draw the diamond here but it goes like this:
First line 1 star, second line 3 stars, third line 5
stars, fourth line 7 stars, fifth line 9 stars, and
it descends the same way (9 7 5 3 1) to complete the
diamond.
Thank you.*
Kinda like that...
Think about the steps you'd follow to type this in yourself and then write them out in Java.
%
Similar Messages
-
Need Help with a JAVA programming assignment
How do I write a JAVA program that could be used as the start of an MS-DOS/Windows simulation of the IEEE 802.3 protocol? I am to only code the parts necessary to build the 802.3 frame. For the initial implementation, the Checksum function need not be a CRC function, and the Destination and Source addresses wil be in input, stored, and output, and in dotted-decimal format.
I need:
1. A record to describe the frame, with each field being a (byte-) string of the required size, except that the Data field is of variable size. Although the "Source address" and "Destination address" would be 6 bytes for a real implementation, for this first implementation you can either assume they'll be text strings in the usual "dotted decimal" form (e.g. "14.04.05.18.01.25" as a typical example--from Tanenbaum, p. 429), or 6 hex digits.
2. Suitable constant declarations for values such as the standard "Preamble" and "Start of Frame" values.
3. Suitable functions to Get the three variable values "Destination address", "Source address", and "Data" from the standard input device.
4. A suitable function to display each of the fields of a given frame in a format such as:
Preamble: ...
StartofFrame: ...
Destination: ...
etc.
5. A suitable function to generate a "Pad" field if necessary.
6. A "dummy" Checksum-generating function which just takes the first 32 bits (4 bytes) of the Data (or Data+Pad, if necessary) rather than an actual CRC algorithm.
I have no experience with Java. Can you help me or start me in the right direction?
Thanks...........TKIf you have no experience with Java, then it seems to me your first step should be to start learning the language. But it's difficult to advise how, since we don't know anything about your background. There are many good books available on Java, some are for beginners and some are for advanced programmers, so I'd suggest you go somewhere that has a large selection and start looking for something that doesn't seem completely over your head.
-
Hello. I'm posting in these forums because I really don't know where else to go. I have been trying for the past several days to figure out how to go about writing my program but to no avail. The project requires reading many lines each containing several different elements from a datafile named "DATA". A few examples of some lines from that file:
Department number/Number of units received/Date on which the shipment arrived/Expiration date/Name of Object
0 78 02/03/2001 02/12/2001 apples
0 26 06/03/2001 06/10/2001 lemons
3 62 03/06/2001 03/14/2001 hamburger
What we have to do with this data is read all of it from the file, separate all the different elements, and based on input from the user, sort everything and print it out to the screen. If the user enters 03, the program will show everything that arrived and expired within the month of March, sorted by date.
It is a pretty basic program, but my problem is that I have no idea how to go about reading in this data, putting it into a vector (probably the easiest method) or separating the different elements. I've gone to websites and looked through my textbooks but they didn't help much. If anyone has any resources that could help for writing such a program, or if anyone could offer help in writing the program, I would really appreciate it. I can also show what I've managed to write so far, or more details on how the program should work. Thanks in advance.
Mattsince im not a pro like some of the guys on here :),
and believe me thiers people here, who could write your whole app in a hour.
anyways my advice , would be to do a search on the forums for useing.bufferReader()
i think you would need to read the file in with bufferreader then split up each line useing the stringTokenizer and then use some algorithm to compare
the values and split them up into your vector arrays as needed.
thier is also fileinputStream i think you can use that too. -
Hey
I am doing a bachelor of Multimedia and for some reason I was forced to do Programming 1 which is just Java programing.I have been doing pretty well but we have the final exam coming up on Thursday and they told us to learn how to do this question but I have no idea how to do it, could someone please help me?
Write a program that reads a file containing a list of students' student numbers and names, and then writes out another file in which the students have been formed into project groups.
Sample input file:
96439530 Naranek, Kosh
08532109 Ivanova, Susan
87642078 Sheridan, John
44327889 Varner, Dell
98100023 Kotto, Vir
66345689 Sinclair, Jeffrey
77421009 Garibaldi, Michael
88775544 Winters, Talia
54321098 Alexander, Lyta
12345098 Mollari, Londo
03465499 Takashima, Laurel
88765432 Kyle, Benjamin
08876500 Keffer, Warren
07687878 Cole, Marcus
For the project course: no group should have more than 5 members; and it is desireable that all groups have as close to 5 members as possible; and that students be allocated to groups alphabetically by family name, as in this sample output file:
Group 1:
Lyta Alexander (54321098)
Susan Ivanova (08532109)
Benjamin Kyle (88765432)
John Sheridan (87642078)
Dell Varner (44327889)
Group 2:
Marcus Cole (07687878)
Warren Keffer (08876500)
Londo Mollari (12345098)
Jeffrey Sinclair (66345689)
Talia Winters (88775544)
Group 3:
Michael Garibaldi (77421009)
Vir Kotto (98100023)
Kosh Naranek (96439530)
Laurel Takashima (03465499)
Students' names are first sorted (Alexander, Cole, Garibaldi, Ivanova, ...), then allocated to the tutes in rotation (Alexander to 1, Cole to 2, Garibaldi to 3, Ivanova to 1, ...).
Note also that the student's details are written in a different format from the input. You may make the (usually wrong!) assumption that each student has a simple one-word family name and one other name.I'm sorry too annoy you again but I don't know how to implement what you told me. Here is my current code:
import java.io.*;
import java.util.*;
class DetailSortTest {
public void run() {
try {
BufferedReader in = new
BufferedReader(new FileReader ("Data.txt"));
String line = in.readLine();
String[] names = new String [10];
int i = 0;
PrintWriter FileOut = new
PrintWriter(new FileWriter ("Data 2.txt"));
processFilesTest(in, FileOut);
in.close();
FileOut.close();
} catch (FileNotFoundException f) {
System.out.println("Could Not Open The File");
} catch (IOException i){
System.out.println(i.getMessage());
public void processFilesTest (BufferedReader in, PrintWriter FileOut)
throws IOException {
String data[] = new String[100];
List dList = new ArrayList();
String NLine = in.readLine();
FileOut.println(NLine);
public static void main(String[] args) {
DetailSortTest anObject = new
DetailSortTest();
anObject.run();
How would I do it I tried:
NLine.split(data[2]+""+data[1]+""+data[0]);
But all that displays is null, null, null
I know I am probably so stupid but I really appreciate the help -
I'm a complete novice with Java. I want to write a Java program to run on Windows 2000 servers to write a list of certain files in a directory into a *.txt file. I hope to add complexity once I have this basic part working. Here's the code I have so far:
//this Java application finds poll* files
public class FindPollApp
//Create File Object
File dir = new File("d:/jda/windss/poll");
//List directory
if(dir.isDirectory())
String[] dirContents = dir.list();
for (int i=0; i < dirContents.length; i++)
System.out.println(dirContents);
//Iterate through files
I get the following errors:
C:\JAVA>javac FindPollApp.java
FindPollApp.java:9: illegal start of type
if(dir.isDirectory())
^
FindPollApp.java:18: <identifier> expected
^
2 errors
Thanks.I'm a complete novice with Java. I want to write a
Java program to run on Windows 2000 servers to write
a list of certain files in a directory into a *.txt
file. I hope to add complexity once I have this
basic part working. Here's the code I have so far:
//this Java application finds poll* files
public class FindPollApp
//Create File Object
File dir = new File("d:/jda/windss/poll");
//List directory
if(dir.isDirectory())
String[] dirContents = dir.list();
for (int i=0; i < dirContents.length; i++)
System.out.println(dirContents);
//Iterate through files
I get the following errors:
C:\JAVA>javac FindPollApp.java
FindPollApp.java:9: illegal start of type
if(dir.isDirectory())
^
FindPollApp.java:18: <identifier> expected
^
2 errors
Thanks.
You need to create a method and insert your if statement in there -
Help me making java program by Jcreator
1. reversing an integer problem:
a. write a program that allows a user to enter an integer up to 4 digits in length. The program should then reverse the order of the integer. The new number should have it's full decimal value (e.g. 432 is really 3*100 + 2*10+ 1*1)
Enter number:123
The reversal is 321
Enter number:1005
The reversal is 5001OK the specification said smth. about decimal extension, here it is:
EXPLANATION:
I am just a 'medium-advanced' Java programer and do this because I wan't to
write more code and gather experience.
And if I just write code but don't show it to any body it would get wasted...
OK , ok now on I Stop helping Trolls and laymen.
* @author melhiah
public class ReverseAnInteger {
private static final int MAX_INT_LEN = 6;
public static void main(String[] args) throws Exception {
/* if(args.length < 1) {
System.out.println("Usage: java ReverseAnInteger <integer-value>");
System.exit(0);
//String parsedIntegerString = args[0].substring(0, MAX_INT_LEN);
String testIntegerString = "1234567890";
String parsedIntegerString;
if(testIntegerString.length() < MAX_INT_LEN) {
parsedIntegerString = testIntegerString.substring(0,
testIntegerString.length());
} else {
parsedIntegerString = testIntegerString.substring(0, MAX_INT_LEN);
String reversedIntegerString = showDecimalExtension(
reverseInt(parsedIntegerString));
System.out.println(reversedIntegerString);
private static String reverseInt(String intString) {
char[] charString = intString.toCharArray();
char[] resultString = new char[charString.length];
int top = charString.length;
for(int i = 0; i < charString.length; i++) {
resultString[i] = charString[--top];
return new String(resultString);
private static String showDecimalExtension(String intString) {
StringBuffer buffer = new StringBuffer();
StringBuffer sb = new StringBuffer(); sb.append("1");
for(int i = 1; i < intString.length(); i++) {
sb.append("0");
String decim = sb.toString();
for(int i = 0; i < intString.length(); i++) {
String str = intString.charAt(i) + "*" + decim + " + ";
decim = decim.substring(0, decim.length() -1);
buffer.append(str);
String result = buffer.substring(0, buffer.length() -3); // to get rid of the trailing '+'
return result;
} -
HELP for Compile java programe !
Hello All,
i want to make java programe by which i can compile java programes
and when i compile java programe from my programe then
i shoul get compiled status means programe compile successfuly
or not compile.
if any example i m thanksfull.
onlyforjava.how about if compile fail?
the process obj seems return value 0 as it run successful.
I haven't try this, but I have experienced the process obj returns 0 if the executed command has some routine to handle error cases, in which, error will not halt the system.
So, I recommand the following scenario.
1. let say, if your java is test.java. check the existence of file test.class.
If, it exists, get its modified time.
2. compile the java code with
Procress p = Runtime.exec(new String[]{"javac", "test.java"});
3. get the error string if any.
InputStream in = new BufferedInputStream(p.getInputStream());int read;while ((read = in.read()) != -1){ System.out.println((char)read);}
4. handle error with the exitValue
if (p.exitValue() != 0){ System.out.println("warning.");}
5. check again the file test.class if it is a newly created file.
6. if it is newly created, compile success. Else, failed. -
Need Help with a Java programming exercise.
I have to Write a program that reads two times in military format (0900, 1730) and prints the number of hours and minutes between two times. Supply your own test program. Here are two sample runs. User inputs are the numbers.
Please enter the first time: 0900
Please enter the second time: 1730
8 hours 30 minutes
Please enter the first time: 1730
Please enter the second time: 0900
15 hours 30 minutes
Test Program I can write up myself. But the entire constructor I have no idea how to start. This is basic Java Coding. no C++ no importing anything.
So far this is what I got and I'm sure it's wrong:
public class TimeInterval
private double hours;
private double minutes;
public TimeInterval(double Time1, double Time2)
hours =
minutes =
}tad2382 wrote:
Jverd,
I'm guessing that in your early days on this forum you must have spent a lot of time explaining constructors, object creation, etc. Now, after some 40K posts to the forum, you figure newbies should just go and read the documentation. Is that what a lot of veteran posters feel?Perhaps the OP is not aware of the fact the Sun has a good deal of high quality study material published on their website. What's wrong with posting it in a thread? Why should one copy the same thing over and over again? If after reading that tutorial, the OP still has some questions about it, s/he is free to post a follow up question. I am sure that many of the regulars here are more than happy to answer them.
Also note that the OP's problem description is rather vague. A "I don't know where to start" is IMO best answered by a link to a comprehensive tutorial or a beginners book.
Being one of the (relatively) novice posters on the forum, I still feel the need to customize posts,Well, by all means: do so.
trying to see things from the poster's side. Maybe after a few thousand posts, I'll just keep throwing the same documentation at newbies, instead of detailed customized responses, heh.IMO, that's a load of cr@p. -
I am doing this simple program. where i have created three menu's and i want it to pop-up a seperate window when i press any of the menu items. till now i have written this code and created the menus, can you please tell me how to attach actionlisteners to each of the menu items, so that when one menuitem is selected it leads to a another frame performing a different function. It is also not showing the color i am using in the code.
public class GUIform extends JMenuBar {
String[] fileList = new String[] {"Connect", "Exit"};
String[] dataList = new String[] {"Query", "Add Student", "Delete Student", "Update Student"};
String[] OptionsList = new String[] {"Color", "Font"};
char[] fileShortcuts = {'L', 'E'};
char[] dataShortcuts = {'Q', 'A', 'T', 'U'};
char[] OptionsShortcuts = {'C', 'N'};
/** Creates a new instance of GUIform */
public GUIform() {
JMenu fileMenu = new JMenu("File");
JMenu dataMenu = new JMenu("Data");
JMenu OptionsMenu = new JMenu("Options");
ActionListener printListener = new ActionListener(){
public void actionPerformed(ActionEvent event) {
System.out.println("Menu item [" + event.getActionCommand( ) +
"] was pressed.");
for(int i = 0; i < fileList.length; i++)
JMenuItem link = new JMenuItem(fileList, fileShortcuts);
link.setAccelerator(KeyStroke.getKeyStroke(fileShortcuts,
Toolkit.getDefaultToolkit( ).getMenuShortcutKeyMask( ), false));
link.addActionListener(printListener);
fileMenu.add(link);
for(int i = 0; i < dataList.length; i++)
JMenuItem link = new JMenuItem(dataList, dataShortcuts);
link.setAccelerator(KeyStroke.getKeyStroke(dataShortcuts,
Toolkit.getDefaultToolkit( ).getMenuShortcutKeyMask( ), false));
link.addActionListener(printListener);
dataMenu.add(link);
for(int i = 0; i < OptionsList.length; i++)
JMenuItem link = new JMenuItem(OptionsList, OptionsShortcuts);
link.setAccelerator(KeyStroke.getKeyStroke(OptionsShortcuts,
Toolkit.getDefaultToolkit( ).getMenuShortcutKeyMask( ), false));
link.addActionListener(printListener);
OptionsMenu.add(link);
add(fileMenu);
add(dataMenu);
add(OptionsMenu);
public static void main(String s[ ]) {
JFrame frame = new JFrame("Student Application");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setJMenuBar(new GUIform( ));
JPanel panel = new JPanel();
panel.setBackground(Color.ORANGE);
frame.pack( );
frame.setSize(300, 200);
frame.setLocation(200, 200);
frame.setVisible(true);import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class MenuTest
public static void main(String s[ ])
JFrame frame = new JFrame("Student Application");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setJMenuBar(getMenuBar( ));
JPanel panel = new JPanel();
panel.setBackground(Color.ORANGE);
frame.getContentPane().add(panel);
frame.pack( );
frame.setSize(300, 200);
frame.setLocation(200, 200);
frame.setVisible(true);
private static JMenuBar getMenuBar()
String[] fileList = { "Connect", "Exit" };
String[] dataList = {
"Query", "Add Student", "Delete Student", "Update Student"
String[] OptionsList = { "Color", "Font" };
char[] fileShortcuts = {'L', 'E'};
char[] dataShortcuts = {'Q', 'A', 'T', 'U'};
char[] OptionsShortcuts = {'C', 'N'};
JMenu fileMenu = new JMenu("File");
JMenu dataMenu = new JMenu("Data");
JMenu OptionsMenu = new JMenu("Options");
ActionListener printListener = new ActionListener()
public void actionPerformed(ActionEvent event)
JMenuItem item = (JMenuItem)event.getSource();
String ac = item.getActionCommand();
System.out.println("ac = " + ac);
for(int i = 0; i < fileList.length; i++)
JMenuItem link = new JMenuItem(fileList, fileShortcuts[i]);
link.setAccelerator(KeyStroke.getKeyStroke(fileShortcuts[i],
Toolkit.getDefaultToolkit().getMenuShortcutKeyMask( ), false));
link.setActionCommand(fileList[i]);
link.addActionListener(printListener);
fileMenu.add(link);
for(int i = 0; i < dataList.length; i++)
JMenuItem link = new JMenuItem(dataList[i], dataShortcuts[i]);
link.setAccelerator(KeyStroke.getKeyStroke(dataShortcuts[i],
Toolkit.getDefaultToolkit( ).getMenuShortcutKeyMask( ), false));
link.setActionCommand(dataList[i]);
link.addActionListener(printListener);
dataMenu.add(link);
for(int i = 0; i < OptionsList.length; i++)
JMenuItem link = new JMenuItem(OptionsList[i], OptionsShortcuts[i]);
link.setAccelerator(KeyStroke.getKeyStroke(OptionsShortcuts[i],
Toolkit.getDefaultToolkit( ).getMenuShortcutKeyMask( ), false));
link.setActionCommand(OptionsList[i]);
link.addActionListener(printListener);
OptionsMenu.add(link);
JMenuBar menuBar = new JMenuBar();
menuBar.add(fileMenu);
menuBar.add(dataMenu);
menuBar.add(OptionsMenu);
return menuBar; -
Help! Simple Java Program.
Here is the problem: Write a program that creates a loan amortization table. The user of the program will supply values for Initial Loan Principal, Annual Percentage Rate and Monthly Payment. The program should print out the appropriate amortization table including the number of Monthly Payments and the Total Interest paid for the life of the loan. The program should allow multiple
runs (up to 4 different versions) of the table process and should allow the
user to compare runs in a tabular format.
This is what I have so far and should work one I completely debug it. I am really new to Java, and I thinks it is somthing to do with the Array. I recently switched from C++ to Java, so I don't think I have the syntax down correctly. Thanks.
import javax.swing.JOptionPane;
public class Program_01
public static void main(String [] args)
int Runs;
do{
String Run_Question = JOptionPane.showInputDialog(null, "How many times,would you like to run" +
" the program? (Up to four runs only!)", "Run Question", JOptionPane.QUESTION_MESSAGE);
Runs = Integer.parseInt(Run_Question);
if( Runs < 0 || Runs > 4)
JOptionPane.showMessageDialog(null, "The number is not valid, try again!", "Error",
JOptionPane.INFORMATION_MESSAGE);
}while(Runs < 0 || Runs > 4);
Questions(Runs);
public static void Questions(int Runs)
for(int index = 0;index < Runs;index ++)
String Loan_Principle_String = JOptionPane.showInputDialog(null, "What is the Loan Principle?", "Loan Amount",
JOptionPane.QUESTION_MESSAGE);
String Percentage_Rate_String = JOptionPane.showInputDialog(null, "What is the Annual Percentage Rate?",
"Interest Rate", JOptionPane.QUESTION_MESSAGE);
String Monthly_Payment_String = JOptionPane.showInputDialog(null, "What is the Monthly Payment", "Payment",
JOptionPane.QUESTION_MESSAGE);
double Loan_Principle = Double.parseDouble(Loan_Principle_String);
double Percentage_Rate = Double.parseDouble(Percentage_Rate_String);
double Monthly_Payment = Double.parseDouble(Monthly_Payment_String);
Calculate(Loan_Principle, Percentage_Rate, Monthly_Payment);
public static void Calculate (double Loan, double Percentage, double Monthly)
double[] Principle = new double[]{0,0};
double[] Interest = new double[]{0,0};
double[] Remain = new double[]{0,0};
double Monthly_Percent = Percentage/12;
double MPR = ((int)((Monthly_Percent + .005) * 100.) / 100.);
boolean Over = true;
double Borrowed = Loan;
int Month = 0;
for (int index = 0; Over != false; index++)
double Rate = MPR * Loan;
double decimalRate = ((int)((Rate + .005) * 100.) / 100.);
Interest[index] = decimalRate;
double Prince = Monthly - decimalRate;
double decimalPrince = ((int)((Prince + .005) * 100.) / 100.);
Principle[index]= decimalPrince;
double Rmn = Borrowed - decimalPrince;
Borrowed = Rmn;
double decimalRmn = ((int)((Rmn + .005) * 100.) / 100.);
Remain[index] = decimalRmn;
if(Monthly > Remain[index] && Remain[index] > 0)
Monthly = Remain[index];
Over = false;
Month += 1;
System.out.println("I am here!" + Month);
System.out.println("Payment #" + " " + "Principle" + " " + "Payment" + " " + "APR" + " " + "MPR" +
" " + "Interest Payment" + " " + "Principle Payment");
System.out.println("------------------------------------------------------------------------");
for(int index = 0; index < Month; index++)
System.out.println((index + 1) + "\t" + Remain[index] + "\t" + Percentage + "\t" + MPR + "\t" + Interest[index]
+ "\t" + Principle[index]);
}Okay, here is my updated code. I am having trouble outputting my formate to align with each category.
import javax.swing.JOptionPane;
import java.text.DecimalFormat;
public class Program_01
public static void main(String [] args)
int Runs;
do
String Run_Question = JOptionPane.showInputDialog(null, "How many times would you like to run" +
" the program? (Up to four runs only!)", "Run Question", JOptionPane.QUESTION_MESSAGE);
Runs = Integer.parseInt(Run_Question);
if( Runs < 0 || Runs > 4)
JOptionPane.showMessageDialog(null, "The number is not valid, try again!", "Error",
JOptionPane.INFORMATION_MESSAGE);
}while(Runs < 0 || Runs > 4);
Questions(Runs);
public static void Questions(int Runs)
for(int index = 0;index < Runs;index ++)
String Loan_Principle_String = JOptionPane.showInputDialog(null, "What is the Loan Principle?", "Loan Amount",
JOptionPane.QUESTION_MESSAGE);
String Percentage_Rate_String = JOptionPane.showInputDialog(null, "What is the Annual Percentage Rate?",
"Interest Rate", JOptionPane.QUESTION_MESSAGE);
String Monthly_Payment_String = JOptionPane.showInputDialog(null, "What is the Monthly Payment", "Payment",
JOptionPane.QUESTION_MESSAGE);
double Loan_Principle = Double.parseDouble(Loan_Principle_String);
double Percentage_Rate = Double.parseDouble(Percentage_Rate_String);
double Monthly_Payment = Double.parseDouble(Monthly_Payment_String);
Calculate(Loan_Principle, Percentage_Rate, Monthly_Payment);
public static void Calculate (double Loan, double Percentage, double Monthly)
double[] Principle = new double[100];
double[] Interest = new double[100];
double[] Remain = new double[100];
double[] Payment = new double[100];
DecimalFormat Decimal = new DecimalFormat(".00");
double Total_Interest = 0;
double T_Interest;
double Monthly_Percent = (Percentage/12)/100;
double MPR = Monthly_Percent;
boolean Over = true;
double Borrowed = Loan;
double Deposit = Monthly;
int Month = 0;
for (int index = 0; Over = true; index++)
double Rate = MPR * Borrowed;
double decimalRate = round(Rate,2);
Interest[index] = decimalRate;
Remain[index] = Borrowed;
Month += 1;
if(Monthly > Remain[index ] && Remain[index ] > 0)
for(int count = 0; count <= Month; count++)
Total_Interest += Interest[count];
T_Interest = round(Total_Interest,2);
Payment[index] = T_Interest;
Deposit = T_Interest;
else
Payment[index] = Deposit;
double Prince = Deposit - decimalRate;
double decimalPrince = round(Prince,3);
Principle[index]= decimalPrince;
System.out.println("I am here!" + decimalPrince);
double Rmn = Borrowed - decimalPrince;
double decimalRmn = round(Rmn,2);
Borrowed = decimalRmn;
if(Monthly > Remain[index ] && Remain[index ] > 0)
Over = false;
break;
System.out.println("Payment #" + " " + "Principle" + " " + "Payment" + " " + "Percentage" + " " + "MPR" +
" " + "Interest Payment" + " " + "Principle Payment");
System.out.println("----------------------------------------------------------------------------");
for(int index = 0; index < Month; index++)
System.out.println(" " + (index + 1) + "\t " + Decimal.format(Remain[index]) + " " +
Decimal.format(Payment[index]) + " " + Decimal.format(Percentage) + " " + MPR +
"\t" + Decimal.format(Interest[index]) + "\t\t" + Decimal.format(Principle[index]));
T_Interest = ((int)((Total_Interest + .005) * 100.) / 100.);
System.out.println("\n\t\t\t" + "Total Interest Paid \t" + T_Interest + "\n");
for(int index = 0; index < Month; index++)
System.out.printf("%f %f\n", Principle[index],Remain[index]);
public static double round(double val, int places) {
long factor = (long)Math.pow(10,places);
// Shift the decimal the correct number of places
// to the right.
val = val * factor;
// Round to the nearest integer.
long tmp = Math.round(val);
// Shift the decimal the correct number of places
// back to the left.
return (double)tmp / factor;
} -
Help please with java programming
ok so i need a little help on getting started on this program.
i need to make a program where the user can enter the last names of candidates and the votes recieved by each candidate. then the program should output both the candidates names and the total votes recieved by each candidate and the perctage of votes each recieved.
can anyone help me get started with some sample code. thanks.ok so this is what i have so far . . . . it goes through the array and works.
im suppose to also have these two methods . . .
sumVotes- Which will receive the votes array by reference.
Calculate the total votes.- Return the calculated integral total votes.winnerIndex- Which will receive the votes array by reference.- Identify the top candidate who received more votes. - Return the identified index.
my program is suppose to do this . . .The program should then output each candidate?s name, votes received by that candidate, and the percentage of the total votes received by the candidate. The program should also output the winner of the election.
ok so anyone out there nice enough to tutor me through making these 2 methods i need?
here is code of what i have so far
package assign11942;
import javax.swing.*;
public class Assign11942 {
* @param args
public static void main(String[] args) {
// TODO Auto-generated method stub
String strLast[],strNumCand, strVotes[];
int numCand;
double votes[], percentage, totalVotes[];
strNumCand = JOptionPane.showInputDialog("Enter Number of Candidates: ");
numCand = Integer.parseInt(strNumCand);
strLast=new String[numCand];
strVotes=new String[numCand];
votes=new double[numCand];
totalVotes=new double[numCand];
for (int i =0 ; i < numCand; i++) {
strLast= JOptionPane.showInputDialog("Enter Candidates Last Name: ");
strVotes[i]=JOptionPane.showInputDialog("Enter Number of Votes: "); -
Hi all ..
i am a new in Java and i need some help with my School Project ,,,
Will you help me ??
regards,
TootaPeople here will answer questions and comment on your code, but don't ecpect them to debug your source nor do your homework for you.
-
Help with inventory Java program
Hello,
I've been working on this and couldn't get what's the problem is :(
Can somebody explain to me what would be the problems?
import java.util.Scanner;
public class Product
public static void main(String[] args)
Scanner s = new Scanner(System.in);
System.out.print("Enter the item number: ");
int item = s.nextInt();
System.out.print("Enter the product name: ");
String product = s.next();
System.out.print("Enter the unit: ");
int unit = s.nextInt();
System.out.print("Enter the price for each unit: ");
double price = s.nextDouble();
product p = new product(item, product, unit, price);
System.out.println("You entered: ");
System.out.print("Item: " + p.getItemNumber() + "\nProduct: " + p.getProductName() + "\nUnits: " + p.getUnits() + "\nPricePerUnit: " + p.getPriceUnit() + "\n");
System.out.println("Here is the value of inventory :" + p.getPriceInventory());
class Inventory1
private int itemNumber;
private String productName;
private int Unit;
private double priceUnit;
public Inventory1(int itemNumber, String productName, int Unit, double priceUnit)
this.itemNumber = itemNumber;
this.productName = productName;
this.Unit = Unit;
this.priceUnit = priceUnit;
public int getItemNumber()
return itemNumber;
public void setItemNumber(int itemNumber)
this.itemNumber = itemNumber;
public double getPriceUnit()
return priceUnit;
public void setPriceUnit(double priceUnit)
this.priceUnit = priceUnit;
public String getProductName()
return productName;
public void setProductName(String productName)
this.productName = productName;
public int getUnit()
return Unit;
public void setUnit(int Unit)
this.Unit = Unit;
public double getPriceInventory()
double number = getUnit() * getPriceUnit();
return number;
}Build output:
--------------------Configuration: <Default>--------------------
java:10: class Product is public, should be declared in a file named Product.java
public class Product
^
TestProduct.java:23: cannot find symbol
symbol : class product
location: class Product
product p = new product(item, product, unit, price);
^
TestProduct.java:23: cannot find symbol
symbol : class product
location: class Product
product p = new product(item, product, unit, price);
^
3 errors
Process completed.General output:
java.lang.NoClassDefFoundError: Product
Caused by: java.lang.ClassNotFoundException: Product
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
Exception in thread "main"
Process completed.Help!!
Thank you in advanceI adjusted and this time it says:
Build Output
--------------------Configuration: <Default>--------------------
16: cannot find symbol
symbol : variable product
location: class Product
Product p = new Product(item, product, unit, price);
^
16: internal error; cannot instantiate Product.<init> at Product to ()
Product p = new Product(item, product, unit, price);
^18: cannot find symbol
symbol : method getItemNumber()
location: class Product
System.out.print("Item: " + p.getItemNumber() + "\nProduct: " + p.getProductName() + "\nUnits: " + p.getUnits() + "\nPricePerUnit: " + p.getPriceUnit() + "\n");
^
18: cannot find symbol
symbol : method getProductName()
location: class Product
System.out.print("Item: " + p.getItemNumber() + "\nProduct: " + p.getProductName() + "\nUnits: " + p.getUnits() + "\nPricePerUnit: " + p.getPriceUnit() + "\n");
^
18: cannot find symbol
symbol : method getUnits()
location: class Product
System.out.print("Item: " + p.getItemNumber() + "\nProduct: " + p.getProductName() + "\nUnits: " + p.getUnits() + "\nPricePerUnit: " + p.getPriceUnit() + "\n");
^
18: cannot find symbol
symbol : method getPriceUnit()
location: class Product
System.out.print("Item: " + p.getItemNumber() + "\nProduct: " + p.getProductName() + "\nUnits: " + p.getUnits() + "\nPricePerUnit: " + p.getPriceUnit() + "\n");
^
19: cannot find symbol
symbol : method getPriceInventory()
location: class Product
System.out.println("Here is the value of inventory :" + p.getPriceInventory());
^
7 errors
Process completed.General Output
--------------------Configuration: <Default>--------------------
java.lang.NoClassDefFoundError: Product
Caused by: java.lang.ClassNotFoundException: Product
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
Exception in thread "main"
Process completed.(>_<)
I forgot to mention...
That I need to create a product class that holds the item number, the name of the product, the number of units in stock and the price of each unit (I think I got this part)
I need to create a Java application that displays the product number, the name of the product, the number of units in stock, the price of each unit, and the value of the inventory (the number of units in stock multiplied by the price of each unit).
Edited by: yodartas on Sep 27, 2008 7:54 PM -
Urgent help needed in Java Strings
Hi guys/gals..
I want to know how to i Capitalize onlt the first Alphabet of a String.
Eg if i hav the string "swing". i need it as "Swing" ie the first alpha shud be capitalized. How to do tat. The Java method of toUpperCase wud be of now use since it capitalizes the whole string.
Tks.
Divya...I use this. Maybe not the most optimal way, but it works :)
public static String capString(String inp)
byte[] buf = inp.getBytes();
// first character is between 'a' and 'z', substract 32 from it to capitalize the character
if(buf[0] >= 97 && buf[0] <= 122)
buf[0] -= 32;
return new String(buf);
} -
Help me for java programming about ATM machine
can anyone make a program for me or fix my program? cause i got some of the errors that i can not fix....
my school project duedate at 14 july2001
please email me at [email protected]
Thanksbut show me the code to solve your problem.
Maybe you are looking for
-
I have a new IPAD and just bought APple TV. Need to set up home sharing on my account and have followed Support options wherein you log into ITunes, choose advanced, then allow Home sharing. There is no place to even sign in to ITunes as i have alway
-
What is better in Portal 7.0 (compared to Portal 5.0) ?
Hi experts, what would be the main argument for upgrading Portal from 5.0 to 7.0? What is decisively better in the higher version (e.g. Forums)? The reason why I am asking is that I really need arguments in order to make the customer clear why such a
-
Upload image that is not in local file system
We have an abomination of a project where we are trying to upload employee images into our main 'People' form. The only issue is that the images exist on a SQL Server database. I can get the images onto the Oracle server easily enough but the functio
-
Pricing problem : one product two treatment,one single customer
dear all, i am facing a strange problem i m having some material which is under one division one distribution channel and one sale organization,and also the customer is same,but the customer some times taking the product for internal use of their com
-
Hello All Is it possible to upload the Document in SAP DMS without creating from CV01N transaction? Also my requirement is to upload around 2.1 GB documents in SAP is it possible to upload it in one transaction? User want to just upload the docs in S